Skip to content

Commit

Permalink
tablecodec: fix project1 (talent-plan#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 authored Mar 14, 2022
1 parent d8ccf3c commit fecae66
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions tablecodec/tablecodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,44 +102,25 @@ func DecodeIndexKeyPrefix(key kv.Key) (tableID int64, indexID int64, indexValues
func DecodeIndexKey(key kv.Key) (tableID int64, indexID int64, indexValues []string, err error) {
k := key

tableID, indexID, isRecord, err := DecodeKeyHead(key)
tableID, indexID, key, err = DecodeIndexKeyPrefix(key)
if err != nil {
return 0, 0, nil, errors.Trace(err)
}
if isRecord {
err = errInvalidIndexKey.GenWithStack("invalid index key - %q", k)
return 0, 0, nil, err
}
indexKey := key[prefixLen+idLen:]
indexValues, err = DecodeValuesBytesToStrings(indexKey)
if err != nil {
err = errInvalidIndexKey.GenWithStack("invalid index key - %q %v", k, err)
return 0, 0, nil, err
}
return tableID, indexID, indexValues, nil
}

// DecodeValuesBytesToStrings decode the raw bytes to strings for each columns.
// FIXME: Without the schema information, we can only decode the raw kind of
// the column. For instance, MysqlTime is internally saved as uint64.
func DecodeValuesBytesToStrings(b []byte) ([]string, error) {
var datumValues []string
for len(b) > 0 {
remain, d, e := codec.DecodeOne(b)
for len(key) > 0 {
remain, d, e := codec.DecodeOne(key)
if e != nil {
return nil, e
return 0, 0, nil, errInvalidIndexKey.GenWithStack("invalid index key - %q %v", k, e)
}
str, e1 := d.ToString()
if e1 != nil {
return nil, e
return 0, 0, nil, errInvalidIndexKey.GenWithStack("invalid index key - %q %v", k, e1)
}
datumValues = append(datumValues, str)
b = remain
indexValues = append(indexValues, str)
key = remain
}
return datumValues, nil
return
}


// EncodeRow encode row data and column ids into a slice of byte.
// Row layout: colID1, value1, colID2, value2, .....
// valBuf and values pass by caller, for reducing EncodeRow allocates temporary bufs. If you pass valBuf and values as nil,
Expand Down

0 comments on commit fecae66

Please sign in to comment.