-
-
Notifications
You must be signed in to change notification settings - Fork 238
Add Wrapper values #2893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Wrapper values #2893
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
cfde3c5
Implement values.Wrapper and values.AnyWrapper
nicktobey a92ff64
Propagate context parameter.
nicktobey 91f1c0d
[ga-format-pr] Run ./format_repo.sh to fix formatting
nicktobey 12d340f
Add extra checks to wrapper test
nicktobey 2ce4c01
Amend toast implementation
nicktobey b49ea60
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey 48e833f
Unwrap values before casting them to strings or bytes.
nicktobey d8edd4c
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey d4589a3
Unwrap wrapped values when computing hashes for keyless tables.
nicktobey 9f11af5
Migrate explicit string casts to calls to sql.Unwrap
nicktobey 8a2ead9
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey ba2722f
Make NewUpdateResult public
nicktobey 1867e61
Allow tests that inspect the encoding of a wrapped value without unwr…
nicktobey f5b659e
Disable the short circuiting of comparing wrapped values until we con…
nicktobey 0dc98df
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey 92b9799
Respond to PR feedback.
nicktobey a17f203
[ga-format-pr] Run ./format_repo.sh to fix formatting
nicktobey 543ddd0
Unwrap values when inserting them into a key cache.
nicktobey e17df0b
more precision fixes for `unix_timestamp` (#2918)
jycor 9170b3c
Unwrap wrapped values in Like expressions.
nicktobey 2ac2dec
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey 9988aef
Propagate context parameter.
nicktobey 54ed687
Propagate context parameter.
nicktobey 4569796
Update tests
nicktobey 1d90344
Propogate context in StringType::Compare
nicktobey 822f120
Add context parameter to DatetimeType::Compare
nicktobey 8c2fddb
WIP propogate context parameter
nicktobey f950002
Propogate context parameter
nicktobey 56c0371
Allow nil ctx parameter in globalStatusVariables::SetGlobal
nicktobey e5862b5
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
nicktobey d169367
[ga-format-pr] Run ./format_repo.sh to fix formatting
nicktobey 5585f96
Don't create sql.Context in MySQLRangeCut.Compare
nicktobey 00fc297
Propogate context parameter.
nicktobey b3f3563
Propogate context parameter, and remove redundant context instantiati…
nicktobey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| // Copyright 2025 Dolthub, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package enginetest | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| sqle "github.com/dolthub/go-mysql-server" | ||
| "github.com/dolthub/go-mysql-server/memory" | ||
| "github.com/dolthub/go-mysql-server/sql" | ||
| "github.com/dolthub/go-mysql-server/sql/planbuilder" | ||
| "github.com/dolthub/go-mysql-server/sql/types" | ||
| ) | ||
|
|
||
| // ErrorWrapper is a wrapped type that errors when unwrapped. This can be used to test that certain operations | ||
| // won't trigger an unwrap. | ||
| type ErrorWrapper[T any] struct { | ||
| maxByteLength int64 | ||
| isExactLength bool | ||
| } | ||
|
|
||
| func (w ErrorWrapper[T]) Compare(ctx context.Context, other interface{}) (cmp int, comparable bool, err error) { | ||
| return 0, false, nil | ||
| } | ||
|
|
||
| var textErrorWrapper = ErrorWrapper[string]{maxByteLength: types.Text.MaxByteLength(), isExactLength: false} | ||
| var longTextErrorWrapper = ErrorWrapper[string]{maxByteLength: types.LongText.MaxByteLength(), isExactLength: false} | ||
|
|
||
| func exactLengthErrorWrapper(maxByteLength int64) ErrorWrapper[string] { | ||
| return ErrorWrapper[string]{maxByteLength: maxByteLength, isExactLength: true} | ||
| } | ||
|
|
||
| func (w ErrorWrapper[T]) assertInterfaces() { | ||
| var _ sql.Wrapper[T] = w | ||
| } | ||
|
|
||
| func (w ErrorWrapper[T]) Unwrap(ctx context.Context) (result T, err error) { | ||
| return result, fmt.Errorf("unwrap failed") | ||
| } | ||
|
|
||
| func (w ErrorWrapper[T]) UnwrapAny(ctx context.Context) (result interface{}, err error) { | ||
| return result, fmt.Errorf("unwrap failed") | ||
| } | ||
|
|
||
| func (w ErrorWrapper[T]) MaxByteLength() int64 { | ||
| return w.maxByteLength | ||
| } | ||
|
|
||
| func (w ErrorWrapper[T]) IsExactLength() bool { | ||
| return w.isExactLength | ||
| } | ||
|
|
||
| func setupWrapperTests(t *testing.T) (*sql.Context, *memory.Database, *MemoryHarness, *sqle.Engine) { | ||
| db := memory.NewDatabase("mydb") | ||
| pro := memory.NewDBProvider(db) | ||
| harness := NewDefaultMemoryHarness().WithProvider(pro) | ||
| ctx := NewContext(harness) | ||
| e := NewEngineWithProvider(t, harness, pro) | ||
| return ctx, db, harness, e | ||
| } | ||
|
|
||
| // TestWrapperCopyInKey tests that copying a wrapped value in the primary key doesn't require the value to be unwrapped. | ||
| // This is skipped because inserting into tables requires comparisons between primary keys, which currently requires | ||
| // unwrapping. But in the future, we may be able to skip fully unwrapping values for specific operations. | ||
| func TestWrapperCopyInKey(t *testing.T) { | ||
| t.Skip() | ||
| ctx, db, harness, e := setupWrapperTests(t) | ||
|
|
||
| schema := sql.NewPrimaryKeySchema(sql.Schema{ | ||
| &sql.Column{Name: "col1", Source: "test", Type: types.LongText, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `""`, types.Text, false)}, | ||
| }) | ||
| table := memory.NewTable(db.BaseDatabase, "test", schema, nil) | ||
|
|
||
| require.NoError(t, table.Insert(ctx, sql.Row{"brave"})) | ||
| require.NoError(t, table.Insert(ctx, sql.Row{longTextErrorWrapper})) | ||
| require.NoError(t, table.Insert(ctx, sql.Row{"!"})) | ||
|
|
||
| TestQueryWithContext(t, ctx, e, harness, "CREATE TABLE t2 AS SELECT 1, col1, 2 FROM test;", nil, nil, nil, nil) | ||
| } | ||
|
|
||
| // TestWrapperCopyInKey tests that copying a wrapped value not in the primary key doesn't require the value to be unwrapped. | ||
| func TestWrapperCopyNotInKey(t *testing.T) { | ||
| ctx, db, harness, e := setupWrapperTests(t) | ||
|
|
||
| schema := sql.NewPrimaryKeySchema(sql.Schema{ | ||
| &sql.Column{Name: "pk", Source: "test", Type: types.Int64, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `1`, types.Int64, false), PrimaryKey: true}, | ||
| &sql.Column{Name: "col1", Source: "test", Type: types.LongText, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `""`, types.Text, false), PrimaryKey: false}, | ||
| }) | ||
|
|
||
| testTable := memory.NewTable(db.BaseDatabase, "test", schema, nil) | ||
| db.AddTable("test", testTable) | ||
|
|
||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(1), "brave"})) | ||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(2), longTextErrorWrapper})) | ||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(3), "!"})) | ||
|
|
||
| copySchema := sql.NewPrimaryKeySchema(sql.Schema{ | ||
| &sql.Column{Name: "one", Source: "t2", Type: types.Int64, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `1`, types.Int64, false), PrimaryKey: true}, | ||
| &sql.Column{Name: "pk", Source: "t2", Type: types.Int64, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `1`, types.Int64, false), PrimaryKey: true}, | ||
| &sql.Column{Name: "col1", Source: "t2", Type: types.LongText, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `""`, types.Text, false), PrimaryKey: false}, | ||
| &sql.Column{Name: "two", Source: "t2", Type: types.Int64, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `1`, types.Int64, false), PrimaryKey: false}, | ||
| }) | ||
|
|
||
| testTable2 := memory.NewTable(db.BaseDatabase, "t2", copySchema, nil) | ||
| db.AddTable("t2", testTable2) | ||
|
|
||
| TestQueryWithContext(t, ctx, e, harness, "INSERT INTO t2 SELECT 1, pk, col1, 2 FROM test;", nil, nil, nil, nil) | ||
| } | ||
|
|
||
| // TestWrapperCopyWhenWideningColumn tests that widening a column doesn't cause values to be unwrapped. | ||
| func TestWrapperCopyWhenWideningColumn(t *testing.T) { | ||
| ctx, db, harness, e := setupWrapperTests(t) | ||
|
|
||
| schema := sql.NewPrimaryKeySchema(sql.Schema{ | ||
| &sql.Column{Name: "pk", Source: "test", Type: types.Int64, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `1`, types.Int64, false), PrimaryKey: true}, | ||
| &sql.Column{Name: "col1", Source: "test", Type: types.Text, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `""`, types.Text, false), PrimaryKey: false}, | ||
| }) | ||
|
|
||
| testTable := memory.NewTable(db.BaseDatabase, "test", schema, nil) | ||
| db.AddTable("test", testTable) | ||
|
|
||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(1), "brave"})) | ||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(2), textErrorWrapper})) | ||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(3), "!"})) | ||
|
|
||
| TestQueryWithContext(t, ctx, e, harness, "ALTER TABLE test MODIFY COLUMN col1 LONGTEXT;", nil, nil, nil, nil) | ||
| } | ||
|
|
||
| // TestWrapperCopyWhenWideningColumn tests that widening a column doesn't cause values to be unwrapped. | ||
| func TestWrapperCopyWhenNarrowingColumn(t *testing.T) { | ||
| ctx, db, harness, e := setupWrapperTests(t) | ||
|
|
||
| schema := sql.NewPrimaryKeySchema(sql.Schema{ | ||
| &sql.Column{Name: "pk", Source: "test", Type: types.Int64, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `1`, types.Int64, false), PrimaryKey: true}, | ||
| &sql.Column{Name: "col1", Source: "test", Type: types.LongText, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `""`, types.Text, false), PrimaryKey: false}, | ||
| }) | ||
|
|
||
| testTable := memory.NewTable(db.BaseDatabase, "test", schema, nil) | ||
| db.AddTable("test", testTable) | ||
|
|
||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(1), "brave"})) | ||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(2), longTextErrorWrapper})) | ||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(3), "!"})) | ||
|
|
||
| AssertErrWithCtx(t, e, harness, ctx, "ALTER TABLE test MODIFY COLUMN col1 TEXT;", nil, nil, "unwrap failed") | ||
| } | ||
|
|
||
| func TestWrapperCopyWithExactLengthWhenNarrowingColumn(t *testing.T) { | ||
| ctx, db, harness, e := setupWrapperTests(t) | ||
|
|
||
| schema := sql.NewPrimaryKeySchema(sql.Schema{ | ||
| &sql.Column{Name: "pk", Source: "test", Type: types.Int64, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `1`, types.Int64, false), PrimaryKey: true}, | ||
| &sql.Column{Name: "col1", Source: "test", Type: types.LongText, Nullable: false, Default: planbuilder.MustStringToColumnDefaultValue(sql.NewEmptyContext(), `""`, types.Text, false), PrimaryKey: false}, | ||
| }) | ||
|
|
||
| testTable := memory.NewTable(db.BaseDatabase, "test", schema, nil) | ||
| db.AddTable("test", testTable) | ||
|
|
||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(1), "brave"})) | ||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(2), exactLengthErrorWrapper(64)})) | ||
| require.NoError(t, testTable.Insert(ctx, sql.Row{int64(3), "!"})) | ||
|
|
||
| TestQueryWithContext(t, ctx, e, harness, "ALTER TABLE test MODIFY COLUMN col1 TEXT;", nil, nil, nil, nil) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.