mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-23 13:48:42 -05:00
added enum and set encodings
This commit is contained in:
@@ -70,6 +70,10 @@ func GetField(td val.TupleDesc, i int, tup val.Tuple) (v interface{}, err error)
|
||||
}
|
||||
case val.DatetimeEnc:
|
||||
v, ok = td.GetDatetime(i, tup)
|
||||
case val.EnumEnc:
|
||||
v, ok = td.GetEnum(i, tup)
|
||||
case val.SetEnc:
|
||||
v, ok = td.GetSet(i, tup)
|
||||
case val.StringEnc:
|
||||
v, ok = td.GetString(i, tup)
|
||||
case val.ByteStringEnc:
|
||||
@@ -145,6 +149,10 @@ func PutField(tb *val.TupleBuilder, i int, v interface{}) error {
|
||||
tb.PutSqlTime(i, t)
|
||||
case val.DatetimeEnc:
|
||||
tb.PutDatetime(i, v.(time.Time))
|
||||
case val.EnumEnc:
|
||||
tb.PutEnum(i, v.(uint16))
|
||||
case val.SetEnc:
|
||||
tb.PutSet(i, v.(uint64))
|
||||
case val.StringEnc:
|
||||
tb.PutString(i, v.(string))
|
||||
case val.ByteStringEnc:
|
||||
|
||||
@@ -132,20 +132,12 @@ func encodingFromSqlType(typ query.Type) val.Encoding {
|
||||
|
||||
// todo(andy): replace temp encodings
|
||||
switch typ {
|
||||
case query.Type_DECIMAL:
|
||||
return val.DecimalEnc
|
||||
case query.Type_GEOMETRY:
|
||||
return val.GeometryEnc
|
||||
case query.Type_BIT:
|
||||
return val.Uint64Enc
|
||||
case query.Type_BLOB:
|
||||
return val.ByteStringEnc
|
||||
case query.Type_TEXT:
|
||||
return val.StringEnc
|
||||
case query.Type_ENUM:
|
||||
return val.StringEnc
|
||||
case query.Type_SET:
|
||||
return val.StringEnc
|
||||
case query.Type_JSON:
|
||||
return val.JSONEnc
|
||||
}
|
||||
@@ -175,6 +167,8 @@ func encodingFromSqlType(typ query.Type) val.Encoding {
|
||||
return val.Float32Enc
|
||||
case query.Type_FLOAT64:
|
||||
return val.Float64Enc
|
||||
case query.Type_DECIMAL:
|
||||
return val.DecimalEnc
|
||||
case query.Type_YEAR:
|
||||
return val.YearEnc
|
||||
case query.Type_DATE:
|
||||
@@ -185,6 +179,10 @@ func encodingFromSqlType(typ query.Type) val.Encoding {
|
||||
return val.DatetimeEnc
|
||||
case query.Type_DATETIME:
|
||||
return val.DatetimeEnc
|
||||
case query.Type_ENUM:
|
||||
return val.EnumEnc
|
||||
case query.Type_SET:
|
||||
return val.SetEnc
|
||||
case query.Type_BINARY:
|
||||
return val.ByteStringEnc
|
||||
case query.Type_VARBINARY:
|
||||
@@ -193,6 +191,8 @@ func encodingFromSqlType(typ query.Type) val.Encoding {
|
||||
return val.StringEnc
|
||||
case query.Type_VARCHAR:
|
||||
return val.StringEnc
|
||||
case query.Type_GEOMETRY:
|
||||
return val.GeometryEnc
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown encoding %v", typ))
|
||||
}
|
||||
|
||||
@@ -55,6 +55,9 @@ const (
|
||||
dateSize ByteSize = 4
|
||||
timeSize ByteSize = 8
|
||||
datetimeSize ByteSize = 8
|
||||
|
||||
enumSize ByteSize = 2
|
||||
setSize ByteSize = 8
|
||||
)
|
||||
|
||||
type Encoding uint8
|
||||
@@ -80,6 +83,9 @@ const (
|
||||
TimeEnc Encoding = 16
|
||||
DatetimeEnc Encoding = 17
|
||||
|
||||
EnumEnc Encoding = 18
|
||||
SetEnc Encoding = 19
|
||||
|
||||
sentinel Encoding = 127
|
||||
)
|
||||
|
||||
@@ -478,6 +484,30 @@ func compareDatetime(l, r time.Time) int {
|
||||
}
|
||||
}
|
||||
|
||||
func readEnum(val []byte) uint16 {
|
||||
return readUint16(val)
|
||||
}
|
||||
|
||||
func writeEnum(buf []byte, val uint16) {
|
||||
writeUint16(buf, val)
|
||||
}
|
||||
|
||||
func compareEnum(l, r uint16) int {
|
||||
return compareUint16(l, r)
|
||||
}
|
||||
|
||||
func readSet(val []byte) uint64 {
|
||||
return readUint64(val)
|
||||
}
|
||||
|
||||
func writeSet(buf []byte, val uint64) {
|
||||
writeUint64(buf, val)
|
||||
}
|
||||
|
||||
func compareSet(l, r uint64) int {
|
||||
return compareUint64(l, r)
|
||||
}
|
||||
|
||||
func readString(val []byte) string {
|
||||
return stringFromBytes(readByteString(val))
|
||||
}
|
||||
|
||||
@@ -189,6 +189,20 @@ func (tb *TupleBuilder) PutDatetime(i int, v time.Time) {
|
||||
tb.pos += datetimeSize
|
||||
}
|
||||
|
||||
func (tb *TupleBuilder) PutEnum(i int, v uint16) {
|
||||
tb.Desc.expectEncoding(i, EnumEnc)
|
||||
tb.fields[i] = tb.buf[tb.pos : tb.pos+enumSize]
|
||||
writeEnum(tb.fields[i], v)
|
||||
tb.pos += enumSize
|
||||
}
|
||||
|
||||
func (tb *TupleBuilder) PutSet(i int, v uint64) {
|
||||
tb.Desc.expectEncoding(i, SetEnc)
|
||||
tb.fields[i] = tb.buf[tb.pos : tb.pos+setSize]
|
||||
writeSet(tb.fields[i], v)
|
||||
tb.pos += setSize
|
||||
}
|
||||
|
||||
func (tb *TupleBuilder) PutDecimal(i int, v decimal.Decimal) {
|
||||
tb.Desc.expectEncoding(i, DecimalEnc)
|
||||
sz := sizeOfDecimal(v)
|
||||
|
||||
@@ -98,6 +98,10 @@ func compare(typ Type, left, right []byte) int {
|
||||
return compareTime(readTime(left), readTime(right))
|
||||
case DatetimeEnc:
|
||||
return compareDatetime(readDatetime(left), readDatetime(right))
|
||||
case EnumEnc:
|
||||
return compareEnum(readEnum(left), readEnum(right))
|
||||
case SetEnc:
|
||||
return compareSet(readSet(left), readSet(right))
|
||||
case DecimalEnc:
|
||||
return compareDecimal(readDecimal(left), readDecimal(right))
|
||||
case StringEnc:
|
||||
|
||||
@@ -296,6 +296,28 @@ func (td TupleDesc) GetDatetime(i int, tup Tuple) (v time.Time, ok bool) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetEnum reads a uin16 from the ith field of the Tuple.
|
||||
// If the ith field is NULL, |ok| is set to false.
|
||||
func (td TupleDesc) GetEnum(i int, tup Tuple) (v uint16, ok bool) {
|
||||
td.expectEncoding(i, EnumEnc)
|
||||
b := td.GetField(i, tup)
|
||||
if b != nil {
|
||||
v, ok = readEnum(b), true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetSet reads a uint64 from the ith field of the Tuple.
|
||||
// If the ith field is NULL, |ok| is set to false.
|
||||
func (td TupleDesc) GetSet(i int, tup Tuple) (v uint64, ok bool) {
|
||||
td.expectEncoding(i, SetEnc)
|
||||
b := td.GetField(i, tup)
|
||||
if b != nil {
|
||||
v, ok = readSet(b), true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetString reads a string from the ith field of the Tuple.
|
||||
// If the ith field is NULL, |ok| is set to false.
|
||||
func (td TupleDesc) GetString(i int, tup Tuple) (v string, ok bool) {
|
||||
|
||||
Reference in New Issue
Block a user