From 824411f474d636d97e85ab2a384956db0d257a95 Mon Sep 17 00:00:00 2001 From: Atri Sharma Date: Mon, 14 Jun 2021 11:38:36 +0530 Subject: [PATCH 1/2] Expand Range Of Data Types Supported As Hash Keys --- internal/encoding/block/from_orc.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/encoding/block/from_orc.go b/internal/encoding/block/from_orc.go index e65e42db..fd29dbf8 100644 --- a/internal/encoding/block/from_orc.go +++ b/internal/encoding/block/from_orc.go @@ -137,7 +137,7 @@ 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 { @@ -148,5 +148,26 @@ func convertToString(value interface{}) (string, bool) { return strconv.FormatInt(valueInt, 10), true } + valueInt32, ok := value.(int32) + if ok { + return strconv.FormatInt(int64(valueInt32), 10), true + } + + valueByteArray := string(value.([]uint8)) + + if valueByteArray != "" { + return valueByteArray, true + } + + valueFloat32, ok := value.(float32) + if ok { + return strconv.FormatFloat(float64(valueFloat32), 'E', -1, 64), true + } + + valueFloat64, ok := value.(float64) + if ok { + return strconv.FormatFloat(valueFloat64, 'E', -1, 64), true + } + return "", false } From cd0a698fd0e54c39523a735bccce58b0863e1bae Mon Sep 17 00:00:00 2001 From: Atri Sharma Date: Wed, 16 Jun 2021 12:58:14 +0530 Subject: [PATCH 2/2] Add Tests --- internal/encoding/block/from_orc.go | 41 +++++++------------- internal/encoding/block/from_parquet_test.go | 12 ++++++ 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/internal/encoding/block/from_orc.go b/internal/encoding/block/from_orc.go index fd29dbf8..a7e332c9 100644 --- a/internal/encoding/block/from_orc.go +++ b/internal/encoding/block/from_orc.go @@ -139,34 +139,19 @@ func convertToJSON(value interface{}) (string, bool) { // 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 - } - - valueInt32, ok := value.(int32) - if ok { - return strconv.FormatInt(int64(valueInt32), 10), true - } - - valueByteArray := string(value.([]uint8)) - - if valueByteArray != "" { - return valueByteArray, true - } - - valueFloat32, ok := value.(float32) - if ok { - return strconv.FormatFloat(float64(valueFloat32), 'E', -1, 64), true - } - - valueFloat64, ok := value.(float64) - if ok { - return strconv.FormatFloat(valueFloat64, 'E', -1, 64), 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 diff --git a/internal/encoding/block/from_parquet_test.go b/internal/encoding/block/from_parquet_test.go index 55e29472..a3d16079 100644 --- a/internal/encoding/block/from_parquet_test.go +++ b/internal/encoding/block/from_parquet_test.go @@ -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)) } \ No newline at end of file