Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,99 @@ type ScriptTestAssertion struct {
// Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of
// the tests.
var ScriptTests = []ScriptTest{
{
// https://github.com/dolthub/dolt/issues/9836
Skip: true,
Name: "Ordering by pk does not change the order of results",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these tests, can you update to "select pk from test order by pk"? we don't need to test for casting here. You can also simplify the test to just include the 7 values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also tag the entire test with Skip, instead of individual assertions

SetUpScript: []string{
"CREATE TABLE test(pk VARCHAR(50) PRIMARY KEY)",
"INSERT INTO test VALUES (' 3 12 4'), ('3. 12 4'), ('3.2 12 4'), ('-3.1234'), ('-3.1a'), ('-5+8'), ('+3.1234')",
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT pk FROM test ORDER BY pk",
Expected: []sql.Row{{" 3 12 4"}, {"-3.1234"}, {"-3.1a"}, {"-5+8"}, {"+3.1234"}, {"3. 12 4"}, {"3.2 12 4"}},
},
},
},
{
// https://github.com/dolthub/dolt/issues/9812
Name: "String-to-number comparison operators should behave consistently",
Assertions: []ScriptTestAssertion{
{
Dialect: "mysql",
Query: "SELECT ('A') = (0)",
Expected: []sql.Row{{true}},
//ExpectedWarningsCount: 1,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
//ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
},
{
Dialect: "mysql",
Query: "SELECT ('A') IN (0)",
Expected: []sql.Row{{true}},
//ExpectedWarningsCount: 1,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
//ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
},
{
Dialect: "mysql",
Query: "SELECT ('A') != (0)",
Expected: []sql.Row{{false}},
//ExpectedWarningsCount: 1,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
//ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
},
{
Dialect: "mysql",
Query: "SELECT ('A') <> (0)",
Expected: []sql.Row{{false}},
//ExpectedWarningsCount: 1,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
//ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
},
{
Dialect: "mysql",
Query: "SELECT ('A') < (0)",
Expected: []sql.Row{{false}},
//ExpectedWarningsCount: 1,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
//ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
},
{
Dialect: "mysql",
Query: "SELECT ('A') <= (0)",
Expected: []sql.Row{{true}},
//ExpectedWarningsCount: 1,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
//ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
},
{
Dialect: "mysql",
Query: "SELECT ('A') > (0)",
Expected: []sql.Row{{false}},
//ExpectedWarningsCount: 1,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
//ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
},
{
Dialect: "mysql",
Query: "SELECT ('A') >= (0)",
Expected: []sql.Row{{true}},
//ExpectedWarningsCount: 1,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
//ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
},
{
Dialect: "mysql",
Query: "SELECT ('A') NOT IN (0)",
Expected: []sql.Row{{false}},
//ExpectedWarningsCount: 1,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
//ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
},
},
},
{
// https://github.com/dolthub/dolt/issues/9794
Name: "UPDATE with TRIM function on TEXT column",
Expand Down Expand Up @@ -11662,6 +11755,8 @@ select * from t1 except (
{"5.932887e7abc", float32(5.932887e+07)},
{"a1a1", float32(0)},
},
//ExpectedWarningsCount: 12,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
},
{
Dialect: "mysql",
Expand All @@ -11686,6 +11781,8 @@ select * from t1 except (
{"5.932887e7abc", 5.932887e+07},
{"a1a1", 0.0},
},
//ExpectedWarningsCount: 12,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
},
{
Dialect: "mysql",
Expand All @@ -11710,6 +11807,8 @@ select * from t1 except (
{"5.932887e7abc", 5},
{"a1a1", 0},
},
//ExpectedWarningsCount: 12,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
},
{
Dialect: "mysql",
Expand All @@ -11734,6 +11833,8 @@ select * from t1 except (
{"5.932887e7abc", uint64(5)},
{"a1a1", uint64(0)},
},
//ExpectedWarningsCount: 19,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
},
{
Dialect: "mysql",
Expand All @@ -11758,10 +11859,13 @@ select * from t1 except (
{"5.932887e7abc", "59328870.000"},
{"a1a1", "0.000"},
},
//ExpectedWarningsCount: 13,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
},
{
Query: "select * from test01 where pk in ('11')",
Expected: []sql.Row{{"11"}},
//ExpectedWarningsCount: 0,
},
{
// https://github.com/dolthub/dolt/issues/9739
Expand All @@ -11774,6 +11878,8 @@ select * from t1 except (
{"11d"},
{"11wha?"},
},
//ExpectedWarningsCount: 12,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
},
{
// https://github.com/dolthub/dolt/issues/9739
Expand All @@ -11785,6 +11891,8 @@ select * from t1 except (
{" 3. 12 4"},
{"3. 12 4"},
},
//ExpectedWarningsCount: 12,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
},
{
// https://github.com/dolthub/dolt/issues/9739
Expand All @@ -11798,20 +11906,26 @@ select * from t1 except (
{"+3.1234"},
{"3. 12 4"},
},
//ExpectedWarningsCount: 20,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
},
{
// https://github.com/dolthub/dolt/issues/9739
Skip: true,
Dialect: "mysql",
Query: "select * from test02 where pk in ('11asdf')",
Expected: []sql.Row{{"11"}},
//ExpectedWarningsCount: 1,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
},
{
// https://github.com/dolthub/dolt/issues/9739
Skip: true,
Dialect: "mysql",
Query: "select * from test02 where pk='11.12asdf'",
Expected: []sql.Row{},
//ExpectedWarningsCount: 1,
//ExpectedWarning: mysql.ERTruncatedWrongValue,
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions sql/expression/comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *comparison) Compare(ctx *sql.Context, row sql.Row) (int, error) {
return c.Left().Type().Compare(ctx, left, right)
}

l, r, compareType, err := c.castLeftAndRight(ctx, left, right)
l, r, compareType, err := c.CastLeftAndRight(ctx, left, right)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func (c *comparison) evalLeftAndRight(ctx *sql.Context, row sql.Row) (interface{
return left, right, nil
}

func (c *comparison) castLeftAndRight(ctx *sql.Context, left, right interface{}) (interface{}, interface{}, sql.Type, error) {
func (c *comparison) CastLeftAndRight(ctx *sql.Context, left, right interface{}) (interface{}, interface{}, sql.Type, error) {
leftType := c.Left().Type()
rightType := c.Right().Type()

Expand Down Expand Up @@ -452,7 +452,7 @@ func (e *NullSafeEquals) Compare(ctx *sql.Context, row sql.Row) (int, error) {
}

var compareType sql.Type
left, right, compareType, err = e.castLeftAndRight(ctx, left, right)
left, right, compareType, err = e.CastLeftAndRight(ctx, left, right)
if err != nil {
return 0, err
}
Expand Down
41 changes: 9 additions & 32 deletions sql/expression/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func NewInTuple(left sql.Expression, right sql.Expression) *InTuple {

// Eval implements the Expression interface.
func (in *InTuple) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
typ := in.Left().Type().Promote()
leftElems := types.NumColumns(typ)
leftElems := types.NumColumns(in.Left().Type())
originalLeft, err := in.Left().Eval(ctx, row)
if err != nil {
return nil, err
Expand All @@ -78,11 +77,6 @@ func (in *InTuple) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
// also if no match is found in the list and one of the expressions in the list is NULL.
rightNull := false

left, _, err := typ.Convert(ctx, originalLeft)
if err != nil {
return nil, err
}

switch right := in.Right().(type) {
case Tuple:
for _, el := range right {
Expand All @@ -102,31 +96,14 @@ func (in *InTuple) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
continue
}

var cmp int
elType := el.Type()
if types.IsDecimal(elType) || types.IsFloat(elType) {
rtyp := el.Type().Promote()
left, err := types.ConvertOrTruncate(ctx, left, rtyp)
if err != nil {
return nil, err
}
right, err := types.ConvertOrTruncate(ctx, originalRight, rtyp)
if err != nil {
return nil, err
}
cmp, err = rtyp.Compare(ctx, left, right)
if err != nil {
return nil, err
}
} else {
right, err := types.ConvertOrTruncate(ctx, originalRight, typ)
if err != nil {
return nil, err
}
cmp, err = typ.Compare(ctx, left, right)
if err != nil {
return nil, err
}
comp := newComparison(NewLiteral(originalLeft, in.Left().Type()), NewLiteral(originalRight, el.Type()))
l, r, compareType, err := comp.CastLeftAndRight(ctx, originalLeft, originalRight)
if err != nil {
return nil, err
}
cmp, err := compareType.Compare(ctx, l, r)
if err != nil {
return nil, err
}

if cmp == 0 {
Expand Down
Loading