Skip to content

Commit

Permalink
Implemented DECIMAL, TIME, ENUM, and SET, along with missing type ali…
Browse files Browse the repository at this point in the history
…ases
  • Loading branch information
Hydrocharged committed Apr 14, 2020
1 parent 4d54586 commit 75fb59d
Show file tree
Hide file tree
Showing 23 changed files with 2,054 additions and 338 deletions.
523 changes: 395 additions & 128 deletions bats/types.bats

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ require (

replace github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi => ./gen/proto/dolt/services/eventsapi

replace github.com/src-d/go-mysql-server => github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200414183459-0b63a0868140
replace github.com/src-d/go-mysql-server => github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200414214346-0c65dac7ca1e

replace vitess.io/vitess => github.com/liquidata-inc/vitess v0.0.0-20200413233505-a88cc54bd1ee

Expand Down
32 changes: 32 additions & 0 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,46 @@ github.com/krishicks/yaml-patch v0.0.10/go.mod h1:Sm5TchwZS6sm7RJoyg87tzxm2ZcKzd
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/liquidata-inc/go-mysql-server v0.4.1-0.20200311072715-b12ae9d0cc97 h1:Zr78cjOfa0bM4X5JA692xhx3QvFPTsJiM0bD0xl/22Q=
github.com/liquidata-inc/go-mysql-server v0.4.1-0.20200311072715-b12ae9d0cc97/go.mod h1:Lh0pg7jnO08HxFm6oj6gtcSTUeeOTu4Spt50Aeo2mes=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200330231002-2ac5a85cf8d6 h1:iKET+xfMh3NaiiIbrMBLi+MJ9hwmm++7DBtPGfarf50=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200330231002-2ac5a85cf8d6 h1:iKET+xfMh3NaiiIbrMBLi+MJ9hwmm++7DBtPGfarf50=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200330231002-2ac5a85cf8d6/go.mod h1:TCTrDbzIA05e8zV3SW+nsjc1LCR58GRSOIcF32lJ+Qc=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200330231002-2ac5a85cf8d6/go.mod h1:TCTrDbzIA05e8zV3SW+nsjc1LCR58GRSOIcF32lJ+Qc=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200403150612-34c67410dcd4 h1:UIksBT7bRENT38ErKSz+auGLc7a5tDpCHwNhuajoJbU=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200403150612-34c67410dcd4/go.mod h1:TCTrDbzIA05e8zV3SW+nsjc1LCR58GRSOIcF32lJ+Qc=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200403171307-83ac7e7158e2 h1:l4mXLvgHMoihWuEqcmcJKEvQtAccHxhsKwkVn/okoxc=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200403171307-83ac7e7158e2/go.mod h1:TCTrDbzIA05e8zV3SW+nsjc1LCR58GRSOIcF32lJ+Qc=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200407175239-21fb18d4d9fd h1:SGGh7+XPqPYw3LaIK4VUvy/81Za1Y3p29lh4WDMtXh0=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200407175239-21fb18d4d9fd/go.mod h1:xu1cUi3vfWVJZ/9mQl9f8sdfJGobnS7kIucM3lfWIPk=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200412072052-a6583959dafb/go.mod h1:n8M6jtUZ5myu3O9kfcLqRnXPBVkqbkoBPe45mnYCKd0=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200412232521-1e406e8056fb/go.mod h1:n8M6jtUZ5myu3O9kfcLqRnXPBVkqbkoBPe45mnYCKd0=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200414052025-88d3eff3f7f5 h1:Liiz/stNuLoWg1j1A/yGChITW4H/IbEyFwPGZPk+B8M=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200414052025-88d3eff3f7f5/go.mod h1:n8M6jtUZ5myu3O9kfcLqRnXPBVkqbkoBPe45mnYCKd0=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200414183459-0b63a0868140 h1:rxT0Pkt2ZLS0P4m8scQ3TATRjKYcntF6F0X5/yHcIDg=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200414183459-0b63a0868140/go.mod h1:tK/saWoda2x+KXyGsdVariMdfVOsjmRgQF2pbl4Mr1E=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200414214346-0c65dac7ca1e h1:cYKHqocy3oNkPmfayDwIswVy14Dcp8q5FFSYLS4FvIA=
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200414214346-0c65dac7ca1e/go.mod h1:tK/saWoda2x+KXyGsdVariMdfVOsjmRgQF2pbl4Mr1E=
github.com/liquidata-inc/ishell v0.0.0-20190514193646-693241f1f2a0 h1:phMgajKClMUiIr+hF2LGt8KRuUa2Vd2GI1sNgHgSXoU=
github.com/liquidata-inc/ishell v0.0.0-20190514193646-693241f1f2a0/go.mod h1:YC1rI9k5gx8D02ljlbxDfZe80s/iq8bGvaaQsvR+qxs=
github.com/liquidata-inc/mmap-go v1.0.3 h1:2LndAeAtup9rpvUmu4wZSYCsjCQ0Zpc+NqE+6+PnT7g=
github.com/liquidata-inc/mmap-go v1.0.3/go.mod h1:w0doE7jfkuDEZyxb/zD3VWnRaQBYx1uDTS816kH8HoY=
github.com/liquidata-inc/sqllogictest/go v0.0.0-20200225183643-358992a611e1 h1:BDpmbvQ9I8npWe7TOzQcGkrn7EYHrW1hJtTd9h8MNZA=
github.com/liquidata-inc/sqllogictest/go v0.0.0-20200225183643-358992a611e1/go.mod h1:kKRVtyuomkqz15YFRpS0OT8kpsU8y/F3jyiZtvALdKU=
github.com/liquidata-inc/sqllogictest/go v0.0.0-20200320151923-b11801f10e15 h1:H3RwcYfzkdW4kFh7znTUopcX3XZqnFXm6pcmxSy0mNo=
github.com/liquidata-inc/sqllogictest/go v0.0.0-20200320151923-b11801f10e15 h1:H3RwcYfzkdW4kFh7znTUopcX3XZqnFXm6pcmxSy0mNo=
github.com/liquidata-inc/sqllogictest/go v0.0.0-20200320151923-b11801f10e15/go.mod h1:kKRVtyuomkqz15YFRpS0OT8kpsU8y/F3jyiZtvALdKU=
github.com/liquidata-inc/sqllogictest/go v0.0.0-20200320151923-b11801f10e15/go.mod h1:kKRVtyuomkqz15YFRpS0OT8kpsU8y/F3jyiZtvALdKU=
github.com/liquidata-inc/vitess v0.0.0-20200102230944-f3410911d61f h1:fqsJy7h3D3esm9tYSzU7LV6h2tfifdYTanPuDL5LJ1A=
github.com/liquidata-inc/vitess v0.0.0-20200102230944-f3410911d61f/go.mod h1:vn/QvIl/1+N6+qjheejcLt8jmX2kQSQwFinzZuoY1VY=
github.com/liquidata-inc/vitess v0.0.0-20200318153456-e0b079da3f54 h1:LR/OEhgIYVQuo5a/lxr8Ps76AZ1FNWUgNANfKCA0XSQ=
github.com/liquidata-inc/vitess v0.0.0-20200318153456-e0b079da3f54 h1:LR/OEhgIYVQuo5a/lxr8Ps76AZ1FNWUgNANfKCA0XSQ=
github.com/liquidata-inc/vitess v0.0.0-20200318153456-e0b079da3f54/go.mod h1:vn/QvIl/1+N6+qjheejcLt8jmX2kQSQwFinzZuoY1VY=
github.com/liquidata-inc/vitess v0.0.0-20200318153456-e0b079da3f54/go.mod h1:vn/QvIl/1+N6+qjheejcLt8jmX2kQSQwFinzZuoY1VY=
github.com/liquidata-inc/vitess v0.0.0-20200407071440-54a487aaf7d9 h1:eaE6IFxMviaDSNFaKlTbNPA/+0Vhj/XgV6lG2SaoAWM=
github.com/liquidata-inc/vitess v0.0.0-20200407071440-54a487aaf7d9/go.mod h1:vn/QvIl/1+N6+qjheejcLt8jmX2kQSQwFinzZuoY1VY=
github.com/liquidata-inc/vitess v0.0.0-20200410001601-55d11bea14ca h1:m09m0bRpTa3PCxMNcnRf5AiVK7ME0PVIci1vwuciZ5w=
github.com/liquidata-inc/vitess v0.0.0-20200410001601-55d11bea14ca/go.mod h1:vn/QvIl/1+N6+qjheejcLt8jmX2kQSQwFinzZuoY1VY=
github.com/liquidata-inc/vitess v0.0.0-20200413233505-a88cc54bd1ee h1:r8ApUMNHHEyzRhPbuIHrWbr7FOTW4Yo5Sm1HpOEzPrQ=
github.com/liquidata-inc/vitess v0.0.0-20200413233505-a88cc54bd1ee/go.mod h1:vn/QvIl/1+N6+qjheejcLt8jmX2kQSQwFinzZuoY1VY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/doltcore/rowconv/row_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func isNecessary(srcSch, destSch schema.Schema, destToSrc map[uint64]uint64) (bo
return true, nil
}

if srcCol.Kind != destCol.Kind {
if !srcCol.TypeInfo.Equals(destCol.TypeInfo) {
return true, nil
}
}
Expand Down
24 changes: 10 additions & 14 deletions go/libraries/doltcore/schema/encoding/schema_marshaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,8 @@ func TestJSONMarshalling(t *testing.T) {
func TestTypeInfoMarshalling(t *testing.T) {
//TODO: determine the storage format for BINARY
//TODO: determine the storage format for BLOB
//TODO: determine the storage format for DECIMAL
//TODO: determine the storage format for ENUM
//TODO: determine the storage format for LONGBLOB
//TODO: determine the storage format for MEDIUMBLOB
//TODO: determine the storage format for SET
//TODO: determine the storage format for TIME
//TODO: determine the storage format for TINYBLOB
//TODO: determine the storage format for VARBINARY
sqlTypes := []sql.Type{
Expand All @@ -134,11 +130,11 @@ func TestTypeInfoMarshalling(t *testing.T) {
//sql.Blob, //BLOB
sql.Boolean, //BOOLEAN
sql.MustCreateStringWithDefaults(sqltypes.Char, 10), //CHAR(10)
sql.Date, //DATE
sql.Datetime, //DATETIME
//sql.MustCreateDecimalType(9, 5), //DECIMAL(9, 5)
sql.Float64, //DOUBLE
//sql.MustCreateEnumType([]string{"a", "b", "c"}, sql.Collation_Default), //ENUM('a','b','c')
sql.Date, //DATE
sql.Datetime, //DATETIME
sql.MustCreateDecimalType(9, 5), //DECIMAL(9, 5)
sql.Float64, //DOUBLE
sql.MustCreateEnumType([]string{"a", "b", "c"}, sql.Collation_Default), //ENUM('a','b','c')
sql.Float32, //FLOAT
sql.Int32, //INT
sql.Uint32, //INT UNSIGNED
Expand All @@ -148,11 +144,11 @@ func TestTypeInfoMarshalling(t *testing.T) {
sql.Int24, //MEDIUMINT
sql.Uint24, //MEDIUMINT UNSIGNED
sql.MediumText, //MEDIUMTEXT
//sql.MustCreateSetType([]string{"a", "b", "c"}, sql.Collation_Default), //SET('a','b','c')
sql.Int16, //SMALLINT
sql.Uint16, //SMALLINT UNSIGNED
sql.Text, //TEXT
//sql.Time, //TIME
sql.MustCreateSetType([]string{"a", "b", "c"}, sql.Collation_Default), //SET('a','b','c')
sql.Int16, //SMALLINT
sql.Uint16, //SMALLINT UNSIGNED
sql.Text, //TEXT
sql.Time, //TIME
sql.Timestamp, //TIMESTAMP
//sql.TinyBlob, //TINYBLOB
sql.Int8, //TINYINT
Expand Down
23 changes: 23 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@ func generateVarBinaryType(t *testing.T, length int64, pad bool) *varBinaryType
return &varBinaryType{sql.MustCreateBinary(sqltypes.VarBinary, length)}
}

func generateVarStringTypes(t *testing.T, numOfTypes uint16) []TypeInfo {
var res []TypeInfo
loop(t, 1, 500, numOfTypes, func(i int64) {
rts := false
if i%2 == 0 {
rts = true
}
res = append(res, generateVarStringType(t, i, rts))
})
return res
}

func generateVarStringType(t *testing.T, length int64, rts bool) *varStringType {
require.True(t, length > 0)
if rts {
t, err := sql.CreateStringWithDefaults(sqltypes.Char, length)
if err == nil {
return &varStringType{t}
}
}
return &varStringType{sql.MustCreateStringWithDefaults(sqltypes.VarChar, length)}
}

func loop(t *testing.T, start int64, endInclusive int64, numOfSteps uint16, loopedFunc func(int64)) {
require.True(t, endInclusive > start)
maxNumOfSteps := endInclusive - start + 1
Expand Down
29 changes: 9 additions & 20 deletions go/libraries/doltcore/schema/typeinfo/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"strconv"

"github.com/shopspring/decimal"
"github.com/src-d/go-mysql-server/sql"

"github.com/liquidata-inc/dolt/go/store/types"
Expand Down Expand Up @@ -66,12 +67,8 @@ func CreateDecimalTypeFromParams(params map[string]string) (TypeInfo, error) {

// ConvertNomsValueToValue implements TypeInfo interface.
func (ti *decimalType) ConvertNomsValueToValue(v types.Value) (interface{}, error) {
if val, ok := v.(types.String); ok {
res, err := ti.sqlDecimalType.Convert(string(val))
if err != nil {
return nil, fmt.Errorf(`"%v" cannot convert "%v" to value`, ti.String(), val)
}
return res, nil
if val, ok := v.(types.Decimal); ok {
return ti.sqlDecimalType.Convert(decimal.Decimal(val))
}
if _, ok := v.(types.Null); ok || v == nil {
return nil, nil
Expand All @@ -84,15 +81,14 @@ func (ti *decimalType) ConvertValueToNomsValue(v interface{}) (types.Value, erro
if v == nil {
return types.NullValue, nil
}
strVal, err := ti.sqlDecimalType.Convert(v)
decVal, err := ti.sqlDecimalType.ConvertToDecimal(v)
if err != nil {
return nil, err
}
val, ok := strVal.(string)
if ok {
return types.String(val), nil
if !decVal.Valid {
return nil, fmt.Errorf(`"%v" has unexpectedly encountered a null value from embedded type`, ti.String())
}
return nil, fmt.Errorf(`"%v" has unexpectedly encountered a value of type "%T" from embedded type`, ti.String(), v)
return types.Decimal(decVal.Decimal), nil
}

// Equals implements TypeInfo interface.
Expand Down Expand Up @@ -144,22 +140,15 @@ func (ti *decimalType) IsValid(v types.Value) bool {

// NomsKind implements TypeInfo interface.
func (ti *decimalType) NomsKind() types.NomsKind {
return types.StringKind
return types.DecimalKind
}

// ParseValue implements TypeInfo interface.
func (ti *decimalType) ParseValue(str *string) (types.Value, error) {
if str == nil || *str == "" {
return types.NullValue, nil
}
strVal, err := ti.sqlDecimalType.Convert(*str)
if err != nil {
return nil, err
}
if val, ok := strVal.(string); ok {
return types.String(val), nil
}
return nil, fmt.Errorf(`"%v" cannot convert the string "%v" to a value`, ti.String(), str)
return ti.ConvertValueToNomsValue(*str)
}

// String implements TypeInfo interface.
Expand Down
Loading

0 comments on commit 75fb59d

Please sign in to comment.