Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d2d2878
tmp patch
Sep 8, 2025
2b95542
attempt at consolidating logic
Sep 9, 2025
389b1c2
asdf
Sep 9, 2025
04aea42
aaaaa
Sep 9, 2025
23fe588
consolidate logic for truncation
Sep 10, 2025
24ea63f
some progress
Sep 10, 2025
d8a7a10
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Sep 10, 2025
6e8c620
refactoring and fixing char function
Sep 11, 2025
052c204
simplify char function
Sep 11, 2025
00e92a7
special case
Sep 12, 2025
b128268
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Sep 11, 2025
8d73f9b
more edge case fixing
Sep 12, 2025
071c4e0
almost done
Sep 12, 2025
7f3900f
cleaning up
Sep 15, 2025
8c5f4e8
fixing tests
Sep 15, 2025
92c424f
fix more tests
Sep 15, 2025
ef266d1
more tests
Sep 15, 2025
55eb7ae
fix tests
Sep 15, 2025
e4ab607
more
Sep 15, 2025
57e44c9
rebase
Sep 15, 2025
f493c9f
asdf
Sep 16, 2025
e2c9956
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Sep 15, 2025
83c1f30
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Sep 16, 2025
be3d33c
aaaaa
Sep 16, 2025
82ce778
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Sep 16, 2025
48c43ab
fixing tests
Sep 16, 2025
2403150
more test fixes
Sep 17, 2025
5038fc4
more test fixes
Sep 17, 2025
759a42c
attempt at consolidating logic
Sep 9, 2025
bbe38b8
aaaaa
Sep 9, 2025
a0f4c95
consolidate logic for truncation
Sep 10, 2025
71f29ee
some progress
Sep 10, 2025
cdcaff4
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Sep 10, 2025
53b61c3
refactoring and fixing char function
Sep 11, 2025
8888b23
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Sep 11, 2025
867e8f9
more edge case fixing
Sep 12, 2025
f390e64
almost done
Sep 12, 2025
19d4470
cleaning up
Sep 15, 2025
7f5a607
fixing tests
Sep 15, 2025
b63da57
fix more tests
Sep 15, 2025
d236023
fix tests
Sep 15, 2025
d48d5b2
rebase
Sep 15, 2025
e521ce7
asdf
Sep 16, 2025
b39da9b
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Sep 15, 2025
0ccdc32
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Sep 16, 2025
0d527bd
aaaaa
Sep 16, 2025
2c8eee2
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Sep 16, 2025
187dbd9
more test fixes
Sep 17, 2025
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
2 changes: 1 addition & 1 deletion enginetest/enginetests.go
Original file line number Diff line number Diff line change
Expand Up @@ -3960,9 +3960,9 @@ func TestWindowRangeFrames(t *testing.T, harness Harness) {
TestQueryWithContext(t, ctx, e, harness, `SELECT sum(y) over (partition by z order by date range between unbounded preceding and interval '1' DAY following) FROM c order by x`, []sql.Row{{float64(1)}, {float64(1)}, {float64(1)}, {float64(1)}, {float64(5)}, {float64(5)}, {float64(10)}, {float64(10)}, {float64(10)}, {float64(10)}}, nil, nil, nil)
TestQueryWithContext(t, ctx, e, harness, `SELECT count(y) over (partition by z order by date range between interval '1' DAY following and interval '2' DAY following) FROM c order by x`, []sql.Row{{1}, {1}, {1}, {1}, {1}, {0}, {2}, {2}, {0}, {0}}, nil, nil, nil)
TestQueryWithContext(t, ctx, e, harness, `SELECT count(y) over (partition by z order by date range between interval '1' DAY preceding and interval '2' DAY following) FROM c order by x`, []sql.Row{{4}, {4}, {4}, {5}, {2}, {2}, {4}, {4}, {4}, {4}}, nil, nil, nil)
TestQueryWithContext(t, ctx, e, harness, "SELECT sum(y) over (partition by z order by date range interval 'e' DAY preceding) FROM c order by x", []sql.Row{{float64(0)}, {float64(0)}, {float64(0)}, {float64(1)}, {float64(1)}, {float64(3)}, {float64(1)}, {float64(1)}, {float64(4)}, {float64(4)}}, nil, nil, nil)

AssertErr(t, e, harness, "SELECT sum(y) over (partition by z range between unbounded preceding and interval '1' DAY following) FROM c order by x", nil, aggregation.ErrRangeInvalidOrderBy)
AssertErr(t, e, harness, "SELECT sum(y) over (partition by z order by date range interval 'e' DAY preceding) FROM c order by x", nil, sql.ErrInvalidValue)
}

func TestNamedWindows(t *testing.T, harness Harness) {
Expand Down
147 changes: 140 additions & 7 deletions enginetest/memory_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,161 @@ func TestSingleScript(t *testing.T) {
t.Skip()
var scripts = []queries.ScriptTest{
{
Name: "AS OF propagates to nested CALLs",
SetUpScript: []string{},
Name: "sets",
SetUpScript: []string{
`CREATE TABLE test (pk SET("a","b","c") PRIMARY KEY, v1 SET("w","x","y","z"));`,
`INSERT INTO test VALUES (0, 1), ("b", "y"), ("b,c", "z,z"), ("a,c,b", 10);`,
`UPDATE test SET v1 = "y,x,w" WHERE pk >= 4`,
`DELETE FROM test WHERE pk > "b,c";`,
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "create procedure create_proc() create table t (i int primary key, j int);",
Query: `SELECT * FROM test ORDER BY pk;`,
Expected: []sql.Row{
{" 3 12 4", uint64(3)},
{" 3.2 12 4", uint64(3)},
{"-3.1234", uint64(18446744073709551613)},
{"-3.1a", uint64(18446744073709551613)},
{"-5+8", uint64(18446744073709551611)},
{"+3.1234", uint64(3)},
{"11", uint64(11)},
{"11-5", uint64(11)},
{"11d", uint64(11)},
{"11wha?", uint64(11)},
{"12", uint64(12)},
{"1a1", uint64(1)},
{"3. 12 4", uint64(3)},
{"5.932887e+07", uint64(5)},
{"5.932887e+07abc", uint64(5)},
{"5.932887e7", uint64(5)},
{"5.932887e7abc", uint64(5)},
{"a1a1", uint64(2)},
},
},
{
Dialect: "mysql",
Query: "select pk, cast(pk as decimal(12,3)) from test01",
Expected: []sql.Row{
{" 3 12 4", "3.000"},
{" 3.2 12 4", "3.200"},
{"-3.1234", "-3.123"},
{"-3.1a", "-3.100"},
{"-5+8", "-5.000"},
{"+3.1234", "3.123"},
{"11", "11.000"},
{"11-5", "11.000"},
{"11d", "11.000"},
{"11wha?", "11.000"},
{"12", "12.000"},
{"1a1", "1.000"},
{"3. 12 4", "3.000"},
{"5.932887e+07", "59328870.000"},
{"5.932887e+07abc", "59328870.000"},
{"5.932887e7", "59328870.000"},
{"5.932887e7abc", "59328870.000"},
{"a1a1", "0.000"},
},
},
{
Query: "select * from test01 where pk in ('11')",
Expected: []sql.Row{{"11"}},
},
{
// https://github.com/dolthub/dolt/issues/9739
Skip: true,
Dialect: "mysql",
Query: "select * from test01 where pk in (11)",
Expected: []sql.Row{
{"11"},
{"11-5"},
{"11d"},
{"11wha?"},
},
},
{
// https://github.com/dolthub/dolt/issues/9739
Skip: true,
Dialect: "mysql",
Query: "select * from test01 where pk=3",
Expected: []sql.Row{
{types.NewOkResult(0)},
{" 3 12 4"},
{" 3. 12 4"},
{"3. 12 4"},
},
},
{
Query: "call create_proc()",
// https://github.com/dolthub/dolt/issues/9739
Skip: true,
Dialect: "mysql",
Query: "select * from test01 where pk>=3 and pk < 4",
Expected: []sql.Row{
{types.NewOkResult(0)},
{" 3 12 4"},
{" 3. 12 4"},
{" 3.2 12 4"},
{"+3.1234"},
{"3. 12 4"},
},
},
//{
// // https://github.com/dolthub/dolt/issues/9739
// Skip: true,
// Dialect: "mysql",
// Query: "select * from test02 where pk in ('11asdf')",
// Expected: []sql.Row{{"11"}},
//},
//{
// // https://github.com/dolthub/dolt/issues/9739
// Skip: true,
// Dialect: "mysql",
// Query: "select * from test02 where pk='11.12asdf'",
// Expected: []sql.Row{},
//},
},
},
//{
// Name: "AS OF propagates to nested CALLs",
// SetUpScript: []string{},
// Assertions: []queries.ScriptTestAssertion{
// {
// Query: "select cast('123.99' as signed);",
// Expected: []sql.Row{
// {123},
// },
// },
// // TODO: some how fix this
// {
// Query: "select x'20' = 32;",
// Expected: []sql.Row{
// {types.NewOkResult(0)},
// },
// },
// },
//},

//{
// Name: "AS OF propagates to nested CALLs",
// SetUpScript: []string{},
// Assertions: []queries.ScriptTestAssertion{
// {
// Query: "select cast('123.99' as signed);",
// Expected: []sql.Row{
// {123},
// },
// },
// // TODO: some how fix this
// {
// Query: "select x'20' = 32;",
// Expected: []sql.Row{
// {types.NewOkResult(0)},
// },
// },
// },
//},
}

for _, test := range scripts {
harness := enginetest.NewMemoryHarness("", 1, testNumPartitions, true, nil)
//harness.UseServer()
harness.UseServer()
engine, err := harness.NewEngine(t)
if err != nil {
panic(err)
Expand Down
6 changes: 3 additions & 3 deletions enginetest/queries/alter_table_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,9 +1011,9 @@ var AlterTableScripts = []ScriptTest{
Name: "alter modify column type float to bigint",
SetUpScript: []string{
"create table t1 (pk int primary key, c1 float);",
"insert into t1 values (1, 0.0)",
"insert into t1 values (2, 127.9)",
"insert into t1 values (3, 42.1)",
"insert into t1 values (1, 0.0);",
"insert into t1 values (2, 127.9);",
"insert into t1 values (3, 42.1);",
},
Assertions: []ScriptTestAssertion{
{
Expand Down
4 changes: 2 additions & 2 deletions enginetest/queries/json_table_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ var JSONTableScriptTests = []ScriptTest{
},
{
Query: "SELECT * FROM JSON_TABLE('{\"c1\":\"abc\"}', '$' COLUMNS(c1 INT PATH '$.c1' DEFAULT 'def' ON ERROR)) as jt;",
ExpectedErrStr: "error: 'def' is not a valid value for 'int'",
ExpectedErrStr: "Invalid JSON text in argument 1 to function JSON_TABLE: \"Invalid value.\"",
},
},
},
Expand Down Expand Up @@ -612,7 +612,7 @@ var JSONTableScriptTests = []ScriptTest{
},
{
Query: "SELECT * FROM JSON_TABLE('{\"c1\":\"abc\"}', '$' COLUMNS(c1 INT PATH '$.c1' ERROR ON ERROR)) as jt;",
ExpectedErrStr: "error: 'abc' is not a valid value for 'int'",
ExpectedErrStr: "Invalid JSON text in argument 1 to function JSON_TABLE: \"Invalid value.\"",
},
},
},
Expand Down
9 changes: 5 additions & 4 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -3932,6 +3932,7 @@ CREATE TABLE tab3 (
},
},
{
Skip: true, // TODO: Aaaaaaaaaaaa
Name: "Handle hex number to binary conversion",
SetUpScript: []string{
"CREATE TABLE hex_nums1 (pk BIGINT PRIMARY KEY, v1 INT, v2 BIGINT UNSIGNED, v3 DOUBLE, v4 BINARY(32));",
Expand Down Expand Up @@ -11778,13 +11779,13 @@ select * from t1 except (
// https://github.com/dolthub/dolt/issues/9739
Name: "strings cast to numbers",
SetUpScript: []string{
"create table test01(pk varchar(20) primary key)",
"create table test01(pk varchar(20) primary key);",
`insert into test01 values (' 3 12 4'),
(' 3.2 12 4'),('-3.1234'),('-3.1a'),('-5+8'),('+3.1234'),
('11d'),('11wha?'),('11'),('12'),('1a1'),('a1a1'),('11-5'),
('3. 12 4'),('5.932887e+07'),('5.932887e+07abc'),('5.932887e7'),('5.932887e7abc')`,
"create table test02(pk int primary key)",
"insert into test02 values(11),(12),(13),(14),(15)",
('3. 12 4'),('5.932887e+07'),('5.932887e+07abc'),('5.932887e7'),('5.932887e7abc');`,
"create table test02(pk int primary key);",
"insert into test02 values(11),(12),(13),(14),(15);",
},
Assertions: []ScriptTestAssertion{
{
Expand Down
4 changes: 2 additions & 2 deletions enginetest/queries/type_wire_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,8 @@ var TypeWireTests = []TypeWireTest{
SetUpScript: []string{
`CREATE TABLE test (pk SET("a","b","c") PRIMARY KEY, v1 SET("w","x","y","z"));`,
`INSERT INTO test VALUES (0, 1), ("b", "y"), ("b,c", "z,z"), ("a,c,b", 10);`,
`UPDATE test SET v1 = "y,x,w" WHERE pk >= 4`,
`DELETE FROM test WHERE pk > "b,c";`,
`UPDATE test SET v1 = "y,x,w" WHERE pk >= 4;`,
`DELETE FROM test WHERE pk = "a,b,c";`,
},
Queries: []string{
`SELECT * FROM test ORDER BY pk;`,
Expand Down
5 changes: 4 additions & 1 deletion memory/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1430,11 +1430,14 @@ func (t *Table) ModifyColumn(ctx *sql.Context, columnName string, column *sql.Co
oldRowWithoutVal = append(oldRowWithoutVal, row[:oldIdx]...)
oldRowWithoutVal = append(oldRowWithoutVal, row[oldIdx+1:]...)
oldType := data.schema.Schema[oldIdx].Type
newVal, inRange, err := types.TypeAwareConversion(ctx, row[oldIdx], oldType, column.Type)
newVal, inRange, err := types.TypeAwareConversion(ctx, row[oldIdx], oldType, column.Type, true)
if err != nil {
if sql.ErrNotMatchingSRID.Is(err) {
err = sql.ErrNotMatchingSRIDWithColName.New(columnName, err)
}
if sql.ErrTruncatedIncorrect.Is(err) {
err = sql.ErrInvalidValue.New(row[oldIdx], column.Type)
}
return err
}
if !inRange {
Expand Down
2 changes: 1 addition & 1 deletion server/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ func TestStatusVariableMaxUsedConnections(t *testing.T) {
}

checkGlobalStatVar(t, "Max_used_connections", uint64(0))
checkGlobalStatVar(t, "Max_used_connections_time", "")
checkGlobalStatVar(t, "Max_used_connections_time", uint64(0))

conn1 := newConn(1)
handler.NewConnection(conn1)
Expand Down
2 changes: 1 addition & 1 deletion sql/analyzer/resolve_column_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func normalizeDefault(ctx *sql.Context, colDefault *sql.ColumnDefaultValue) (sql
}
val, err := colDefault.Eval(ctx, nil)
if err != nil {
return colDefault, transform.SameTree, nil
return nil, transform.SameTree, err
}

newDefault, err := colDefault.WithChildren(expression.NewLiteral(val, typ))
Expand Down
12 changes: 9 additions & 3 deletions sql/columndefault.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ func (e *ColumnDefaultValue) Eval(ctx *Context, r Row) (interface{}, error) {

if e.OutType != nil {
var inRange ConvertInRange
if val, inRange, err = e.OutType.Convert(ctx, val); err != nil {
if roundType, isRoundType := e.OutType.(RoundingNumberType); isRoundType {
val, inRange, err = roundType.ConvertRound(ctx, val)
} else {
val, inRange, err = e.OutType.Convert(ctx, val)
}
if err != nil {
return nil, ErrIncompatibleDefaultType.New()
} else if !inRange {
}
if !inRange {
return nil, ErrValueOutOfRange.New(val, e.OutType)
}
}
Expand Down Expand Up @@ -228,7 +234,7 @@ func (e *ColumnDefaultValue) CheckType(ctx *Context) error {
return ErrIncompatibleDefaultType.New()
}
_, inRange, err := e.OutType.Convert(ctx, val)
if err != nil {
if err != nil && !ErrTruncatedIncorrect.Is(err) {
return ErrIncompatibleDefaultType.Wrap(err)
} else if !inRange {
return ErrIncompatibleDefaultType.Wrap(ErrValueOutOfRange.New(val, e.Expr))
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (c *Case) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
}
// When unable to convert to the type of the case, return the original value
// A common error here is "Out of bounds value for decimal type"
if ret, inRange, err := types.TypeAwareConversion(ctx, bval, b.Value.Type(), t); inRange && err == nil {
if ret, inRange, err := types.TypeAwareConversion(ctx, bval, b.Value.Type(), t, false); inRange && err == nil {
return ret, nil
}
return bval, nil
Expand All @@ -150,7 +150,7 @@ func (c *Case) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
}
// When unable to convert to the type of the case, return the original value
// A common error here is "Out of bounds value for decimal type"
if ret, inRange, err := types.TypeAwareConversion(ctx, val, c.Else.Type(), t); inRange && err == nil {
if ret, inRange, err := types.TypeAwareConversion(ctx, val, c.Else.Type(), t, false); inRange && err == nil {
return ret, nil
}
return val, nil
Expand Down
Loading
Loading