Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cfde3c5
Implement values.Wrapper and values.AnyWrapper
nicktobey Mar 5, 2025
a92ff64
Propagate context parameter.
nicktobey Mar 14, 2025
91f1c0d
[ga-format-pr] Run ./format_repo.sh to fix formatting
nicktobey Mar 17, 2025
12d340f
Add extra checks to wrapper test
nicktobey Mar 19, 2025
2ce4c01
Amend toast implementation
nicktobey Mar 20, 2025
b49ea60
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey Mar 21, 2025
48e833f
Unwrap values before casting them to strings or bytes.
nicktobey Mar 24, 2025
d8edd4c
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey Mar 24, 2025
d4589a3
Unwrap wrapped values when computing hashes for keyless tables.
nicktobey Mar 25, 2025
9f11af5
Migrate explicit string casts to calls to sql.Unwrap
nicktobey Mar 25, 2025
8a2ead9
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey Mar 26, 2025
ba2722f
Make NewUpdateResult public
nicktobey Mar 27, 2025
1867e61
Allow tests that inspect the encoding of a wrapped value without unwr…
nicktobey Mar 27, 2025
f5b659e
Disable the short circuiting of comparing wrapped values until we con…
nicktobey Mar 27, 2025
0dc98df
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey Mar 27, 2025
92b9799
Respond to PR feedback.
nicktobey Mar 28, 2025
a17f203
[ga-format-pr] Run ./format_repo.sh to fix formatting
nicktobey Mar 28, 2025
543ddd0
Unwrap values when inserting them into a key cache.
nicktobey Mar 28, 2025
e17df0b
more precision fixes for `unix_timestamp` (#2918)
jycor Mar 28, 2025
9170b3c
Unwrap wrapped values in Like expressions.
nicktobey Apr 1, 2025
2ac2dec
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey Apr 1, 2025
9988aef
Propagate context parameter.
nicktobey Apr 1, 2025
54ed687
Propagate context parameter.
nicktobey Apr 1, 2025
4569796
Update tests
nicktobey Apr 1, 2025
1d90344
Propogate context in StringType::Compare
nicktobey Apr 1, 2025
822f120
Add context parameter to DatetimeType::Compare
nicktobey Apr 1, 2025
8c2fddb
WIP propogate context parameter
nicktobey Apr 1, 2025
f950002
Propogate context parameter
nicktobey Apr 1, 2025
56c0371
Allow nil ctx parameter in globalStatusVariables::SetGlobal
nicktobey Apr 1, 2025
e5862b5
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey Apr 2, 2025
d169367
[ga-format-pr] Run ./format_repo.sh to fix formatting
nicktobey Apr 2, 2025
5585f96
Don't create sql.Context in MySQLRangeCut.Compare
nicktobey Apr 4, 2025
00fc297
Propogate context parameter.
nicktobey Apr 4, 2025
b3f3563
Propogate context parameter, and remove redundant context instantiati…
nicktobey Apr 7, 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
6 changes: 4 additions & 2 deletions enginetest/enginetests.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func TestBrokenQueries(t *testing.T, harness Harness) {
// queries during debugging.
func RunQueryTests(t *testing.T, harness Harness, queries []queries.QueryTest) {
for _, tt := range queries {
TestQuery(t, harness, tt.Query, tt.Expected, tt.ExpectedColumns, nil)
testQuery(t, harness, tt.Query, tt.Expected, tt.ExpectedColumns, nil, !tt.DontUnwrap)
}
}

Expand Down Expand Up @@ -848,7 +848,9 @@ func TestOrderByGroupBy(t *testing.T, harness Harness) {
panic(fmt.Sprintf("unexpected type %T", v))
}

team := row[1].(string)
team, ok, err := sql.Unwrap[string](ctx, row[1])
require.True(t, ok)
require.NoError(t, err)
switch team {
case "red":
require.True(t, val == 3 || val == 4)
Expand Down
66 changes: 52 additions & 14 deletions enginetest/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ func TestTransactionScriptWithEngine(t *testing.T, e QueryEngine, harness Harnes
// TestQuery runs a query on the engine given and asserts that results are as expected.
// TODO: this should take en engine
func TestQuery(t *testing.T, harness Harness, q string, expected []sql.Row, expectedCols []*sql.Column, bindings map[string]sqlparser.Expr) {
testQuery(t, harness, q, expected, expectedCols, bindings, true)
}

func testQuery(t *testing.T, harness Harness, q string, expected []sql.Row, expectedCols []*sql.Column, bindings map[string]sqlparser.Expr, unwrapValues bool) {
t.Run(q, func(t *testing.T) {
if sh, ok := harness.(SkippingHarness); ok {
if sh.SkipQueryTest(q) {
Expand All @@ -336,7 +340,7 @@ func TestQuery(t *testing.T, harness Harness, q string, expected []sql.Row, expe
e := mustNewEngine(t, harness)
defer e.Close()
ctx := NewContext(harness)
TestQueryWithContext(t, ctx, e, harness, q, expected, expectedCols, bindings, nil)
testQueryWithContext(t, ctx, e, harness, q, expected, expectedCols, bindings, nil, unwrapValues)
})
}

Expand Down Expand Up @@ -378,6 +382,21 @@ func TestQueryWithContext(
expectedCols []*sql.Column,
bindings map[string]sqlparser.Expr,
qFlags *sql.QueryFlags,
) {
testQueryWithContext(t, ctx, e, harness, q, expected, expectedCols, bindings, qFlags, true)
}

func testQueryWithContext(
t *testing.T,
ctx *sql.Context,
e QueryEngine,
harness Harness,
q string,
expected []sql.Row,
expectedCols []*sql.Column,
bindings map[string]sqlparser.Expr,
qFlags *sql.QueryFlags,
unwrapValues bool,
) {
ctx = ctx.WithQuery(q)
require := require.New(t)
Expand All @@ -393,7 +412,7 @@ func TestQueryWithContext(
require.NoError(err, "Unexpected error for query %s: %s", q, err)

if expected != nil {
CheckResults(t, harness, expected, expectedCols, sch, rows, q, e)
checkResults(t, harness, expected, expectedCols, sch, rows, q, e, unwrapValues)
}

require.Equal(
Expand Down Expand Up @@ -502,7 +521,6 @@ func TestPreparedQueryWithContext(t *testing.T, ctx *sql.Context, e QueryEngine,
validateEngine(t, ctx, h, e)
}

// CheckResults compares the
func CheckResults(
t *testing.T,
h Harness,
Expand All @@ -512,11 +530,25 @@ func CheckResults(
rows []sql.Row,
q string,
e QueryEngine,
) {
checkResults(t, h, expected, expectedCols, sch, rows, q, e, true)
}

func checkResults(
t *testing.T,
h Harness,
expected []sql.Row,
expectedCols []*sql.Column,
sch sql.Schema,
rows []sql.Row,
q string,
e QueryEngine,
unwrapValues bool,
) {
if reh, ok := h.(ResultEvaluationHarness); ok {
reh.EvaluateQueryResults(t, expected, expectedCols, sch, rows, q)
reh.EvaluateQueryResults(t, expected, expectedCols, sch, rows, q, unwrapValues)
} else {
checkResults(t, expected, expectedCols, sch, rows, q, e)
checkResultsDefault(t, expected, expectedCols, sch, rows, q, e, unwrapValues)
}
}

Expand Down Expand Up @@ -669,16 +701,19 @@ func toSQL(c *sql.Column, expected any, isZeroTime bool) (any, error) {
}
}

// checkResults is the default implementation for checking the results of a test query assertion for harnesses that
// checkResultsDefault is the default implementation for checking the results of a test query assertion for harnesses that
// don't implement ResultEvaluationHarness. All numerical values are widened to their widest type before comparison.
func checkResults(
// Based on the value of |unwrapValues|, this either normalized wrapped values by unwrapping them, or replaces them
// with their hash so the test caller can assert that the values are wrapped and have a certain hash.
func checkResultsDefault(
t *testing.T,
expected []sql.Row,
expectedCols []*sql.Column,
sch sql.Schema,
rows []sql.Row,
q string,
e QueryEngine,
unwrapValues bool,
) {
widenedRows := WidenRows(t, sch, rows)
widenedExpected := WidenRows(t, sch, expected)
Expand Down Expand Up @@ -715,6 +750,14 @@ func checkResults(
widenedRow[i] = el
}
}
case sql.AnyWrapper:
if unwrapValues {
var err error
widenedRow[i], err = sql.UnwrapAny(context.Background(), v)
require.NoError(t, err)
} else {
widenedRow[i] = v.Hash()
}
}
}
}
Expand Down Expand Up @@ -825,7 +868,6 @@ func WidenRow(t *testing.T, sch sql.Schema, row sql.Row) sql.Row {

// widenValue normalizes the input by widening it to its widest type and unwrapping any wrappers.
func widenValue(t *testing.T, v interface{}) (vw interface{}) {
var err error
switch x := v.(type) {
case int:
vw = int64(x)
Expand All @@ -850,10 +892,6 @@ func widenValue(t *testing.T, v interface{}) (vw interface{}) {
// The exact expected decimal type value cannot be defined in enginetests,
// so convert the result to string format, which is the value we get on sql shell.
vw = x.StringFixed(x.Exponent() * -1)
case sql.AnyWrapper:
vw, err = x.UnwrapAny(context.Background())
vw = widenValue(t, vw)
require.NoError(t, err)
default:
vw = v
}
Expand Down Expand Up @@ -1160,12 +1198,12 @@ func RunWriteQueryTestWithEngine(t *testing.T, harness Harness, e QueryEngine, t
}

ctx := NewContext(harness)
TestQueryWithContext(t, ctx, e, harness, tt.WriteQuery, tt.ExpectedWriteResult, nil, nil, nil)
testQueryWithContext(t, ctx, e, harness, tt.WriteQuery, tt.ExpectedWriteResult, nil, nil, nil, !tt.DontUnwrap)
expectedSelect := tt.ExpectedSelect
if IsServerEngine(e) && tt.SkipServerEngine {
expectedSelect = nil
}
TestQueryWithContext(t, ctx, e, harness, tt.SelectQuery, expectedSelect, nil, nil, nil)
testQueryWithContext(t, ctx, e, harness, tt.SelectQuery, expectedSelect, nil, nil, nil, !tt.DontUnwrap)
}

func supportedDialect(harness Harness, dialect string) bool {
Expand Down
1 change: 1 addition & 0 deletions enginetest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ type ResultEvaluationHarness interface {
expectdSch sql.Schema,
actualRows []sql.Row,
query string,
unwrapValues bool,
)

// EvaluateExpectedError compares expected error strings to actual errors and emits failed test assertions in the
Expand Down
4 changes: 2 additions & 2 deletions enginetest/queries/blob_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var BlobWriteQueries = []WriteQueryTest{
},
{
WriteQuery: "update blobt set b = '100000000' where i = 1",
ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}},
ExpectedWriteResult: []sql.Row{{NewUpdateResult(1, 1)}},
SelectQuery: "select * from blobt where i = 1",
ExpectedSelect: []sql.Row{{1, []byte("100000000")}},
},
Expand Down Expand Up @@ -130,7 +130,7 @@ var BlobWriteQueries = []WriteQueryTest{
},
{
WriteQuery: "update textt set t = '100000000' where i = 1",
ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}},
ExpectedWriteResult: []sql.Row{{NewUpdateResult(1, 1)}},
SelectQuery: "select * from textt where i = 1",
ExpectedSelect: []sql.Row{{1, "100000000"}},
},
Expand Down
4 changes: 2 additions & 2 deletions enginetest/queries/column_default_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var ColumnDefaultTests = []ScriptTest{
Assertions: []ScriptTestAssertion{
{
Query: "update t1 n inner join t2 m on n.name = m.name set n.cnt =m.cnt+1;",
Expected: []sql.Row{{newUpdateResult(2, 2)}},
Expected: []sql.Row{{NewUpdateResult(2, 2)}},
},
{
Query: "select name, cnt from t1",
Expand All @@ -48,7 +48,7 @@ var ColumnDefaultTests = []ScriptTest{
Assertions: []ScriptTestAssertion{
{
Query: "update t1 n inner join t2 m on n.y = m.y set n.x =n.y where n.x = 3;",
Expected: []sql.Row{{newUpdateResult(1, 1)}},
Expected: []sql.Row{{NewUpdateResult(1, 1)}},
},
{
Query: "select * from t1",
Expand Down
10 changes: 5 additions & 5 deletions enginetest/queries/generated_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var GeneratedColumnTests = []ScriptTest{
},
{
Query: "update t1 set a = 10 where a = 1",
Expected: []sql.Row{{newUpdateResult(1, 1)}},
Expected: []sql.Row{{NewUpdateResult(1, 1)}},
},
{
Query: "select * from t1 order by a",
Expand Down Expand Up @@ -149,7 +149,7 @@ var GeneratedColumnTests = []ScriptTest{
},
{
Query: "update t1 set a = 10 where a = 1",
Expected: []sql.Row{{newUpdateResult(1, 1)}},
Expected: []sql.Row{{NewUpdateResult(1, 1)}},
},
{
Query: "select * from t1 where b = 11 order by a",
Expand Down Expand Up @@ -466,7 +466,7 @@ var GeneratedColumnTests = []ScriptTest{
},
{
Query: "update t1 set a = 5, c = 10 where b = 2 and c = 3",
Expected: []sql.Row{{newUpdateResult(1, 1)}},
Expected: []sql.Row{{NewUpdateResult(1, 1)}},
},
{
Query: "select * from t1 where b = 6 and c = 10 order by a",
Expand Down Expand Up @@ -1006,7 +1006,7 @@ var GeneratedColumnTests = []ScriptTest{
},
{
Query: "update t1 set b = 5 where c = 3",
Expected: []sql.Row{{newUpdateResult(1, 1)}},
Expected: []sql.Row{{NewUpdateResult(1, 1)}},
},
{
Query: "select * from t1 order by a",
Expand Down Expand Up @@ -1046,7 +1046,7 @@ var GeneratedColumnTests = []ScriptTest{
},
{
Query: "update t1 set j = '{\"a\": 5}' where v = 2",
Expected: []sql.Row{{newUpdateResult(1, 1)}},
Expected: []sql.Row{{NewUpdateResult(1, 1)}},
},
{
Query: "select * from t1 order by v",
Expand Down
8 changes: 4 additions & 4 deletions enginetest/queries/insert_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -2895,7 +2895,7 @@ var IgnoreWithDuplicateUniqueKeyKeylessScripts = []ScriptTest{
Assertions: []ScriptTestAssertion{
{
Query: "UPDATE IGNORE keyless SET val = 2 where pk = 1",
Expected: []sql.Row{{newUpdateResult(1, 1)}},
Expected: []sql.Row{{NewUpdateResult(1, 1)}},
},
{
Query: "SELECT * FROM keyless ORDER BY pk",
Expand All @@ -2907,15 +2907,15 @@ var IgnoreWithDuplicateUniqueKeyKeylessScripts = []ScriptTest{
},
{
Query: "UPDATE IGNORE keyless SET val = 1 where pk = 1",
Expected: []sql.Row{{newUpdateResult(1, 1)}},
Expected: []sql.Row{{NewUpdateResult(1, 1)}},
},
{
Query: "ALTER TABLE keyless ADD CONSTRAINT c UNIQUE(val)",
Expected: []sql.Row{{types.NewOkResult(0)}},
},
{
Query: "UPDATE IGNORE keyless SET val = 3 where pk = 1",
Expected: []sql.Row{{newUpdateResult(1, 0)}},
Expected: []sql.Row{{NewUpdateResult(1, 0)}},
ExpectedWarningsCount: 1,
ExpectedWarning: mysql.ERDupEntry,
},
Expand All @@ -2925,7 +2925,7 @@ var IgnoreWithDuplicateUniqueKeyKeylessScripts = []ScriptTest{
},
{
Query: "UPDATE IGNORE keyless SET val = val + 1 ORDER BY pk",
Expected: []sql.Row{{newUpdateResult(3, 1)}},
Expected: []sql.Row{{NewUpdateResult(3, 1)}},
ExpectedWarningsCount: 2,
ExpectedWarning: mysql.ERDupEntry,
},
Expand Down
8 changes: 8 additions & 0 deletions enginetest/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type QueryTest struct {
// Dialect is the supported dialect for this query, which must match the dialect of the harness if specified.
// The query is skipped if the dialect doesn't match.
Dialect string
// DontUnwrap indicates whether to skip normalizing the select results via unwrapping wrapped values.
// Instead, the test engine will replace wrapped values with their hash (as determined by sql.AnyWrapped.Hash).
// Set this to test the exact encodings being returned by the query.
DontUnwrap bool
}

type QueryPlanTest struct {
Expand Down Expand Up @@ -11387,6 +11391,10 @@ type WriteQueryTest struct {
// Dialect is the supported dialect for this test, which must match the dialect of the harness if specified.
// The script is skipped if the dialect doesn't match.
Dialect string
// DontUnwrap indicates whether to skip normalizing the select results via unwrapping wrapped values.
// Instead, the test engine will replace wrapped values with their hash (as determined by sql.AnyWrapped.Hash).
// Set this to test the exact encodings being returned by the query.
DontUnwrap bool
}

// GenericErrorQueryTest is a query test that is used to assert an error occurs for some query, without specifying what
Expand Down
Loading
Loading