mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-16 20:00:53 -05:00
lots of dead code removed
This commit is contained in:
@@ -60,11 +60,11 @@ type FKViolationReceiver interface {
|
||||
// RegisterForeignKeyViolations emits constraint violations that have been created as a
|
||||
// result of the diff between |baseRoot| and |newRoot|. It sends violations to |receiver|.
|
||||
func RegisterForeignKeyViolations(
|
||||
ctx *sql.Context,
|
||||
tableResolver doltdb.TableResolver,
|
||||
newRoot, baseRoot doltdb.RootValue,
|
||||
tables *doltdb.TableNameSet,
|
||||
receiver FKViolationReceiver,
|
||||
ctx *sql.Context,
|
||||
tableResolver doltdb.TableResolver,
|
||||
newRoot, baseRoot doltdb.RootValue,
|
||||
tables *doltdb.TableNameSet,
|
||||
receiver FKViolationReceiver,
|
||||
) error {
|
||||
fkColl, err := newRoot.GetForeignKeyCollection(ctx)
|
||||
if err != nil {
|
||||
@@ -317,11 +317,11 @@ var _ FKViolationReceiver = (*foreignKeyViolationWriter)(nil)
|
||||
|
||||
// parentFkConstraintViolations processes foreign key constraint violations for the parent in a foreign key.
|
||||
func parentFkConstraintViolations(
|
||||
ctx context.Context,
|
||||
foreignKey doltdb.ForeignKey,
|
||||
preParent, postParent, postChild *constraintViolationsLoadedTable,
|
||||
preParentRowData durable.Index,
|
||||
receiver FKViolationReceiver,
|
||||
ctx context.Context,
|
||||
foreignKey doltdb.ForeignKey,
|
||||
preParent, postParent, postChild *constraintViolationsLoadedTable,
|
||||
preParentRowData durable.Index,
|
||||
receiver FKViolationReceiver,
|
||||
) error {
|
||||
if preParentRowData.Format() != types.Format_DOLT {
|
||||
panic("unsupported format: " + preParentRowData.Format().VersionString())
|
||||
@@ -357,12 +357,12 @@ func parentFkConstraintViolations(
|
||||
// childFkConstraintViolations handles processing the reference options on a child, or creating a violation if
|
||||
// necessary.
|
||||
func childFkConstraintViolations(
|
||||
ctx context.Context,
|
||||
vr types.ValueReader,
|
||||
foreignKey doltdb.ForeignKey,
|
||||
postParent, postChild, preChild *constraintViolationsLoadedTable,
|
||||
preChildRowData durable.Index,
|
||||
receiver FKViolationReceiver,
|
||||
ctx context.Context,
|
||||
vr types.ValueReader,
|
||||
foreignKey doltdb.ForeignKey,
|
||||
postParent, postChild, preChild *constraintViolationsLoadedTable,
|
||||
preChildRowData durable.Index,
|
||||
receiver FKViolationReceiver,
|
||||
) error {
|
||||
if preChildRowData.Format() != types.Format_DOLT {
|
||||
panic("unsupported format: " + preChildRowData.Format().VersionString())
|
||||
@@ -399,11 +399,11 @@ func childFkConstraintViolations(
|
||||
// newConstraintViolationsLoadedTable returns a *constraintViolationsLoadedTable. Returns false if the table was loaded
|
||||
// but the index could not be found. If the table could not be found, then an error is returned.
|
||||
func newConstraintViolationsLoadedTable(
|
||||
ctx *sql.Context,
|
||||
tableResolver doltdb.TableResolver,
|
||||
tblName doltdb.TableName,
|
||||
idxName string,
|
||||
root doltdb.RootValue,
|
||||
ctx *sql.Context,
|
||||
tableResolver doltdb.TableResolver,
|
||||
tblName doltdb.TableName,
|
||||
idxName string,
|
||||
root doltdb.RootValue,
|
||||
) (*constraintViolationsLoadedTable, bool, error) {
|
||||
trueTblName, tbl, ok, err := tableResolver.ResolveTableInsensitive(ctx, root, tblName)
|
||||
if err != nil {
|
||||
|
||||
@@ -22,11 +22,9 @@ import (
|
||||
"unicode/utf8"
|
||||
"unsafe"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
"github.com/dolthub/vitess/go/sqltypes"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -45,38 +43,10 @@ type blobStringType struct {
|
||||
var _ TypeInfo = (*blobStringType)(nil)
|
||||
|
||||
var (
|
||||
TinyTextType TypeInfo = &blobStringType{sqlStringType: gmstypes.TinyText}
|
||||
TextType TypeInfo = &blobStringType{sqlStringType: gmstypes.Text}
|
||||
MediumTextType TypeInfo = &blobStringType{sqlStringType: gmstypes.MediumText}
|
||||
LongTextType TypeInfo = &blobStringType{sqlStringType: gmstypes.LongText}
|
||||
TextType TypeInfo = &blobStringType{sqlStringType: gmstypes.Text}
|
||||
LongTextType TypeInfo = &blobStringType{sqlStringType: gmstypes.LongText}
|
||||
)
|
||||
|
||||
func CreateBlobStringTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
collationStr, ok := params[blobStringTypeParam_Collate]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`create blobstring type info is missing param "%v"`, blobStringTypeParam_Collate)
|
||||
}
|
||||
collation, err := sql.ParseCollation("", collationStr, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
maxLengthStr, ok := params[blobStringTypeParam_Length]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`create blobstring type info is missing param "%v"`, blobStringTypeParam_Length)
|
||||
}
|
||||
length, err := strconv.ParseInt(maxLengthStr, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sqlType, err := gmstypes.CreateString(sqltypes.Text, length, collation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &blobStringType{sqlType}, nil
|
||||
}
|
||||
|
||||
// ConvertNomsValueToValue implements TypeInfo interface.
|
||||
func (ti *blobStringType) ConvertNomsValueToValue(v types.Value) (interface{}, error) {
|
||||
if val, ok := v.(types.Blob); ok {
|
||||
|
||||
@@ -116,29 +116,6 @@ func generateSetType(t *testing.T, numOfElements int) *setType {
|
||||
return &setType{gmstypes.MustCreateSetType(vals, sql.Collation_Default)}
|
||||
}
|
||||
|
||||
func generateInlineBlobTypes(t *testing.T, numOfTypes uint16) []TypeInfo {
|
||||
var res []TypeInfo
|
||||
loop(t, 1, 500, numOfTypes, func(i int64) {
|
||||
pad := false
|
||||
if i%2 == 0 {
|
||||
pad = true
|
||||
}
|
||||
res = append(res, generateInlineBlobType(t, i, pad))
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
func generateInlineBlobType(t *testing.T, length int64, pad bool) *inlineBlobType {
|
||||
require.True(t, length > 0)
|
||||
if pad {
|
||||
t, err := gmstypes.CreateBinary(sqltypes.Binary, length)
|
||||
if err == nil {
|
||||
return &inlineBlobType{t}
|
||||
}
|
||||
}
|
||||
return &inlineBlobType{gmstypes.MustCreateBinary(sqltypes.VarBinary, length)}
|
||||
}
|
||||
|
||||
func generateVarStringTypes(t *testing.T, numOfTypes uint16) []TypeInfo {
|
||||
var res []TypeInfo
|
||||
loop(t, 1, 500, numOfTypes, func(i int64) {
|
||||
|
||||
@@ -17,7 +17,6 @@ package typeinfo
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
@@ -50,39 +49,6 @@ func CreateDatetimeTypeFromSqlType(typ sql.DatetimeType) *datetimeType {
|
||||
return &datetimeType{typ}
|
||||
}
|
||||
|
||||
func CreateDatetimeTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
if sqlType, ok := params[datetimeTypeParam_SQL]; ok {
|
||||
precision := 6
|
||||
if precisionParam, ok := params[datetimeTypeParam_Precision]; ok {
|
||||
var err error
|
||||
precision, err = strconv.Atoi(precisionParam)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
switch sqlType {
|
||||
case datetimeTypeParam_SQL_Date:
|
||||
return DateType, nil
|
||||
case datetimeTypeParam_SQL_Datetime:
|
||||
gmsType, err := gmstypes.CreateDatetimeType(sqltypes.Datetime, precision)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return CreateDatetimeTypeFromSqlType(gmsType), nil
|
||||
case datetimeTypeParam_SQL_Timestamp:
|
||||
gmsType, err := gmstypes.CreateDatetimeType(sqltypes.Timestamp, precision)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return CreateDatetimeTypeFromSqlType(gmsType), nil
|
||||
default:
|
||||
return nil, fmt.Errorf(`create datetime type info has invalid param "%v"`, sqlType)
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf(`create datetime type info is missing param "%v"`, datetimeTypeParam_SQL)
|
||||
}
|
||||
}
|
||||
|
||||
// ConvertNomsValueToValue implements TypeInfo interface.
|
||||
func (ti *datetimeType) ConvertNomsValueToValue(v types.Value) (interface{}, error) {
|
||||
if val, ok := v.(types.Timestamp); ok {
|
||||
@@ -121,7 +87,7 @@ func (ti *datetimeType) ReadFrom(_ *types.NomsBinFormat, reader types.CodecReade
|
||||
|
||||
// ConvertValueToNomsValue implements TypeInfo interface.
|
||||
func (ti *datetimeType) ConvertValueToNomsValue(ctx context.Context, vrw types.ValueReadWriter, v interface{}) (types.Value, error) {
|
||||
//TODO: handle the zero value as a special case that is valid for all ranges
|
||||
// TODO: handle the zero value as a special case that is valid for all ranges
|
||||
if v == nil {
|
||||
return types.NullValue, nil
|
||||
}
|
||||
|
||||
@@ -16,14 +16,11 @@ package typeinfo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -39,34 +36,6 @@ type enumType struct {
|
||||
|
||||
var _ TypeInfo = (*enumType)(nil)
|
||||
|
||||
func CreateEnumTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var collation sql.CollationID
|
||||
var err error
|
||||
if collationStr, ok := params[enumTypeParam_Collation]; ok {
|
||||
collation, err = sql.ParseCollation("", collationStr, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf(`create enum type info is missing param "%v"`, enumTypeParam_Collation)
|
||||
}
|
||||
var values []string
|
||||
if valuesStr, ok := params[enumTypeParam_Values]; ok {
|
||||
dec := gob.NewDecoder(strings.NewReader(valuesStr))
|
||||
err = dec.Decode(&values)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf(`create enum type info is missing param "%v"`, enumTypeParam_Values)
|
||||
}
|
||||
sqlEnumType, err := gmstypes.CreateEnumType(values, collation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return CreateEnumTypeFromSqlEnumType(sqlEnumType), nil
|
||||
}
|
||||
|
||||
func CreateEnumTypeFromSqlEnumType(sqlEnumType sql.EnumType) TypeInfo {
|
||||
return &enumType{sqlEnumType}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,8 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
const (
|
||||
extendedTypeParams_string_encoded = "string_encoded"
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
)
|
||||
|
||||
// extendedType is a type that refers to an ExtendedType in GMS. These are only supported in the new format, and have many
|
||||
@@ -36,18 +30,6 @@ type extendedType struct {
|
||||
|
||||
var _ TypeInfo = (*extendedType)(nil)
|
||||
|
||||
// CreateExtendedTypeFromParams creates a TypeInfo from the given parameter map.
|
||||
func CreateExtendedTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
if encodedString, ok := params[extendedTypeParams_string_encoded]; ok {
|
||||
t, err := gmstypes.DeserializeTypeFromString(encodedString)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &extendedType{t}, nil
|
||||
}
|
||||
return nil, fmt.Errorf(`create extended type info is missing "%v" param`, extendedTypeParams_string_encoded)
|
||||
}
|
||||
|
||||
// CreateExtendedTypeFromSqlType creates a TypeInfo from the given extended type.
|
||||
func CreateExtendedTypeFromSqlType(typ sql.ExtendedType) TypeInfo {
|
||||
return &extendedType{typ}
|
||||
|
||||
@@ -30,12 +30,6 @@ import (
|
||||
|
||||
type FloatWidth int8
|
||||
|
||||
const (
|
||||
floatTypeParam_Width = "width"
|
||||
floatTypeParam_Width_32 = "32"
|
||||
floatTypeParam_Width_64 = "64"
|
||||
)
|
||||
|
||||
type floatType struct {
|
||||
sqlFloatType sql.NumberType
|
||||
}
|
||||
@@ -46,20 +40,6 @@ var (
|
||||
Float64Type = &floatType{gmstypes.Float64}
|
||||
)
|
||||
|
||||
func CreateFloatTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
if width, ok := params[floatTypeParam_Width]; ok {
|
||||
switch width {
|
||||
case floatTypeParam_Width_32:
|
||||
return Float32Type, nil
|
||||
case floatTypeParam_Width_64:
|
||||
return Float64Type, nil
|
||||
default:
|
||||
return nil, fmt.Errorf(`create float type info has "%v" param with value "%v"`, floatTypeParam_Width, width)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf(`create float type info is missing "%v" param`, floatTypeParam_Width)
|
||||
}
|
||||
|
||||
// ConvertNomsValueToValue implements TypeInfo interface.
|
||||
func (ti *floatType) ConvertNomsValueToValue(v types.Value) (interface{}, error) {
|
||||
if val, ok := v.(types.Float); ok {
|
||||
|
||||
@@ -17,7 +17,6 @@ package typeinfo
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
@@ -289,28 +288,6 @@ func geometryTypeConverter(ctx context.Context, src *geometryType, destTi TypeIn
|
||||
}
|
||||
}
|
||||
|
||||
func CreateGeometryTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var (
|
||||
err error
|
||||
sridVal uint64
|
||||
def bool
|
||||
)
|
||||
if s, ok := params["SRID"]; ok {
|
||||
sridVal, err = strconv.ParseUint(s, 10, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if d, ok := params["DefinedSRID"]; ok {
|
||||
def, err = strconv.ParseBool(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return CreateGeometryTypeFromSqlGeometryType(gmstypes.GeometryType{SRID: uint32(sridVal), DefinedSRID: def}), nil
|
||||
}
|
||||
|
||||
func CreateGeometryTypeFromSqlGeometryType(sqlGeometryType gmstypes.GeometryType) TypeInfo {
|
||||
return &geometryType{sqlGeometryType: sqlGeometryType}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package typeinfo
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
@@ -197,25 +196,3 @@ func geomcollTypeConverter(ctx context.Context, src *geomcollType, destTi TypeIn
|
||||
return nil, false, UnhandledTypeConversion.New(src.String(), destTi.String())
|
||||
}
|
||||
}
|
||||
|
||||
func CreateGeomCollTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var (
|
||||
err error
|
||||
sridVal uint64
|
||||
def bool
|
||||
)
|
||||
if s, ok := params["SRID"]; ok {
|
||||
sridVal, err = strconv.ParseUint(s, 10, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if d, ok := params["DefinedSRID"]; ok {
|
||||
def, err = strconv.ParseBool(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &geomcollType{sqlGeomCollType: gmstypes.GeomCollType{SRID: uint32(sridVal), DefinedSRID: def}}, nil
|
||||
}
|
||||
|
||||
@@ -22,19 +22,11 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
"github.com/dolthub/vitess/go/sqltypes"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
const (
|
||||
inlineBlobTypeParam_Length = "length"
|
||||
inlineBlobTypeParam_SQL = "sql"
|
||||
inlineBlobTypeParam_SQL_Binary = "bin"
|
||||
inlineBlobTypeParam_SQL_VarBinary = "varbin"
|
||||
)
|
||||
|
||||
// inlineBlobType handles BINARY and VARBINARY. BLOB types are handled by varBinaryType.
|
||||
type inlineBlobType struct {
|
||||
sqlBinaryType sql.StringType
|
||||
@@ -42,40 +34,6 @@ type inlineBlobType struct {
|
||||
|
||||
var _ TypeInfo = (*inlineBlobType)(nil)
|
||||
|
||||
var (
|
||||
VarbinaryDefaultType = &inlineBlobType{gmstypes.MustCreateBinary(sqltypes.VarBinary, 16383)}
|
||||
)
|
||||
|
||||
func CreateInlineBlobTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var length int64
|
||||
var err error
|
||||
if lengthStr, ok := params[inlineBlobTypeParam_Length]; ok {
|
||||
length, err = strconv.ParseInt(lengthStr, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf(`create inlineblob type info is missing param "%v"`, inlineBlobTypeParam_Length)
|
||||
}
|
||||
if sqlStr, ok := params[inlineBlobTypeParam_SQL]; ok {
|
||||
var sqlType sql.StringType
|
||||
switch sqlStr {
|
||||
case inlineBlobTypeParam_SQL_Binary:
|
||||
sqlType, err = gmstypes.CreateBinary(sqltypes.Binary, length)
|
||||
case inlineBlobTypeParam_SQL_VarBinary:
|
||||
sqlType, err = gmstypes.CreateBinary(sqltypes.VarBinary, length)
|
||||
default:
|
||||
return nil, fmt.Errorf(`create inlineblob type info has "%v" param with value "%v"`, inlineBlobTypeParam_SQL, sqlStr)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &inlineBlobType{sqlType}, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf(`create inlineblob type info is missing param "%v"`, inlineBlobTypeParam_SQL)
|
||||
}
|
||||
}
|
||||
|
||||
// ConvertNomsValueToValue implements TypeInfo interface.
|
||||
func (ti *inlineBlobType) ConvertNomsValueToValue(v types.Value) (interface{}, error) {
|
||||
if val, ok := v.(types.InlineBlob); ok {
|
||||
|
||||
@@ -26,15 +26,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
const (
|
||||
intTypeParams_Width = "width"
|
||||
intTypeParams_Width_8 = "8"
|
||||
intTypeParams_Width_16 = "16"
|
||||
intTypeParams_Width_24 = "24"
|
||||
intTypeParams_Width_32 = "32"
|
||||
intTypeParams_Width_64 = "64"
|
||||
)
|
||||
|
||||
type intType struct {
|
||||
sqlIntType sql.NumberType
|
||||
}
|
||||
@@ -48,26 +39,6 @@ var (
|
||||
Int64Type = &intType{gmstypes.Int64}
|
||||
)
|
||||
|
||||
func CreateIntTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
if width, ok := params[intTypeParams_Width]; ok {
|
||||
switch width {
|
||||
case intTypeParams_Width_8:
|
||||
return Int8Type, nil
|
||||
case intTypeParams_Width_16:
|
||||
return Int16Type, nil
|
||||
case intTypeParams_Width_24:
|
||||
return Int24Type, nil
|
||||
case intTypeParams_Width_32:
|
||||
return Int32Type, nil
|
||||
case intTypeParams_Width_64:
|
||||
return Int64Type, nil
|
||||
default:
|
||||
return nil, fmt.Errorf(`create int type info has "%v" param with value "%v"`, intTypeParams_Width, width)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf(`create int type info is missing "%v" param`, intTypeParams_Width)
|
||||
}
|
||||
|
||||
// ConvertNomsValueToValue implements TypeInfo interface.
|
||||
func (ti *intType) ConvertNomsValueToValue(v types.Value) (interface{}, error) {
|
||||
if val, ok := v.(types.Int); ok {
|
||||
|
||||
@@ -17,7 +17,6 @@ package typeinfo
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
@@ -197,24 +196,3 @@ func linestringTypeConverter(ctx context.Context, src *linestringType, destTi Ty
|
||||
return nil, false, UnhandledTypeConversion.New(src.String(), destTi.String())
|
||||
}
|
||||
}
|
||||
|
||||
func CreateLineStringTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var (
|
||||
err error
|
||||
sridVal uint64
|
||||
def bool
|
||||
)
|
||||
if s, ok := params["SRID"]; ok {
|
||||
sridVal, err = strconv.ParseUint(s, 10, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if d, ok := params["DefinedSRID"]; ok {
|
||||
def, err = strconv.ParseBool(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &linestringType{sqlLineStringType: gmstypes.LineStringType{SRID: uint32(sridVal), DefinedSRID: def}}, nil
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package typeinfo
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
@@ -197,25 +196,3 @@ func multilinestringTypeConverter(ctx context.Context, src *multilinestringType,
|
||||
return nil, false, UnhandledTypeConversion.New(src.String(), destTi.String())
|
||||
}
|
||||
}
|
||||
|
||||
func CreateMultiLineStringTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var (
|
||||
err error
|
||||
sridVal uint64
|
||||
def bool
|
||||
)
|
||||
if s, ok := params["SRID"]; ok {
|
||||
sridVal, err = strconv.ParseUint(s, 10, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if d, ok := params["DefinedSRID"]; ok {
|
||||
def, err = strconv.ParseBool(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &multilinestringType{sqlMultiLineStringType: gmstypes.MultiLineStringType{SRID: uint32(sridVal), DefinedSRID: def}}, nil
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package typeinfo
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
@@ -197,24 +196,3 @@ func multipointTypeConverter(ctx context.Context, src *multipointType, destTi Ty
|
||||
return nil, false, UnhandledTypeConversion.New(src.String(), destTi.String())
|
||||
}
|
||||
}
|
||||
|
||||
func CreateMultiPointTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var (
|
||||
err error
|
||||
sridVal uint64
|
||||
def bool
|
||||
)
|
||||
if s, ok := params["SRID"]; ok {
|
||||
sridVal, err = strconv.ParseUint(s, 10, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if d, ok := params["DefinedSRID"]; ok {
|
||||
def, err = strconv.ParseBool(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &multipointType{sqlMultiPointType: gmstypes.MultiPointType{SRID: uint32(sridVal), DefinedSRID: def}}, nil
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package typeinfo
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
@@ -197,25 +196,3 @@ func multipolygonTypeConverter(ctx context.Context, src *multipolygonType, destT
|
||||
return nil, false, UnhandledTypeConversion.New(src.String(), destTi.String())
|
||||
}
|
||||
}
|
||||
|
||||
func CreateMultiPolygonTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var (
|
||||
err error
|
||||
sridVal uint64
|
||||
def bool
|
||||
)
|
||||
if s, ok := params["SRID"]; ok {
|
||||
sridVal, err = strconv.ParseUint(s, 10, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if d, ok := params["DefinedSRID"]; ok {
|
||||
def, err = strconv.ParseBool(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &multipolygonType{sqlMultiPolygonType: gmstypes.MultiPolygonType{SRID: uint32(sridVal), DefinedSRID: def}}, nil
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package typeinfo
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
@@ -198,28 +197,6 @@ func pointTypeConverter(ctx context.Context, src *pointType, destTi TypeInfo) (t
|
||||
}
|
||||
}
|
||||
|
||||
func CreatePointTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var (
|
||||
err error
|
||||
sridVal uint64
|
||||
def bool
|
||||
)
|
||||
if s, ok := params["SRID"]; ok {
|
||||
sridVal, err = strconv.ParseUint(s, 10, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if d, ok := params["DefinedSRID"]; ok {
|
||||
def, err = strconv.ParseBool(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return CreatePointTypeFromSqlPointType(gmstypes.PointType{SRID: uint32(sridVal), DefinedSRID: def}), nil
|
||||
}
|
||||
|
||||
func CreatePointTypeFromSqlPointType(sqlPointType gmstypes.PointType) TypeInfo {
|
||||
return &pointType{sqlPointType: sqlPointType}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package typeinfo
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
@@ -197,25 +196,3 @@ func polygonTypeConverter(ctx context.Context, src *polygonType, destTi TypeInfo
|
||||
return nil, false, UnhandledTypeConversion.New(src.String(), destTi.String())
|
||||
}
|
||||
}
|
||||
|
||||
func CreatePolygonTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var (
|
||||
err error
|
||||
sridVal uint64
|
||||
def bool
|
||||
)
|
||||
if s, ok := params["SRID"]; ok {
|
||||
sridVal, err = strconv.ParseUint(s, 10, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if d, ok := params["DefinedSRID"]; ok {
|
||||
def, err = strconv.ParseBool(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &polygonType{sqlPolygonType: gmstypes.PolygonType{SRID: uint32(sridVal), DefinedSRID: def}}, nil
|
||||
}
|
||||
|
||||
@@ -16,19 +16,11 @@ package typeinfo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
const (
|
||||
setTypeParam_Collation = "collate"
|
||||
setTypeParam_Values = "vals"
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
)
|
||||
|
||||
// This is a dolt implementation of the MySQL type Set, thus most of the functionality
|
||||
@@ -39,33 +31,6 @@ type setType struct {
|
||||
|
||||
var _ TypeInfo = (*setType)(nil)
|
||||
|
||||
func CreateSetTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
collationStr, ok := params[setTypeParam_Collation]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`create set type info is missing param "%v"`, setTypeParam_Collation)
|
||||
}
|
||||
collation, err := sql.ParseCollation("", collationStr, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
valuesStr, ok := params[setTypeParam_Values]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`create set type info is missing param "%v"`, setTypeParam_Values)
|
||||
}
|
||||
var values []string
|
||||
dec := gob.NewDecoder(strings.NewReader(valuesStr))
|
||||
if err = dec.Decode(&values); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sqlSetType, err := gmstypes.CreateSetType(values, collation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return CreateSetTypeFromSqlSetType(sqlSetType), nil
|
||||
}
|
||||
|
||||
func CreateSetTypeFromSqlSetType(sqlSetType sql.SetType) TypeInfo {
|
||||
return &setType{sqlSetType}
|
||||
}
|
||||
|
||||
@@ -26,15 +26,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
const (
|
||||
uintTypeParam_Width = "width"
|
||||
uintTypeParam_Width_8 = "8"
|
||||
uintTypeParam_Width_16 = "16"
|
||||
uintTypeParam_Width_24 = "24"
|
||||
uintTypeParam_Width_32 = "32"
|
||||
uintTypeParam_Width_64 = "64"
|
||||
)
|
||||
|
||||
type uintType struct {
|
||||
sqlUintType sql.NumberType
|
||||
}
|
||||
@@ -48,26 +39,6 @@ var (
|
||||
Uint64Type = &uintType{gmstypes.Uint64}
|
||||
)
|
||||
|
||||
func CreateUintTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
if width, ok := params[uintTypeParam_Width]; ok {
|
||||
switch width {
|
||||
case uintTypeParam_Width_8:
|
||||
return Uint8Type, nil
|
||||
case uintTypeParam_Width_16:
|
||||
return Uint16Type, nil
|
||||
case uintTypeParam_Width_24:
|
||||
return Uint24Type, nil
|
||||
case uintTypeParam_Width_32:
|
||||
return Uint32Type, nil
|
||||
case uintTypeParam_Width_64:
|
||||
return Uint64Type, nil
|
||||
default:
|
||||
return nil, fmt.Errorf(`create uint type info has "%v" param with value "%v"`, uintTypeParam_Width, width)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf(`create uint type info is missing "%v" param`, uintTypeParam_Width)
|
||||
}
|
||||
|
||||
// ConvertNomsValueToValue implements TypeInfo interface.
|
||||
func (ti *uintType) ConvertNomsValueToValue(v types.Value) (interface{}, error) {
|
||||
if val, ok := v.(types.Uint); ok {
|
||||
|
||||
@@ -16,22 +16,14 @@ package typeinfo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
|
||||
"github.com/dolthub/vitess/go/sqltypes"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
const (
|
||||
varBinaryTypeParam_Length = "length"
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
)
|
||||
|
||||
// As a type, this is modeled more after MySQL's story for binary data. There, it's treated
|
||||
@@ -46,31 +38,6 @@ type varBinaryType struct {
|
||||
|
||||
var _ TypeInfo = (*varBinaryType)(nil)
|
||||
|
||||
var (
|
||||
TinyBlobType TypeInfo = &varBinaryType{sqlBinaryType: gmstypes.TinyBlob}
|
||||
BlobType TypeInfo = &varBinaryType{sqlBinaryType: gmstypes.Blob}
|
||||
MediumBlobType TypeInfo = &varBinaryType{sqlBinaryType: gmstypes.MediumBlob}
|
||||
LongBlobType TypeInfo = &varBinaryType{sqlBinaryType: gmstypes.LongBlob}
|
||||
)
|
||||
|
||||
func CreateVarBinaryTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var length int64
|
||||
var err error
|
||||
if lengthStr, ok := params[varBinaryTypeParam_Length]; ok {
|
||||
length, err = strconv.ParseInt(lengthStr, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf(`create varbinary type info is missing param "%v"`, varBinaryTypeParam_Length)
|
||||
}
|
||||
sqlType, err := gmstypes.CreateBinary(sqltypes.Blob, length)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &varBinaryType{sqlType}, nil
|
||||
}
|
||||
|
||||
// ConvertNomsValueToValue implements TypeInfo interface.
|
||||
func (ti *varBinaryType) ConvertNomsValueToValue(v types.Value) (interface{}, error) {
|
||||
if val, ok := v.(types.Blob); ok {
|
||||
@@ -199,29 +166,6 @@ func fromBlob(b types.Blob) ([]byte, error) {
|
||||
return str, nil
|
||||
}
|
||||
|
||||
// hasPrefix finds out if a Blob has a prefixed integer. Initially blobs for varBinary prepended an integer indicating
|
||||
// the length, which was unnecessary (as the underlying sequence tracks the total size). It's been removed, but this
|
||||
// may be used to see if a Blob is one of those older Blobs. A false positive is possible, but EXTREMELY unlikely.
|
||||
func hasPrefix(b types.Blob, ctx context.Context) (bool, error) {
|
||||
blobLength := b.Len()
|
||||
if blobLength < 8 {
|
||||
return false, nil
|
||||
}
|
||||
countBytes := make([]byte, 8)
|
||||
n, err := b.ReadAt(ctx, countBytes, 0)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if n != 8 {
|
||||
return false, fmt.Errorf("wanted 8 bytes from blob for count, got %d", n)
|
||||
}
|
||||
prefixedLength := binary.LittleEndian.Uint64(countBytes)
|
||||
if prefixedLength == blobLength-8 {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// varBinaryTypeConverter is an internal function for GetTypeConverter that handles the specific type as the source TypeInfo.
|
||||
func varBinaryTypeConverter(ctx context.Context, src *varBinaryType, destTi TypeInfo) (tc TypeConverter, needsConversion bool, err error) {
|
||||
switch dest := destTi.(type) {
|
||||
|
||||
@@ -28,15 +28,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
const (
|
||||
varStringTypeParam_Collate = "collate"
|
||||
varStringTypeParam_Length = "length"
|
||||
varStringTypeParam_SQL = "sql"
|
||||
varStringTypeParam_SQL_Char = "char"
|
||||
varStringTypeParam_SQL_VarChar = "varchar"
|
||||
varStringTypeParam_SQL_Text = "text"
|
||||
)
|
||||
|
||||
// varStringType handles CHAR and VARCHAR. The TEXT types are handled by blobStringType. For any repositories that were
|
||||
// created before the introduction of blobStringType, they will use varStringType for TEXT types. As varStringType makes
|
||||
// use of the String Value type, it does not actually support all viable lengths of a TEXT string, meaning all such
|
||||
@@ -60,48 +51,6 @@ func CreateVarStringTypeFromSqlType(stringType sql.StringType) TypeInfo {
|
||||
return &varStringType{stringType}
|
||||
}
|
||||
|
||||
func CreateVarStringTypeFromParams(params map[string]string) (TypeInfo, error) {
|
||||
var length int64
|
||||
var collation sql.CollationID
|
||||
var err error
|
||||
if collationStr, ok := params[varStringTypeParam_Collate]; ok {
|
||||
collation, err = sql.ParseCollation("", collationStr, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf(`create varstring type info is missing param "%v"`, varStringTypeParam_Collate)
|
||||
}
|
||||
if maxLengthStr, ok := params[varStringTypeParam_Length]; ok {
|
||||
length, err = strconv.ParseInt(maxLengthStr, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
} else {
|
||||
return nil, fmt.Errorf(`create varstring type info is missing param "%v"`, varStringTypeParam_Length)
|
||||
}
|
||||
if sqlStr, ok := params[varStringTypeParam_SQL]; ok {
|
||||
var sqlType sql.StringType
|
||||
switch sqlStr {
|
||||
case varStringTypeParam_SQL_Char:
|
||||
sqlType, err = gmstypes.CreateString(sqltypes.Char, length, collation)
|
||||
case varStringTypeParam_SQL_VarChar:
|
||||
sqlType, err = gmstypes.CreateString(sqltypes.VarChar, length, collation)
|
||||
case varStringTypeParam_SQL_Text:
|
||||
sqlType, err = gmstypes.CreateString(sqltypes.Text, length, collation)
|
||||
default:
|
||||
return nil, fmt.Errorf(`create varstring type info has "%v" param with value "%v"`, varStringTypeParam_SQL, sqlStr)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &varStringType{sqlType}, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf(`create varstring type info is missing param "%v"`, varStringTypeParam_Length)
|
||||
}
|
||||
}
|
||||
|
||||
// ConvertNomsValueToValue implements TypeInfo interface.
|
||||
func (ti *varStringType) ConvertNomsValueToValue(v types.Value) (interface{}, error) {
|
||||
if val, ok := v.(types.String); ok {
|
||||
|
||||
@@ -16,7 +16,6 @@ package index
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
@@ -30,7 +29,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb/durable"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/typed/noms"
|
||||
"github.com/dolthub/dolt/go/store/datas"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
"github.com/dolthub/dolt/go/store/pool"
|
||||
@@ -755,7 +753,7 @@ func (di *doltIndex) getDurableState(ctx *sql.Context, ti DoltTableable) (*durab
|
||||
}
|
||||
|
||||
func (di *doltIndex) prollyRanges(ctx *sql.Context, ns tree.NodeStore, ranges ...sql.MySQLRange) ([]prolly.Range, error) {
|
||||
//todo(max): it is important that *doltIndexLookup maintains a reference
|
||||
// todo(max): it is important that *doltIndexLookup maintains a reference
|
||||
// to empty sqlRanges, otherwise the analyzer will dismiss the index and
|
||||
// chose a less optimal lookup index. This is a GMS concern, so GMS should
|
||||
// really not rely on the integrator to maintain this tenuous relationship.
|
||||
@@ -773,113 +771,6 @@ func (di *doltIndex) prollyRanges(ctx *sql.Context, ns tree.NodeStore, ranges ..
|
||||
return pranges, nil
|
||||
}
|
||||
|
||||
func (di *doltIndex) nomsRanges(ctx *sql.Context, iranges ...sql.MySQLRange) ([]*noms.ReadRange, error) {
|
||||
// This might remain nil if the given nomsRanges each contain an EmptyRange for one of the columns. This will just
|
||||
// cause the lookup to return no rows, which is the desired behavior.
|
||||
var readRanges []*noms.ReadRange
|
||||
|
||||
ranges := make([]sql.MySQLRange, len(iranges))
|
||||
|
||||
for i := range iranges {
|
||||
ranges[i] = DropTrailingAllColumnExprs(iranges[i])
|
||||
}
|
||||
|
||||
ranges, err := SplitNullsFromRanges(ranges)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
RangeLoop:
|
||||
for _, rang := range ranges {
|
||||
if len(rang) > len(di.columns) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var lowerKeys []interface{}
|
||||
for _, rangeColumnExpr := range rang {
|
||||
if rangeColumnExpr.HasLowerBound() {
|
||||
lowerKeys = append(lowerKeys, sql.GetMySQLRangeCutKey(rangeColumnExpr.LowerBound))
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
lowerboundTuple, err := di.keysToTuple(ctx, lowerKeys)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rangeCheck := make(nomsRangeCheck, len(rang))
|
||||
for i, rangeColumnExpr := range rang {
|
||||
// An empty column expression will mean that no values for this column can be matched, so we can discard the
|
||||
// entire range.
|
||||
if ok, err := rangeColumnExpr.IsEmpty(); err != nil {
|
||||
return nil, err
|
||||
} else if ok {
|
||||
continue RangeLoop
|
||||
}
|
||||
|
||||
cb := columnBounds{}
|
||||
// We promote each type as the value has already been validated against the type
|
||||
promotedType := di.columns[i].TypeInfo.Promote()
|
||||
if rangeColumnExpr.HasLowerBound() {
|
||||
key := sql.GetMySQLRangeCutKey(rangeColumnExpr.LowerBound)
|
||||
val, err := promotedType.ConvertValueToNomsValue(ctx, di.vrw, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if rangeColumnExpr.LowerBound.TypeAsLowerBound() == sql.Closed {
|
||||
// For each lowerbound case, we set the upperbound to infinity, as the upperbound can increment to
|
||||
// get to the desired overall case while retaining whatever was set for the lowerbound.
|
||||
cb.boundsCase = boundsCase_greaterEquals_infinity
|
||||
} else {
|
||||
cb.boundsCase = boundsCase_greater_infinity
|
||||
}
|
||||
cb.lowerbound = val
|
||||
} else {
|
||||
cb.boundsCase = boundsCase_infinity_infinity
|
||||
}
|
||||
if rangeColumnExpr.HasUpperBound() {
|
||||
key := sql.GetMySQLRangeCutKey(rangeColumnExpr.UpperBound)
|
||||
val, err := promotedType.ConvertValueToNomsValue(ctx, di.vrw, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if rangeColumnExpr.UpperBound.TypeAsUpperBound() == sql.Closed {
|
||||
// Bounds cases are enum aliases on bytes, and they're arranged such that we can increment the case
|
||||
// that was previously set when evaluating the lowerbound to get the proper overall case.
|
||||
cb.boundsCase += 1
|
||||
} else {
|
||||
cb.boundsCase += 2
|
||||
}
|
||||
cb.upperbound = val
|
||||
}
|
||||
if rangeColumnExpr.Type() == sql.RangeType_EqualNull {
|
||||
cb.boundsCase = boundsCase_isNull
|
||||
}
|
||||
rangeCheck[i] = cb
|
||||
}
|
||||
|
||||
// If the suffix checks will always succeed (both bounds are infinity) then they can be removed to reduce the
|
||||
// number of checks that are called per-row. Always leave one check to skip NULLs.
|
||||
for i := len(rangeCheck) - 1; i > 0 && len(rangeCheck) > 1; i-- {
|
||||
if rangeCheck[i].boundsCase == boundsCase_infinity_infinity {
|
||||
rangeCheck = rangeCheck[:i]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
readRanges = append(readRanges, &noms.ReadRange{
|
||||
Start: lowerboundTuple,
|
||||
Inclusive: true, // The checks handle whether a value is included or not
|
||||
Reverse: false,
|
||||
Check: rangeCheck,
|
||||
})
|
||||
}
|
||||
|
||||
return readRanges, nil
|
||||
}
|
||||
|
||||
func (di *doltIndex) sqlRowConverter(s *durableIndexState, columns []uint64) *KVToSqlRowConverter {
|
||||
return s.sqlRowConverter(di, columns)
|
||||
}
|
||||
@@ -1125,29 +1016,6 @@ func (di *doltIndex) FullTextKeyColumns(ctx *sql.Context) (fulltext.KeyColumns,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// keysToTuple returns a tuple that indicates the starting point for an index. The empty tuple will cause the index to
|
||||
// start at the very beginning.
|
||||
func (di *doltIndex) keysToTuple(ctx *sql.Context, keys []interface{}) (types.Tuple, error) {
|
||||
nbf := di.vrw.Format()
|
||||
if len(keys) > len(di.columns) {
|
||||
return types.EmptyTuple(nbf), errors.New("too many keys for the column count")
|
||||
}
|
||||
|
||||
vals := make([]types.Value, len(keys)*2)
|
||||
for i := range keys {
|
||||
col := di.columns[i]
|
||||
// As an example, if our TypeInfo is Int8, we should not fail to create a tuple if we are returning all keys
|
||||
// that have a value of less than 9001, thus we promote the TypeInfo to the widest type.
|
||||
val, err := col.TypeInfo.Promote().ConvertValueToNomsValue(ctx, di.vrw, keys[i])
|
||||
if err != nil {
|
||||
return types.EmptyTuple(nbf), err
|
||||
}
|
||||
vals[2*i] = types.Uint(col.Tag)
|
||||
vals[2*i+1] = val
|
||||
}
|
||||
return types.NewTuple(nbf, vals...)
|
||||
}
|
||||
|
||||
var sharePool = pool.NewBuffPool()
|
||||
|
||||
func maybeGetKeyBuilder(idx durable.Index) *val.TupleBuilder {
|
||||
|
||||
@@ -17,195 +17,9 @@ package index
|
||||
import (
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/typed/noms"
|
||||
"github.com/dolthub/dolt/go/store/prolly"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
func ClosedRange(tpl1, tpl2 types.Tuple) *noms.ReadRange {
|
||||
return CustomRange(tpl1, tpl2, sql.Closed, sql.Closed)
|
||||
}
|
||||
|
||||
func OpenRange(tpl1, tpl2 types.Tuple) *noms.ReadRange {
|
||||
return CustomRange(tpl1, tpl2, sql.Open, sql.Open)
|
||||
}
|
||||
|
||||
func CustomRange(tpl1, tpl2 types.Tuple, bt1, bt2 sql.MySQLRangeBoundType) *noms.ReadRange {
|
||||
var nrc nomsRangeCheck
|
||||
_ = tpl1.IterFields(func(tupleIndex uint64, tupleVal types.Value) (stop bool, err error) {
|
||||
if tupleIndex%2 == 0 {
|
||||
return false, nil
|
||||
}
|
||||
if bt1 == sql.Closed {
|
||||
nrc = append(nrc, columnBounds{
|
||||
boundsCase: boundsCase_greaterEquals_infinity,
|
||||
lowerbound: tupleVal,
|
||||
})
|
||||
} else {
|
||||
nrc = append(nrc, columnBounds{
|
||||
boundsCase: boundsCase_greater_infinity,
|
||||
lowerbound: tupleVal,
|
||||
})
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
_ = tpl2.IterFields(func(tupleIndex uint64, tupleVal types.Value) (stop bool, err error) {
|
||||
if tupleIndex%2 == 0 {
|
||||
return false, nil
|
||||
}
|
||||
idx := (tupleIndex - 1) / 2
|
||||
if bt2 == sql.Closed {
|
||||
// Bounds cases are enum aliases on bytes, and they're arranged such that we can increment the case
|
||||
// that was previously set when evaluating the lowerbound to get the proper overall case.
|
||||
nrc[idx].boundsCase += 1
|
||||
nrc[idx].upperbound = tupleVal
|
||||
} else {
|
||||
nrc[idx].boundsCase += 2
|
||||
nrc[idx].upperbound = tupleVal
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
return &noms.ReadRange{
|
||||
Start: tpl1,
|
||||
Inclusive: true,
|
||||
Reverse: false,
|
||||
Check: nrc,
|
||||
}
|
||||
}
|
||||
|
||||
func GreaterThanRange(tpl types.Tuple) *noms.ReadRange {
|
||||
var nrc nomsRangeCheck
|
||||
_ = tpl.IterFields(func(tupleIndex uint64, tupleVal types.Value) (stop bool, err error) {
|
||||
if tupleIndex%2 == 0 {
|
||||
return false, nil
|
||||
}
|
||||
nrc = append(nrc, columnBounds{
|
||||
boundsCase: boundsCase_greater_infinity,
|
||||
lowerbound: tupleVal,
|
||||
})
|
||||
return false, nil
|
||||
})
|
||||
return &noms.ReadRange{
|
||||
Start: tpl,
|
||||
Inclusive: true,
|
||||
Reverse: false,
|
||||
Check: nrc,
|
||||
}
|
||||
}
|
||||
|
||||
func LessThanRange(tpl types.Tuple) *noms.ReadRange {
|
||||
var nrc nomsRangeCheck
|
||||
_ = tpl.IterFields(func(tupleIndex uint64, tupleVal types.Value) (stop bool, err error) {
|
||||
if tupleIndex%2 == 0 {
|
||||
return false, nil
|
||||
}
|
||||
nrc = append(nrc, columnBounds{
|
||||
boundsCase: boundsCase_infinity_less,
|
||||
upperbound: tupleVal,
|
||||
})
|
||||
return false, nil
|
||||
})
|
||||
return &noms.ReadRange{
|
||||
Start: types.EmptyTuple(types.Format_Default),
|
||||
Inclusive: true,
|
||||
Reverse: false,
|
||||
Check: nrc,
|
||||
}
|
||||
}
|
||||
|
||||
func GreaterOrEqualRange(tpl types.Tuple) *noms.ReadRange {
|
||||
var nrc nomsRangeCheck
|
||||
_ = tpl.IterFields(func(tupleIndex uint64, tupleVal types.Value) (stop bool, err error) {
|
||||
if tupleIndex%2 == 0 {
|
||||
return false, nil
|
||||
}
|
||||
nrc = append(nrc, columnBounds{
|
||||
boundsCase: boundsCase_greaterEquals_infinity,
|
||||
lowerbound: tupleVal,
|
||||
})
|
||||
return false, nil
|
||||
})
|
||||
return &noms.ReadRange{
|
||||
Start: tpl,
|
||||
Inclusive: true,
|
||||
Reverse: false,
|
||||
Check: nrc,
|
||||
}
|
||||
}
|
||||
|
||||
func LessOrEqualRange(tpl types.Tuple) *noms.ReadRange {
|
||||
var nrc nomsRangeCheck
|
||||
_ = tpl.IterFields(func(tupleIndex uint64, tupleVal types.Value) (stop bool, err error) {
|
||||
if tupleIndex%2 == 0 {
|
||||
return false, nil
|
||||
}
|
||||
nrc = append(nrc, columnBounds{
|
||||
boundsCase: boundsCase_infinity_lessEquals,
|
||||
upperbound: tupleVal,
|
||||
})
|
||||
return false, nil
|
||||
})
|
||||
return &noms.ReadRange{
|
||||
Start: types.EmptyTuple(types.Format_Default),
|
||||
Inclusive: true,
|
||||
Reverse: false,
|
||||
Check: nrc,
|
||||
}
|
||||
}
|
||||
|
||||
func NullRange() *noms.ReadRange {
|
||||
return &noms.ReadRange{
|
||||
Start: types.EmptyTuple(types.Format_Default),
|
||||
Inclusive: true,
|
||||
Reverse: false,
|
||||
Check: nomsRangeCheck{
|
||||
{
|
||||
boundsCase: boundsCase_isNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NotNullRange() *noms.ReadRange {
|
||||
return &noms.ReadRange{
|
||||
Start: types.EmptyTuple(types.Format_Default),
|
||||
Inclusive: true,
|
||||
Reverse: false,
|
||||
Check: nomsRangeCheck{
|
||||
{
|
||||
boundsCase: boundsCase_infinity_infinity,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func AllRange() *noms.ReadRange {
|
||||
return &noms.ReadRange{
|
||||
Start: types.EmptyTuple(types.Format_Default),
|
||||
Inclusive: true,
|
||||
Reverse: false,
|
||||
Check: nomsRangeCheck{},
|
||||
}
|
||||
}
|
||||
|
||||
func ReadRangesEqual(nr1, nr2 *noms.ReadRange) bool {
|
||||
if nr1 == nil || nr2 == nil {
|
||||
if nr1 == nil && nr2 == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
if nr1.Inclusive != nr2.Inclusive || nr1.Reverse != nr2.Reverse || !nr1.Start.Equals(nr2.Start) ||
|
||||
!nr1.Check.(nomsRangeCheck).Equals(nr2.Check.(nomsRangeCheck)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func NomsRangesFromIndexLookup(ctx *sql.Context, lookup sql.IndexLookup) ([]*noms.ReadRange, error) {
|
||||
return lookup.Index.(*doltIndex).nomsRanges(ctx, lookup.Ranges.(sql.MySQLRangeCollection)...)
|
||||
}
|
||||
|
||||
func ProllyRangesFromIndexLookup(ctx *sql.Context, lookup sql.IndexLookup) ([]prolly.Range, error) {
|
||||
idx := lookup.Index.(*doltIndex)
|
||||
return idx.prollyRanges(ctx, idx.ns, lookup.Ranges.(sql.MySQLRangeCollection)...)
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
package sqlutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -56,173 +54,6 @@ func DoltRowToSqlRow(doltRow row.Row, sch schema.Schema) (sql.Row, error) {
|
||||
return sql.NewRow(colVals...), nil
|
||||
}
|
||||
|
||||
// SqlRowToDoltRow constructs a Dolt row.Row from a go-mysql-server sql.Row.
|
||||
func SqlRowToDoltRow(ctx context.Context, vrw types.ValueReadWriter, r sql.Row, doltSchema schema.Schema) (row.Row, error) {
|
||||
if schema.IsKeyless(doltSchema) {
|
||||
return keylessDoltRowFromSqlRow(ctx, vrw, r, doltSchema)
|
||||
}
|
||||
return pkDoltRowFromSqlRow(ctx, vrw, r, doltSchema)
|
||||
}
|
||||
|
||||
// DoltKeyValueAndMappingFromSqlRow converts a sql.Row to key and value tuples and keeps a mapping from tag to value that
|
||||
// can be used to speed up index key generation for foreign key checks.
|
||||
func DoltKeyValueAndMappingFromSqlRow(ctx context.Context, vrw types.ValueReadWriter, r sql.Row, doltSchema schema.Schema) (types.Tuple, types.Tuple, map[uint64]types.Value, error) {
|
||||
numCols := doltSchema.GetAllCols().Size()
|
||||
vals := make([]types.Value, numCols*2)
|
||||
tagToVal := make(map[uint64]types.Value, numCols)
|
||||
|
||||
nonPKCols := doltSchema.GetNonPKCols()
|
||||
numNonPKVals := nonPKCols.Size() * 2
|
||||
nonPKVals := vals[:numNonPKVals]
|
||||
pkVals := vals[numNonPKVals:]
|
||||
|
||||
for i, c := range doltSchema.GetAllCols().GetColumns() {
|
||||
val := r[i]
|
||||
if val == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
nomsVal, err := c.TypeInfo.ConvertValueToNomsValue(ctx, vrw, val)
|
||||
if err != nil {
|
||||
return types.Tuple{}, types.Tuple{}, nil, err
|
||||
}
|
||||
|
||||
tagToVal[c.Tag] = nomsVal
|
||||
}
|
||||
|
||||
nonPKIdx := 0
|
||||
for _, tag := range nonPKCols.SortedTags {
|
||||
// nonPkCols sorted by ascending tag order
|
||||
if val, ok := tagToVal[tag]; ok {
|
||||
nonPKVals[nonPKIdx] = types.Uint(tag)
|
||||
nonPKVals[nonPKIdx+1] = val
|
||||
nonPKIdx += 2
|
||||
}
|
||||
}
|
||||
|
||||
pkIdx := 0
|
||||
for _, tag := range doltSchema.GetPKCols().Tags {
|
||||
// pkCols are in the primary key defined order
|
||||
if val, ok := tagToVal[tag]; ok {
|
||||
pkVals[pkIdx] = types.Uint(tag)
|
||||
pkVals[pkIdx+1] = val
|
||||
pkIdx += 2
|
||||
}
|
||||
}
|
||||
|
||||
nonPKVals = nonPKVals[:nonPKIdx]
|
||||
|
||||
nbf := vrw.Format()
|
||||
keyTuple, err := types.NewTuple(nbf, pkVals...)
|
||||
|
||||
if err != nil {
|
||||
return types.Tuple{}, types.Tuple{}, nil, err
|
||||
}
|
||||
|
||||
valTuple, err := types.NewTuple(nbf, nonPKVals...)
|
||||
|
||||
if err != nil {
|
||||
return types.Tuple{}, types.Tuple{}, nil, err
|
||||
}
|
||||
|
||||
return keyTuple, valTuple, tagToVal, nil
|
||||
}
|
||||
|
||||
// DoltKeyAndMappingFromSqlRow converts a sql.Row to key tuple and keeps a mapping from tag to value that
|
||||
// can be used to speed up index key generation for foreign key checks.
|
||||
func DoltKeyAndMappingFromSqlRow(ctx context.Context, vrw types.ValueReadWriter, r sql.Row, doltSchema schema.Schema) (types.Tuple, map[uint64]types.Value, error) {
|
||||
if r == nil {
|
||||
return types.EmptyTuple(vrw.Format()), nil, sql.ErrUnexpectedNilRow.New()
|
||||
}
|
||||
|
||||
allCols := doltSchema.GetAllCols()
|
||||
pkCols := doltSchema.GetPKCols()
|
||||
|
||||
numCols := allCols.Size()
|
||||
numPKCols := pkCols.Size()
|
||||
pkVals := make([]types.Value, numPKCols*2)
|
||||
tagToVal := make(map[uint64]types.Value, numCols)
|
||||
|
||||
if len(r) < numCols {
|
||||
numCols = len(r)
|
||||
}
|
||||
|
||||
for i := 0; i < numCols; i++ {
|
||||
schCol := allCols.GetByIndex(i)
|
||||
val := r[i]
|
||||
if val == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
tag := schCol.Tag
|
||||
nomsVal, err := schCol.TypeInfo.ConvertValueToNomsValue(ctx, vrw, val)
|
||||
|
||||
if err != nil {
|
||||
return types.Tuple{}, nil, err
|
||||
}
|
||||
|
||||
tagToVal[tag] = nomsVal
|
||||
}
|
||||
|
||||
pkOrds := doltSchema.GetPkOrdinals()
|
||||
for i, pkCol := range pkCols.GetColumns() {
|
||||
ord := pkOrds[i]
|
||||
val := r[ord]
|
||||
if val == nil {
|
||||
return types.Tuple{}, nil, errors.New("not all pk columns have a value")
|
||||
}
|
||||
pkVals[i*2] = types.Uint(pkCol.Tag)
|
||||
pkVals[i*2+1] = tagToVal[pkCol.Tag]
|
||||
}
|
||||
|
||||
nbf := vrw.Format()
|
||||
keyTuple, err := types.NewTuple(nbf, pkVals...)
|
||||
|
||||
if err != nil {
|
||||
return types.Tuple{}, nil, err
|
||||
}
|
||||
|
||||
return keyTuple, tagToVal, nil
|
||||
}
|
||||
|
||||
func pkDoltRowFromSqlRow(ctx context.Context, vrw types.ValueReadWriter, r sql.Row, doltSchema schema.Schema) (row.Row, error) {
|
||||
taggedVals := make(row.TaggedValues)
|
||||
allCols := doltSchema.GetAllCols()
|
||||
for i, val := range r {
|
||||
tag := allCols.Tags[i]
|
||||
schCol := allCols.TagToCol[tag]
|
||||
if val != nil {
|
||||
var err error
|
||||
taggedVals[tag], err = schCol.TypeInfo.ConvertValueToNomsValue(ctx, vrw, val)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return row.New(vrw.Format(), doltSchema, taggedVals)
|
||||
}
|
||||
|
||||
func keylessDoltRowFromSqlRow(ctx context.Context, vrw types.ValueReadWriter, sqlRow sql.Row, sch schema.Schema) (row.Row, error) {
|
||||
j := 0
|
||||
vals := make([]types.Value, sch.GetAllCols().Size()*2)
|
||||
|
||||
for idx, val := range sqlRow {
|
||||
if val != nil {
|
||||
col := sch.GetAllCols().GetByIndex(idx)
|
||||
nv, err := col.TypeInfo.ConvertValueToNomsValue(ctx, vrw, val)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
vals[j] = types.Uint(col.Tag)
|
||||
vals[j+1] = nv
|
||||
j += 2
|
||||
}
|
||||
}
|
||||
|
||||
return row.KeylessRow(vrw.Format(), vals[:j]...)
|
||||
}
|
||||
|
||||
// BinaryAsHexDisplayValue is a wrapper for binary values that should be displayed as hex strings.
|
||||
type BinaryAsHexDisplayValue string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user