Skip to content

Commit

Permalink
fix the uint convertion
Browse files Browse the repository at this point in the history
  • Loading branch information
wenruimeng-work authored and wenruimeng-work committed Feb 13, 2024
1 parent ac68ff6 commit 10be2f5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion marshal/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func (t *TestInterfaceImpl2) foo() {

type TestInterfaceStruct struct {
Val TestInterface
UintVal32 uint32
UintVal64 uint64
UintVal uint
Uint8 uint8
NestedVal TestInterface
Arr []TestInterface
NestedArr [][]TestInterface
Expand Down Expand Up @@ -116,7 +120,7 @@ func TestInterfaceMarshal(t *testing.T) {
if err != nil {
t.Errorf("failed to marshal values: %v", err)
}
assert.Equal(t, 7, len(schemaHandler.ValueColumns))
assert.Equal(t, 11, len(schemaHandler.ValueColumns))
elementTestSchema := (*tableMap)["Parquet_go_root\x01Arr\x01List\x01Element\x01Test"]
elementBarSchema := (*tableMap)["Parquet_go_root\x01Arr\x01List\x01Element\x01NestedInterface\x01Bar"]
nestedElementTestSchema := (*tableMap)["Parquet_go_root\x01NestedArr\x01List\x01Element\x01List\x01Element\x01Test"]
Expand Down
18 changes: 16 additions & 2 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ func StrToParquetType(s string, pT *parquet.Type, cT *parquet.ConvertedType, len
}
}

func IsUint(kind reflect.Kind) bool {
return kind == reflect.Uint || kind == reflect.Uint16 || kind == reflect.Uint32 || kind == reflect.Uint8 || kind == reflect.Uint64
}

func InterfaceToParquetType(src interface{}, pT *parquet.Type) interface{} {
if src == nil {
return src
Expand All @@ -224,14 +228,24 @@ func InterfaceToParquetType(src interface{}, pT *parquet.Type) interface{} {
if _, ok := src.(int32); ok {
return src
} else {
return int32(reflect.ValueOf(src).Int())
v := reflect.ValueOf(src)
if IsUint(v.Kind()) {
return uint32(v.Uint())
} else {
return int32(v.Int())
}
}

case parquet.Type_INT64:
if _, ok := src.(int64); ok {
return src
} else {
return reflect.ValueOf(src).Int()
v := reflect.ValueOf(src)
if IsUint(v.Kind()) {
return uint64(v.Uint())
} else {
return int64(v.Int())
}
}

case parquet.Type_FLOAT:
Expand Down

0 comments on commit 10be2f5

Please sign in to comment.