Skip to content

Commit 9a942fb

Browse files
author
James Cor
committed
aaaaa
1 parent 494213f commit 9a942fb

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

enginetest/memory_engine_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,19 @@ func TestSingleQueryPrepared(t *testing.T) {
200200

201201
// Convenience test for debugging a single query. Unskip and set to the desired query.
202202
func TestSingleScript(t *testing.T) {
203-
//t.Skip()
203+
t.Skip()
204204
var scripts = []queries.ScriptTest{
205205
{
206-
Name: "asdfasdfasdf",
206+
Name: "sets",
207207
SetUpScript: []string{
208-
"create table parent (e enum('a', 'b', 'c') primary key);",
209-
"insert into parent values (1), (2);",
210-
"create table child1 (e enum('x', 'y', 'z'), foreign key (e) references parent (e));",
208+
`CREATE TABLE test (pk SET("a","b","c") PRIMARY KEY, v1 SET("w","x","y","z"));`,
209+
`INSERT INTO test VALUES (0, 1), ("b", "y"), ("b,c", "z,z"), ("a,c,b", 10);`,
210+
`UPDATE test SET v1 = "y,x,w" WHERE pk >= 4`,
211+
`DELETE FROM test WHERE pk > "b,c";`,
211212
},
212213
Assertions: []queries.ScriptTestAssertion{
213214
{
214-
Query: "insert into child1 values (1), (2);",
215+
Query: `SELECT * FROM test ORDER BY pk;`,
215216
Expected: []sql.Row{
216217
{types.NewOkResult(2)},
217218
},
@@ -242,7 +243,7 @@ func TestSingleScript(t *testing.T) {
242243

243244
for _, test := range scripts {
244245
harness := enginetest.NewMemoryHarness("", 1, testNumPartitions, true, nil)
245-
//harness.UseServer()
246+
harness.UseServer()
246247
engine, err := harness.NewEngine(t)
247248
if err != nil {
248249
panic(err)

sql/expression/comparison.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,32 @@ func (c *comparison) CastLeftAndRight(ctx *sql.Context, left, right interface{})
303303

304304
lType := c.Left().Type()
305305
rType := c.Right().Type()
306+
307+
//lIsEnumOrSet := types.IsEnum(lType) || types.IsSet(lType)
308+
//rIsEnumOrSet := types.IsEnum(rType) || types.IsSet(rType)
309+
//// If right side is convertible to enum/set, convert. Otherwise, convert left side
310+
//if lIsEnumOrSet && (types.IsText(rType) || types.IsNumber(rType)) {
311+
// if r, inRange, err := lType.Convert(ctx, right); inRange && err == nil {
312+
// return left, r, lType, nil
313+
// }
314+
// l, _, err := types.TypeAwareConversion(ctx, left, lType, rType, false)
315+
// if err != nil {
316+
// return nil, nil, nil, err
317+
// }
318+
// return l, right, rType, nil
319+
//}
320+
//// If left side is convertible to enum/set, convert. Otherwise, convert right side
321+
//if rIsEnumOrSet && (types.IsText(lType) || types.IsNumber(lType)) {
322+
// if l, inRange, err := rType.Convert(ctx, left); inRange && err == nil {
323+
// return l, right, rType, nil
324+
// }
325+
// r, _, err := types.TypeAwareConversion(ctx, right, rType, lType, false)
326+
// if err != nil {
327+
// return nil, nil, nil, err
328+
// }
329+
// return left, r, lType, nil
330+
//}
331+
306332
compType := types.GetCompareType(lType, rType)
307333

308334
// Special case for JSON types

sql/types/utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package types
1616

1717
import (
1818
"github.com/dolthub/go-mysql-server/sql"
19+
1920
)
2021

2122
// GetCompareType returns the type to use when comparing values of types left and right.
@@ -24,6 +25,15 @@ func GetCompareType(left, right sql.Type) sql.Type {
2425
return left
2526
}
2627

28+
// Left and right are both Enum types, but not the same, so use uint16 representation for comparison
29+
if IsEnum(left) && IsEnum(right) {
30+
return Uint16
31+
}
32+
// Left and right are both Set types, but not the same, so use uint16 representation for comparison
33+
if IsSet(left) && IsSet(right) {
34+
return Uint16
35+
}
36+
2737
if IsTimespan(left) || IsTimespan(right) {
2838
return left
2939
}

0 commit comments

Comments
 (0)