Merge pull request #10248 from dolthub/angela/key_conversion

Return nil lookupMapping if type conversion is not in range for lookup key
This commit is contained in:
angelamayxie
2025-12-30 15:27:05 -08:00
committed by GitHub
3 changed files with 12 additions and 10 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ require (
github.com/dolthub/dolt-mcp v0.2.2
github.com/dolthub/eventsapi_schema v0.0.0-20250915094920-eadfd39051ca
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-mysql-server v0.20.1-0.20251230191454-7ddc25f8ea97
github.com/dolthub/go-mysql-server v0.20.1-0.20251230225138-0bf05c4e54b0
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63
github.com/edsrzf/mmap-go v1.2.0
github.com/esote/minmaxheap v1.0.0
+2 -2
View File
@@ -195,8 +195,8 @@ github.com/dolthub/fslock v0.0.0-20251215194149-ef20baba2318 h1:n+vdH5G5Db+1qnDC
github.com/dolthub/fslock v0.0.0-20251215194149-ef20baba2318/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
github.com/dolthub/go-icu-regex v0.0.0-20250916051405-78a38d478790 h1:zxMsH7RLiG+dlZ/y0LgJHTV26XoiSJcuWq+em6t6VVc=
github.com/dolthub/go-icu-regex v0.0.0-20250916051405-78a38d478790/go.mod h1:F3cnm+vMRK1HaU6+rNqQrOCyR03HHhR1GWG2gnPOqaE=
github.com/dolthub/go-mysql-server v0.20.1-0.20251230191454-7ddc25f8ea97 h1:zqAXVz/c61Mla+y6TIqNwY8x8FjNCNVTntN0UXX0RM4=
github.com/dolthub/go-mysql-server v0.20.1-0.20251230191454-7ddc25f8ea97/go.mod h1:NjewWKoa5bVSLdKwL7fg7eAfrcIxDybWUKoWEHWRTw4=
github.com/dolthub/go-mysql-server v0.20.1-0.20251230225138-0bf05c4e54b0 h1:/lX2PaxPg13EudyvAM9NNz9NGJXky2C+fPWYWuQ3g5E=
github.com/dolthub/go-mysql-server v0.20.1-0.20251230225138-0bf05c4e54b0/go.mod h1:NjewWKoa5bVSLdKwL7fg7eAfrcIxDybWUKoWEHWRTw4=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
@@ -253,12 +253,15 @@ func newLookupKeyMapping(
litTb := val.NewTupleBuilder(litDesc, ns)
for i, j := range litMappings {
colTyp := typs[j]
val, _, err := convertLiteralKeyValue(ctx, colTyp, keyExprs[j].(*expression.Literal))
value, inRange, err := convertLiteralKeyValue(ctx, colTyp, keyExprs[j].(*expression.Literal))
if err != nil && !sql.ErrTruncatedIncorrect.Is(err) {
return nil, err
}
if inRange != sql.InRange {
return nil, nil
}
if err := tree.PutField(ctx, ns, litTb, i, val); err != nil {
if err := tree.PutField(ctx, ns, litTb, i, value); err != nil {
return nil, err
}
}
@@ -289,18 +292,17 @@ func newLookupKeyMapping(
// convertLiteralKeyValue converts a literal expression value to the appropriate type for the reference column
// in a key lookup
func convertLiteralKeyValue(ctx *sql.Context, colTyp sql.ColumnExpressionType, val *expression.Literal) (any, sql.ConvertInRange, error) {
srcType := val.Type()
func convertLiteralKeyValue(ctx *sql.Context, colTyp sql.ColumnExpressionType, literal *expression.Literal) (any, sql.ConvertInRange, error) {
srcType := literal.Type()
destType := colTyp.Type
// For extended types, use the rich type conversion methods
if srcEt, ok := srcType.(sql.ExtendedType); ok {
if destEt, ok := destType.(sql.ExtendedType); ok {
return destEt.ConvertToType(ctx, srcEt, val.Value())
return destEt.ConvertToType(ctx, srcEt, literal.Value())
}
}
return destType.Convert(ctx, val.Value())
return destType.Convert(ctx, literal.Value())
}
// valid returns whether the source and destination key types