Skip to content

Commit 9fb5262

Browse files
committed
updated tests
1 parent af9f681 commit 9fb5262

File tree

5 files changed

+62
-23
lines changed

5 files changed

+62
-23
lines changed

enginetest/queries/integration_plans.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enginetest/queries/queries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6092,7 +6092,7 @@ SELECT * FROM cte WHERE d = 2;`,
60926092
Query: `SELECT if(123 = 123, NULL, NULL = 1)`,
60936093
Expected: []sql.Row{{nil}},
60946094
ExpectedColumns: []*sql.Column{
6095-
{Name: "if(123 = 123, NULL, NULL = 1)", Type: types.Int64}, // TODO: this should be getting coerced to bool
6095+
{Name: "if(123 = 123, NULL, NULL = 1)", Type: types.Boolean},
60966096
},
60976097
},
60986098
{

sql/expression/case_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ func TestCaseType(t *testing.T) {
161161
}
162162
}
163163

164-
decimalType := types.MustCreateDecimalType(65, 10)
165-
164+
decimalType := types.MustCreateDecimalType(types.DecimalTypeMaxPrecision, types.DecimalTypeMaxScale)
165+
uint64DecimalType := types.MustCreateDecimalType(types.DecimalTypeMaxPrecision, 0)
166166
testCases := []struct {
167167
name string
168168
c *Case
@@ -175,13 +175,13 @@ func TestCaseType(t *testing.T) {
175175
},
176176
{
177177
"unsigned promoted and unsigned",
178-
caseExpr(NewLiteral(uint32(0), types.Uint32), NewLiteral(uint32(1), types.Uint32)),
178+
caseExpr(NewLiteral(uint32(0), types.Uint32), NewLiteral(uint32(1), types.Uint64)),
179179
types.Uint64,
180180
},
181181
{
182182
"signed promoted and signed",
183183
caseExpr(NewLiteral(int8(0), types.Int8), NewLiteral(int32(1), types.Int32)),
184-
types.Int64,
184+
types.Int32,
185185
},
186186
{
187187
"int and float to float",
@@ -216,7 +216,7 @@ func TestCaseType(t *testing.T) {
216216
{
217217
"uint64 and int8 to decimal",
218218
caseExpr(NewLiteral(uint64(10), types.Uint64), NewLiteral(int8(0), types.Int8)),
219-
decimalType,
219+
uint64DecimalType,
220220
},
221221
{
222222
"int and text to text",

sql/types/conversion.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -557,12 +557,10 @@ func TypesEqual(a, b sql.Type) bool {
557557

558558
// generalizeNumberTypes assumes both inputs return true for IsNumber
559559
func generalizeNumberTypes(a, b sql.Type) sql.Type {
560-
if a == Float64 || b == Float64 {
560+
if IsFloat(a) || IsFloat(b) {
561+
// TODO: handle cases where MySQL returns Float32
561562
return Float64
562563
}
563-
if a == Float32 || b == Float32 {
564-
return Float32
565-
}
566564

567565
if IsDecimal(a) || IsDecimal(b) {
568566
// TODO: match precision and scale to that of the decimal type, check if defines column
@@ -598,6 +596,7 @@ func generalizeNumberTypes(a, b sql.Type) sql.Type {
598596
if aIsSigned || bIsSigned {
599597
return Int32
600598
}
599+
return Uint24
601600
}
602601

603602
if a == Int24 || b == Int24 {
@@ -644,6 +643,13 @@ func GeneralizeTypes(a, b sql.Type) sql.Type {
644643
return a
645644
}
646645

646+
if svt, ok := a.(sql.SystemVariableType); ok {
647+
a = svt.UnderlyingType()
648+
}
649+
if svt, ok := a.(sql.SystemVariableType); ok {
650+
b = svt.UnderlyingType()
651+
}
652+
647653
if IsJSON(a) && IsJSON(b) {
648654
return JSON
649655
}
@@ -663,7 +669,7 @@ func GeneralizeTypes(a, b sql.Type) sql.Type {
663669
aIsTimespan := IsTimespan(a)
664670
bIsTimespan := IsTimespan(b)
665671
if aIsTimespan && bIsTimespan {
666-
return a
672+
return Time
667673
}
668674
if (IsTime(a) || aIsTimespan) && (IsTime(b) || bIsTimespan) {
669675
if IsDateType(a) && IsDateType(b) {
@@ -678,7 +684,8 @@ func GeneralizeTypes(a, b sql.Type) sql.Type {
678684
}
679685

680686
if IsBlobType(a) || IsBlobType(b) {
681-
return Blob
687+
// TODO: match blob length to max of the blob lengths
688+
return LongBlob
682689
}
683690

684691
aIsBit := IsBit(a)
@@ -707,12 +714,6 @@ func GeneralizeTypes(a, b sql.Type) sql.Type {
707714
}
708715

709716
if IsNumber(a) && IsNumber(b) {
710-
if svt, ok := a.(sql.SystemVariableType); ok {
711-
a = svt.UnderlyingType()
712-
}
713-
if svt, ok := a.(sql.SystemVariableType); ok {
714-
b = svt.UnderlyingType()
715-
}
716717
return generalizeNumberTypes(a, b)
717718
}
718719
// TODO: decide if we want to make this VarChar to match MySQL, match VarChar length to max of two types

sql/types/conversion_test.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,55 @@ func TestColumnCharTypes(t *testing.T) {
160160
}
161161

162162
func TestGeneralizeTypes(t *testing.T) {
163+
decimalType := MustCreateDecimalType(DecimalTypeMaxPrecision, DecimalTypeMaxScale)
164+
uint64DecimalType := MustCreateDecimalType(DecimalTypeMaxPrecision, 0)
165+
163166
tests := []struct {
164167
typeA sql.Type
165168
typeB sql.Type
166169
expected sql.Type
167170
}{
171+
{Float64, Float32, Float64},
172+
{Float64, Int32, Float64},
173+
{Int24, Float32, Float64},
174+
{decimalType, Float64, Float64},
175+
{decimalType, Int32, decimalType},
176+
{Int64, decimalType, decimalType},
177+
{Uint64, Int32, uint64DecimalType},
178+
{Int24, Uint64, uint64DecimalType},
179+
{Uint64, Uint8, Uint64},
180+
{Uint24, Uint64, Uint64},
181+
{Int64, Uint32, Int64},
182+
{Int24, Int64, Int64},
183+
{Int8, Int64, Int64},
184+
{Uint32, Int24, Int64},
185+
{Uint24, Uint32, Uint32},
186+
{Int32, Int8, Int32},
187+
{Uint24, Int32, Int32},
188+
{Uint24, Int24, Int32},
189+
{Uint8, Uint24, Uint24},
190+
{Int24, Uint8, Int24},
191+
{Int8, Int24, Int24},
192+
{Int8, Uint16, Int24},
193+
{Uint16, Uint8, Uint16},
194+
{Int16, Int16, Int16},
195+
{Int8, Int16, Int16},
196+
{Uint8, Int8, Int16},
197+
{Uint8, Uint8, Uint8},
198+
{Int8, Int8, Int8},
199+
{Boolean, Int64, Int64},
200+
{Boolean, Boolean, Boolean},
168201
{Text, Text, LongText},
169202
{Text, Float64, LongText},
170203
{Int64, Text, LongText},
171-
{Float32, Float32, Float32},
172-
{Int64, Float64, Float64},
173-
{Int32, Int32, Int32},
204+
{Int8, Null, Int8},
205+
{Time, Time, Time},
206+
{Time, Date, DatetimeMaxPrecision},
207+
{Date, Date, Date},
208+
{Date, Timestamp, DatetimeMaxPrecision},
209+
{Timestamp, Timestamp, TimestampMaxPrecision},
210+
{Timestamp, Datetime, DatetimeMaxPrecision},
211+
{Null, Int64, Int64},
174212
{Null, Null, Null},
175213
}
176214
for _, test := range tests {

0 commit comments

Comments
 (0)