Skip to content

Commit f48e915

Browse files
author
Matthew Topol
committed
test(utils): add test for arrow field from column meta
1 parent f7001b5 commit f48e915

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

changelog.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{ .Commits - }}
1+
{{ .Commits -}}

utils_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"testing"
88

9+
"github.com/apache/arrow/go/arrow"
910
"github.com/factset/go-drill/internal/rpc/proto/exec/rpc"
1011
"github.com/factset/go-drill/internal/rpc/proto/exec/shared"
1112
"github.com/factset/go-drill/internal/rpc/proto/exec/user"
@@ -239,3 +240,50 @@ func TestReadPrefixedMessageErr(t *testing.T) {
239240
assert.Nil(t, out)
240241
assert.Error(t, err)
241242
}
243+
244+
func TestArrowFromColPanic(t *testing.T) {
245+
c := &user.ColumnMetadata{}
246+
assert.Panics(t, func() { ColMetaToArrowField(c) })
247+
}
248+
249+
func TestArrowFromCol(t *testing.T) {
250+
tests := []struct {
251+
name string
252+
typ string
253+
expected arrow.DataType
254+
nullable bool
255+
def string
256+
}{
257+
{"bool", "BOOLEAN", arrow.FixedWidthTypes.Boolean, true, "false"},
258+
{"binary", "BINARY VARYING", arrow.BinaryTypes.Binary, false, ""},
259+
{"varchar", "CHARACTER VARYING", arrow.BinaryTypes.String, true, "foo"},
260+
{"integer", "INTEGER", arrow.PrimitiveTypes.Int32, false, "1"},
261+
{"int64", "BIGINT", arrow.PrimitiveTypes.Int64, true, "123456"},
262+
{"int16", "SMALLINT", arrow.PrimitiveTypes.Int16, false, "65535"},
263+
{"tinyint", "TINYINT", arrow.PrimitiveTypes.Int8, true, "1"},
264+
{"date", "DATE", arrow.FixedWidthTypes.Date64, false, "1987-08-04"},
265+
{"time", "TIME", arrow.FixedWidthTypes.Time32ms, true, "12:30PM"},
266+
{"float", "FLOAT", arrow.PrimitiveTypes.Float32, false, "1.2"},
267+
{"double", "DOUBLE", arrow.PrimitiveTypes.Float64, false, "1.2"},
268+
{"timestamp", "TIMESTAMP", arrow.FixedWidthTypes.Timestamp_ms, true, "123456789"},
269+
}
270+
271+
for _, tt := range tests {
272+
t.Run(tt.name, func(t *testing.T) {
273+
c := &user.ColumnMetadata{
274+
ColumnName: &tt.name,
275+
DataType: &tt.typ,
276+
IsNullable: &tt.nullable,
277+
DefaultValue: &tt.def,
278+
}
279+
280+
f := ColMetaToArrowField(c)
281+
assert.True(t, f.Equal(arrow.Field{
282+
Name: tt.name,
283+
Type: tt.expected,
284+
Nullable: tt.nullable,
285+
Metadata: arrow.NewMetadata([]string{"default"}, []string{tt.def}),
286+
}))
287+
})
288+
}
289+
}

0 commit comments

Comments
 (0)