Renames and bug fixes

This commit is contained in:
Zach Musgrave
2023-01-23 18:38:54 -08:00
parent d29fbe8da6
commit 4a69f1a0fb
5 changed files with 49 additions and 37 deletions

View File

@@ -19,18 +19,18 @@ import (
"fmt"
"github.com/dolthub/go-mysql-server/sql"
types2 "github.com/dolthub/go-mysql-server/sql/types"
sqltypes "github.com/dolthub/go-mysql-server/sql/types"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/json"
"github.com/dolthub/dolt/go/store/types"
)
type jsonType struct {
jsonType sql.JsonType
jsonType sqltypes.JsonType
}
var _ TypeInfo = (*jsonType)(nil)
var JSONType = &jsonType{types2.JSON}
var JSONType = &jsonType{sqltypes.JsonType{}}
// ConvertNomsValueToValue implements TypeInfo interface.
func (ti *jsonType) ConvertNomsValueToValue(v types.Value) (interface{}, error) {
@@ -72,7 +72,7 @@ func (ti *jsonType) ConvertValueToNomsValue(ctx context.Context, vrw types.Value
return nil, err
}
jsVal, ok := jsDoc.(types2.JSONValue)
jsVal, ok := jsDoc.(sqltypes.JSONValue)
if !ok {
return nil, fmt.Errorf(`"%v" cannot convert value "%v" of type "%T" as it is invalid`, ti.String(), v, v)
}
@@ -138,7 +138,7 @@ func (ti *jsonType) NomsKind() types.NomsKind {
// Promote implements TypeInfo interface.
func (ti *jsonType) Promote() TypeInfo {
return &jsonType{ti.jsonType.Promote().(sql.JsonType)}
return &jsonType{ti.jsonType.Promote().(sqltypes.JsonType)}
}
// String implements TypeInfo interface.

View File

@@ -20,7 +20,7 @@ import (
"math"
"github.com/dolthub/go-mysql-server/sql"
types2 "github.com/dolthub/go-mysql-server/sql/types"
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
"github.com/dolthub/vitess/go/sqltypes"
"github.com/dolthub/dolt/go/store/types"
@@ -174,22 +174,22 @@ func FromSqlType(sqlType sql.Type) (TypeInfo, error) {
return YearType, nil
case sqltypes.Geometry:
switch sqlType.String() {
case types2.PointType{}.String():
return &pointType{sqlType.(types2.PointType)}, nil
case types2.LineStringType{}.String():
return &linestringType{sqlType.(types2.LineStringType)}, nil
case types2.PolygonType{}.String():
return &polygonType{sqlType.(types2.PolygonType)}, nil
case types2.MultiPointType{}.String():
case gmstypes.PointType{}.String():
return &pointType{sqlType.(gmstypes.PointType)}, nil
case gmstypes.LineStringType{}.String():
return &linestringType{sqlType.(gmstypes.LineStringType)}, nil
case gmstypes.PolygonType{}.String():
return &polygonType{sqlType.(gmstypes.PolygonType)}, nil
case gmstypes.MultiPointType{}.String():
return &multipointType{}, nil
case types2.MultiLineStringType{}.String():
case gmstypes.MultiLineStringType{}.String():
return &multilinestringType{}, nil
case types2.MultiPolygonType{}.String():
case gmstypes.MultiPolygonType{}.String():
return &multipolygonType{}, nil
case types2.GeomCollType{}.String():
case gmstypes.GeomCollType{}.String():
return &geomcollType{}, nil
case types2.GeometryType{}.String():
return &geometryType{sqlGeometryType: sqlType.(types2.GeometryType)}, nil
case gmstypes.GeometryType{}.String():
return &geometryType{sqlGeometryType: sqlType.(gmstypes.GeometryType)}, nil
default:
return nil, fmt.Errorf(`expected "PointTypeIdentifier" from SQL basetype "Geometry"`)
}
@@ -236,13 +236,13 @@ func FromSqlType(sqlType sql.Type) (TypeInfo, error) {
}
return &inlineBlobType{stringType}, nil
case sqltypes.Bit:
bitSQLType, ok := sqlType.(types2.BitType)
bitSQLType, ok := sqlType.(gmstypes.BitType)
if !ok {
return nil, fmt.Errorf(`expected "BitTypeIdentifier" from SQL basetype "Bit"`)
}
return &bitType{bitSQLType}, nil
case sqltypes.TypeJSON:
js, ok := sqlType.(sql.JsonType)
js, ok := sqlType.(gmstypes.JsonType)
if !ok {
return nil, fmt.Errorf(`expected "JsonType" from SQL basetype "TypeJSON"`)
}
@@ -328,13 +328,13 @@ func FromTypeParams(id Identifier, params map[string]string) (TypeInfo, error) {
func FromKind(kind types.NomsKind) TypeInfo {
switch kind {
case types.BlobKind:
return &varBinaryType{types2.LongBlob}
return &varBinaryType{gmstypes.LongBlob}
case types.BoolKind:
return BoolType
case types.FloatKind:
return Float64Type
case types.InlineBlobKind:
return &inlineBlobType{types2.MustCreateBinary(sqltypes.VarBinary, math.MaxUint16)}
return &inlineBlobType{gmstypes.MustCreateBinary(sqltypes.VarBinary, math.MaxUint16)}
case types.IntKind:
return Int64Type
case types.JSONKind:
@@ -360,7 +360,7 @@ func FromKind(kind types.NomsKind) TypeInfo {
case types.UUIDKind:
return UuidType
case types.DecimalKind:
return &decimalType{types2.MustCreateDecimalType(65, 30)}
return &decimalType{gmstypes.MustCreateDecimalType(65, 30)}
default:
panic(fmt.Errorf(`no default type info for NomsKind "%v"`, kind.String()))
}

View File

@@ -29,7 +29,7 @@ import (
"sync"
"github.com/dolthub/go-mysql-server/sql"
types2 "github.com/dolthub/go-mysql-server/sql/types"
sqltypes "github.com/dolthub/go-mysql-server/sql/types"
"github.com/dolthub/dolt/go/libraries/doltcore/branch_control"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
@@ -410,7 +410,7 @@ func (t *DoltTable) DataLength(ctx *sql.Context) (uint64, error) {
numBytesPerRow += 8
case sql.StringType:
numBytesPerRow += uint64(n.MaxByteLength())
case types2.BitType:
case sqltypes.BitType:
numBytesPerRow += 1
case sql.DatetimeType:
numBytesPerRow += 8
@@ -418,11 +418,11 @@ func (t *DoltTable) DataLength(ctx *sql.Context) (uint64, error) {
numBytesPerRow += uint64(n.MaximumScale())
case sql.EnumType:
numBytesPerRow += 2
case sql.JsonType:
case sqltypes.JsonType:
numBytesPerRow += 20
case sql.NullType:
numBytesPerRow += 1
case types2.TimeType:
case sqltypes.TimeType:
numBytesPerRow += 16
case sql.YearType:
numBytesPerRow += 8
@@ -1311,7 +1311,7 @@ func (t *AlterableDoltTable) RewriteInserter(
if strings.ToLower(oldColumn.Name) == strings.ToLower(colName) {
colNames = append(colNames, newColumn.Name)
if len(prefixLengths) > 0 {
if !types2.IsText(newColumn.Type) {
if !sqltypes.IsText(newColumn.Type) {
// drop prefix lengths if column is not a string type
prefixLengths[i] = 0
} else if uint32(prefixLengths[i]) > newColumn.Type.MaxTextResponseByteLength() {
@@ -1499,7 +1499,7 @@ func validateSchemaChange(
) error {
for _, idxCol := range idxCols {
col := newSchema.Schema[newSchema.Schema.IndexOfColName(idxCol.Name)]
if col.PrimaryKey && idxCol.Length > 0 && types2.IsText(col.Type) {
if col.PrimaryKey && idxCol.Length > 0 && sqltypes.IsText(col.Type) {
return sql.ErrUnsupportedIndexPrefix.New(col.Name)
}
}

View File

@@ -193,7 +193,18 @@ func (j *RowWriter) jsonDataForSqlSchema(row sql.Row) ([]byte, error) {
}
switch col.Type.(type) {
case sql.JsonType:
case sql.DatetimeType,
sql.DecimalType,
sql.EnumType,
sql.StringType,
sql.SetType,
types.TupleType:
sqlVal, err := col.Type.SQL(sqlContext, nil, val)
if err != nil {
return nil, err
}
val = sqlVal.ToString()
case types.JsonType:
sqlVal, err := col.Type.SQL(sqlContext, nil, val)
if err != nil {
return nil, err
@@ -206,12 +217,6 @@ func (j *RowWriter) jsonDataForSqlSchema(row sql.Row) ([]byte, error) {
if err != nil {
return nil, err
}
default:
sqlVal, err := col.Type.SQL(sqlContext, nil, val)
if err != nil {
return nil, err
}
val = sqlVal.ToString()
}
colValMap[col.Name] = val

View File

@@ -1012,10 +1012,17 @@ SQL
[[ "$output" =~ '5,5.5,5,' ]] || false
[ "${#lines[@]}" -eq 6 ]
run dolt sql -r csv -q "select @@character_set_client"
[ $status -eq 0 ]
[[ "$output" =~ "utf8mb4" ]] || false
run dolt sql -r json -q "select * from test order by a"
[ $status -eq 0 ]
echo $output
[ "$output" == '{"rows": [{"a":1,"b":1.5,"c":"1","d":"2020-01-01 00:00:00"},{"a":2,"b":2.5,"c":"2","d":"2020-02-02 00:00:00"},{"a":3,"c":"3","d":"2020-03-03 00:00:00"},{"a":4,"b":4.5,"d":"2020-04-04 00:00:00"},{"a":5,"b":5.5,"c":"5"}]}' ]
run dolt sql -r json -q "select @@character_set_client"
[ $status -eq 0 ]
[[ "$output" =~ "utf8mb4" ]] || false
}
@test "sql: output for escaped longtext exports properly" {