Skip to content

Commit

Permalink
Expand Range Of Data Types Supported As Hash Keys (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
atris authored Jun 16, 2021
1 parent 9ddc9f2 commit edc94bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
22 changes: 14 additions & 8 deletions internal/encoding/block/from_orc.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,21 @@ func convertToJSON(value interface{}) (string, bool) {
return string(json.RawMessage(b)), true
}

// convertToString converst value to string because currently all the keys in Badger are stored in the form of string before hashing to the byte array
// convertToString converts value to string because currently all the keys in Badger are stored in the form of string before hashing to the byte array
func convertToString(value interface{}) (string, bool) {
v, ok := value.(string)
if ok {
return v, true
}
valueInt, ok := value.(int64)
if ok {
return strconv.FormatInt(valueInt, 10), true
switch value.(type) {
case string:
return value.(string), true
case int64:
return strconv.FormatInt(value.(int64), 10), true
case int32:
return strconv.FormatInt(int64(value.(int32)), 10), true
case []uint8:
return string(value.([]uint8)), true
case float32:
return strconv.FormatFloat(float64(value.(float32)), 'E', -1, 64), true
case float64:
return strconv.FormatFloat(value.(float64), 'E', -1, 64), true
}

return "", false
Expand Down
12 changes: 12 additions & 0 deletions internal/encoding/block/from_parquet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,16 @@ func TestFromParquet_Nested(t *testing.T) {
b, err := FromParquetBy(o, "foo", nil, apply)
assert.NoError(t, err)
assert.Equal(t, 10000, len(b))

b, err = FromParquetBy(o, "bar", nil, apply)
assert.NoError(t, err)
assert.Equal(t, 10000, len(b))

b, err = FromParquetBy(o, "foofoo", nil, apply)
assert.NoError(t, err)
assert.Equal(t, 1, len(b))

b, err = FromParquetBy(o, "barbar", nil, apply)
assert.NoError(t, err)
assert.Equal(t, 10000, len(b))
}

0 comments on commit edc94bc

Please sign in to comment.