fix translation bugs for YEAR, TIME, and TEXT

This commit is contained in:
Andy Arthur
2022-07-27 21:27:27 -07:00
parent a6dd96de64
commit 0a5b03c365
2 changed files with 25 additions and 18 deletions

View File

@@ -18,6 +18,7 @@ import (
"bytes"
"context"
"fmt"
"strings"
"time"
"github.com/shopspring/decimal"
@@ -105,7 +106,7 @@ func translateNomsField(ctx context.Context, ns tree.NodeStore, value types.Valu
b.PutBool(idx, bool(value.(types.Bool)))
case types.StringKind:
b.PutString(idx, string(value.(types.String)))
return translateStringField(ctx, ns, value.(types.String), idx, b)
case types.UUIDKind:
uuid := value.(types.UUID)
@@ -169,9 +170,9 @@ func translateIntField(value types.Int, idx int, b *val.TupleBuilder) {
case val.Int64Enc:
b.PutInt64(idx, int64(value))
case val.YearEnc:
b.PutInt16(idx, int16(value))
b.PutYear(idx, int16(value))
case val.TimeEnc:
b.PutInt64(idx, int64(value))
b.PutSqlTime(idx, int64(value))
default:
panic(fmt.Sprintf("unexpected encoding for int (%d)", typ.Enc))
}
@@ -189,6 +190,27 @@ func translateFloatField(value types.Float, idx int, b *val.TupleBuilder) {
}
}
func translateStringField(ctx context.Context, ns tree.NodeStore, value types.String, idx int, b *val.TupleBuilder) error {
typ := b.Desc.Types[idx]
switch typ.Enc {
case val.StringEnc:
b.PutString(idx, string(value))
case val.StringAddrEnc:
// note: previously, TEXT fields were serialized as types.String
rd := strings.NewReader(string(value))
t, err := tree.NewImmutableTreeFromReader(ctx, rd, ns, tree.DefaultFixedChunkLength)
if err != nil {
return err
}
b.PutStringAddr(idx, t.Addr)
default:
panic(fmt.Sprintf("unexpected encoding for string (%d)", typ.Enc))
}
return nil
}
func translateTimestampField(value types.Timestamp, idx int, b *val.TupleBuilder) {
typ := b.Desc.Types[idx]
switch typ.Enc {

View File

@@ -203,21 +203,6 @@ func assertNomsKind(kind types.NomsKind, candidates ...types.NomsKind) error {
strings.Join(cs, ", "), types.KindToString[kind])
}
func hashRow(sctx *sql.Context, r sql.Row) (uint64, error) {
for i := range r {
// normalize fields
switch x := r[i].(type) {
case sql.JSONValue:
s, err := x.ToString(sctx)
if err != nil {
return 0, err
}
r[i] = s
}
}
return sql.HashOf(r)
}
func assertTrue(b bool) {
if !b {
panic("expected true")