|
6 | 6 | "io"
|
7 | 7 | "testing"
|
8 | 8 |
|
| 9 | + "github.com/apache/arrow/go/arrow" |
9 | 10 | "github.com/factset/go-drill/internal/rpc/proto/exec/rpc"
|
10 | 11 | "github.com/factset/go-drill/internal/rpc/proto/exec/shared"
|
11 | 12 | "github.com/factset/go-drill/internal/rpc/proto/exec/user"
|
@@ -239,3 +240,50 @@ func TestReadPrefixedMessageErr(t *testing.T) {
|
239 | 240 | assert.Nil(t, out)
|
240 | 241 | assert.Error(t, err)
|
241 | 242 | }
|
| 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