mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-31 03:18:43 -06:00
Add context parameter to TupleTypeHandler type.
This commit is contained in:
@@ -462,23 +462,23 @@ func (si schemaImpl) AddColumn(newCol Column, order *ColumnOrder) (Schema, error
|
||||
}
|
||||
|
||||
// GetMapDescriptors implements the Schema interface.
|
||||
func (si *schemaImpl) GetMapDescriptors() (keyDesc, valueDesc val.TupleDesc) {
|
||||
keyDesc = si.GetKeyDescriptor()
|
||||
valueDesc = si.GetValueDescriptor()
|
||||
func (si *schemaImpl) GetMapDescriptors(vs val.ValueStore) (keyDesc, valueDesc val.TupleDesc) {
|
||||
keyDesc = si.GetKeyDescriptor(vs)
|
||||
valueDesc = si.GetValueDescriptor(vs)
|
||||
return
|
||||
}
|
||||
|
||||
// GetKeyDescriptor implements the Schema interface.
|
||||
func (si *schemaImpl) GetKeyDescriptor() val.TupleDesc {
|
||||
return si.getKeyColumnsDescriptor(true)
|
||||
func (si *schemaImpl) GetKeyDescriptor(vs val.ValueStore) val.TupleDesc {
|
||||
return si.getKeyColumnsDescriptor(vs, true)
|
||||
}
|
||||
|
||||
// GetKeyDescriptorWithNoConversion implements the Schema interface.
|
||||
func (si *schemaImpl) GetKeyDescriptorWithNoConversion() val.TupleDesc {
|
||||
return si.getKeyColumnsDescriptor(false)
|
||||
func (si *schemaImpl) GetKeyDescriptorWithNoConversion(vs val.ValueStore) val.TupleDesc {
|
||||
return si.getKeyColumnsDescriptor(vs, false)
|
||||
}
|
||||
|
||||
func (si *schemaImpl) getKeyColumnsDescriptor(convertAddressColumns bool) val.TupleDesc {
|
||||
func (si *schemaImpl) getKeyColumnsDescriptor(vs val.ValueStore, convertAddressColumns bool) val.TupleDesc {
|
||||
if IsKeyless(si) {
|
||||
return val.KeylessTupleDesc
|
||||
}
|
||||
@@ -496,15 +496,22 @@ func (si *schemaImpl) getKeyColumnsDescriptor(convertAddressColumns bool) val.Tu
|
||||
sqlType := col.TypeInfo.ToSqlType()
|
||||
queryType := sqlType.Type()
|
||||
var t val.Type
|
||||
var handler val.TupleTypeHandler
|
||||
|
||||
_, contentHashedField := contentHashedFields[tag]
|
||||
extendedType, isExtendedType := sqlType.(gmstypes.ExtendedType)
|
||||
|
||||
if isExtendedType {
|
||||
encoding := EncodingFromSqlType(sqlType)
|
||||
t = val.Type{
|
||||
Enc: val.Encoding(EncodingFromSqlType(sqlType)),
|
||||
Enc: val.Encoding(encoding),
|
||||
Nullable: columnMissingNotNullConstraint(col),
|
||||
}
|
||||
if encoding == serial.EncodingExtended {
|
||||
handler = extendedType
|
||||
} else {
|
||||
handler = val.NewExtendedAddressTypeHandler(vs, extendedType)
|
||||
}
|
||||
} else {
|
||||
if convertAddressColumns && !contentHashedField && queryType == query.Type_BLOB {
|
||||
t = val.Type{
|
||||
@@ -538,7 +545,7 @@ func (si *schemaImpl) getKeyColumnsDescriptor(convertAddressColumns bool) val.Tu
|
||||
collations = append(collations, sql.Collation_Unspecified)
|
||||
}
|
||||
|
||||
handlers = append(handlers, extendedType)
|
||||
handlers = append(handlers, handler)
|
||||
|
||||
return
|
||||
})
|
||||
@@ -555,7 +562,7 @@ func (si *schemaImpl) getKeyColumnsDescriptor(convertAddressColumns bool) val.Tu
|
||||
}
|
||||
|
||||
// GetValueDescriptor implements the Schema interface.
|
||||
func (si *schemaImpl) GetValueDescriptor() val.TupleDesc {
|
||||
func (si *schemaImpl) GetValueDescriptor(vs val.ValueStore) val.TupleDesc {
|
||||
var tt []val.Type
|
||||
var handlers []val.TupleTypeHandler
|
||||
var collations []sql.CollationID
|
||||
@@ -572,9 +579,10 @@ func (si *schemaImpl) GetValueDescriptor() val.TupleDesc {
|
||||
}
|
||||
|
||||
sqlType := col.TypeInfo.ToSqlType()
|
||||
encoding := EncodingFromSqlType(sqlType)
|
||||
queryType := sqlType.Type()
|
||||
tt = append(tt, val.Type{
|
||||
Enc: val.Encoding(EncodingFromSqlType(sqlType)),
|
||||
Enc: val.Encoding(encoding),
|
||||
Nullable: col.IsNullable(),
|
||||
})
|
||||
if queryType == query.Type_CHAR || queryType == query.Type_VARCHAR {
|
||||
@@ -585,6 +593,9 @@ func (si *schemaImpl) GetValueDescriptor() val.TupleDesc {
|
||||
}
|
||||
|
||||
if extendedType, ok := sqlType.(gmstypes.ExtendedType); ok {
|
||||
if encoding == serial.EncodingExtendedAddr {
|
||||
handlers = append(handlers, val.NewExtendedAddressTypeHandler(vs, extendedType))
|
||||
}
|
||||
handlers = append(handlers, extendedType)
|
||||
} else {
|
||||
handlers = append(handlers, nil)
|
||||
|
||||
@@ -144,17 +144,13 @@ func GetField(ctx context.Context, td val.TupleDesc, i int, tup val.Tuple, ns No
|
||||
var b []byte
|
||||
b, ok = td.GetExtended(i, tup)
|
||||
if ok {
|
||||
v, err = td.Handlers[i].DeserializeValue(b)
|
||||
v, err = td.Handlers[i].DeserializeValue(ctx, b)
|
||||
}
|
||||
case val.ExtendedAddrEnc:
|
||||
var h hash.Hash
|
||||
h, ok = td.GetExtendedAddr(i, tup)
|
||||
if ok {
|
||||
var b []byte
|
||||
b, err = NewByteArray(h, ns).ToBytes(ctx)
|
||||
if err == nil {
|
||||
v, err = td.Handlers[i].DeserializeValue(b)
|
||||
}
|
||||
v, err = td.Handlers[i].DeserializeValue(ctx, h[:])
|
||||
}
|
||||
default:
|
||||
panic("unknown val.encoding")
|
||||
@@ -279,7 +275,7 @@ func PutField(ctx context.Context, ns NodeStore, tb *val.TupleBuilder, i int, v
|
||||
}
|
||||
tb.PutCell(i, ZCell(v.(types.GeometryValue)))
|
||||
case val.ExtendedEnc:
|
||||
b, err := tb.Desc.Handlers[i].SerializeValue(v)
|
||||
b, err := tb.Desc.Handlers[i].SerializeValue(ctx, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -288,15 +284,11 @@ func PutField(ctx context.Context, ns NodeStore, tb *val.TupleBuilder, i int, v
|
||||
}
|
||||
tb.PutExtended(i, b)
|
||||
case val.ExtendedAddrEnc:
|
||||
b, err := tb.Desc.Handlers[i].SerializeValue(v)
|
||||
b, err := tb.Desc.Handlers[i].SerializeValue(ctx, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, h, err := SerializeBytesToAddr(ctx, ns, bytes.NewReader(b), len(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tb.PutExtendedAddr(i, h)
|
||||
tb.PutExtendedAddr(i, b)
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown encoding %v %v", enc, v))
|
||||
}
|
||||
|
||||
@@ -53,11 +53,11 @@ type TupleDesc struct {
|
||||
type TupleTypeHandler interface {
|
||||
// SerializedCompare compares two byte slices that each represent a serialized value, without first deserializing
|
||||
// the value.
|
||||
SerializedCompare(v1 []byte, v2 []byte) (int, error)
|
||||
SerializedCompare(ctx context.Context, v1 []byte, v2 []byte) (int, error)
|
||||
// SerializeValue converts the given value into a binary representation.
|
||||
SerializeValue(val any) ([]byte, error)
|
||||
SerializeValue(ctx context.Context, val any) ([]byte, error)
|
||||
// DeserializeValue converts a binary representation of a value into its canonical type.
|
||||
DeserializeValue(val []byte) (any, error)
|
||||
DeserializeValue(ctx context.Context, val []byte) (any, error)
|
||||
// FormatValue returns a string version of the value. Primarily intended for display.
|
||||
FormatValue(val any) (string, error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user