Skip to content

Commit

Permalink
Support reflection from float16.Num
Browse files Browse the repository at this point in the history
  • Loading branch information
benibus committed Oct 31, 2023
1 parent e414709 commit f0ead7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions go/parquet/schema/reflection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strconv"
"strings"

"github.com/apache/arrow/go/v14/arrow/float16"
"github.com/apache/arrow/go/v14/parquet"
format "github.com/apache/arrow/go/v14/parquet/internal/gen-go/parquet"
"golang.org/x/xerrors"
Expand Down Expand Up @@ -375,6 +376,9 @@ func typeToNode(name string, typ reflect.Type, repType parquet.Repetition, info
}
return Must(MapOf(name, key, value, repType, fieldID))
case reflect.Struct:
if typ == reflect.TypeOf(float16.Num{}) {
return MustPrimitive(NewPrimitiveNodeLogical(name, repType, Float16LogicalType{}, parquet.Types.FixedLenByteArray, 2, fieldID))
}
// structs are Group nodes
fields := make(FieldList, 0)
for i := 0; i < typ.NumField(); i++ {
Expand Down
3 changes: 3 additions & 0 deletions go/parquet/schema/reflection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"reflect"
"testing"

"github.com/apache/arrow/go/v14/arrow/float16"
"github.com/apache/arrow/go/v14/parquet"
"github.com/apache/arrow/go/v14/parquet/schema"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -154,6 +155,7 @@ func ExampleNewSchemaFromStruct_logicaltypes() {
UUID [16]byte `parquet:"logical=uuid"`
Float16 [2]byte `parquet:"logical=float16"`
Float16Optional *[2]byte `parquet:"logical=float16"`
Float16Num float16.Num
}

sc, err := schema.NewSchemaFromStruct(LogicalTypes{})
Expand Down Expand Up @@ -184,6 +186,7 @@ func ExampleNewSchemaFromStruct_logicaltypes() {
// required fixed_len_byte_array field_id=-1 UUID (UUID);
// required fixed_len_byte_array field_id=-1 Float16 (Float16);
// optional fixed_len_byte_array field_id=-1 Float16Optional (Float16);
// required fixed_len_byte_array field_id=-1 Float16Num (Float16);
// }
}

Expand Down

0 comments on commit f0ead7d

Please sign in to comment.