This is an automated email from the ASF dual-hosted git repository.
sbinet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 94255a4 ARROW-9416: [Go] Add testcases for some datatypes
94255a4 is described below
commit 94255a4de73ded7bb9cd2b6a73214a9e1a4a35ed
Author: dota17 <[email protected]>
AuthorDate: Mon Jul 13 11:59:22 2020 +0200
ARROW-9416: [Go] Add testcases for some datatypes
Closes #7712 from dota17/go_9416_testcases
Authored-by: dota17 <[email protected]>
Signed-off-by: Sebastien Binet <[email protected]>
---
go/arrow/compare_test.go | 36 +++-
...tatype_null_test.go => datatype_binary_test.go} | 31 ++-
go/arrow/datatype_fixedwidth_test.go | 228 +++++++++++++++++++++
go/arrow/datatype_null_test.go | 4 +
go/arrow/schema_test.go | 52 ++++-
5 files changed, 337 insertions(+), 14 deletions(-)
diff --git a/go/arrow/compare_test.go b/go/arrow/compare_test.go
index 47e1bb7..89112de 100644
--- a/go/arrow/compare_test.go
+++ b/go/arrow/compare_test.go
@@ -42,6 +42,9 @@ func TestTypeEqual(t *testing.T) {
Null, Null, true, false,
},
{
+ &BinaryType{}, &StringType{}, false, false,
+ },
+ {
&Time32Type{Unit: Second}, &Time32Type{Unit: Second},
true, false,
},
{
@@ -143,13 +146,44 @@ func TestTypeEqual(t *testing.T) {
Field{Name: "f1", Type:
PrimitiveTypes.Uint32, Nullable: true},
Field{Name: "f2", Type:
PrimitiveTypes.Uint32, Nullable: true},
},
- index: map[string]int{"f1": 0, "f2": 0},
+ index: map[string]int{"f1": 0, "f2": 1},
},
false, true,
},
{
&StructType{
fields: []Field{
+ Field{Name: "f1", Type:
PrimitiveTypes.Uint32, Nullable: true},
+ },
+ index: map[string]int{"f1": 0},
+ },
+ &StructType{
+ fields: []Field{
+ Field{Name: "f1", Type:
PrimitiveTypes.Uint32, Nullable: true},
+ Field{Name: "f2", Type:
PrimitiveTypes.Uint32, Nullable: true},
+ },
+ index: map[string]int{"f1": 0, "f2": 1},
+ },
+ false, false,
+ },
+ {
+ &StructType{
+ fields: []Field{
+ Field{Name: "f1", Type:
PrimitiveTypes.Uint32, Nullable: true},
+ },
+ index: map[string]int{"f1": 0},
+ },
+ &StructType{
+ fields: []Field{
+ Field{Name: "f2", Type:
PrimitiveTypes.Uint32, Nullable: true},
+ },
+ index: map[string]int{"f2": 0},
+ },
+ false, false,
+ },
+ {
+ &StructType{
+ fields: []Field{
Field{Name: "f1", Type:
PrimitiveTypes.Uint16, Nullable: true},
Field{Name: "f2", Type:
PrimitiveTypes.Float32, Nullable: false},
},
diff --git a/go/arrow/datatype_null_test.go b/go/arrow/datatype_binary_test.go
similarity index 50%
copy from go/arrow/datatype_null_test.go
copy to go/arrow/datatype_binary_test.go
index e773cc4..26791e9 100644
--- a/go/arrow/datatype_null_test.go
+++ b/go/arrow/datatype_binary_test.go
@@ -22,13 +22,32 @@ import (
"github.com/apache/arrow/go/arrow"
)
-func TestNullType(t *testing.T) {
- var nt *arrow.NullType
- if got, want := nt.ID(), arrow.NULL; got != want {
- t.Fatalf("invalid null type id. got=%v, want=%v", got, want)
+func TestBinaryType(t *testing.T) {
+ var nt *arrow.BinaryType
+ if got, want := nt.ID(), arrow.BINARY; got != want {
+ t.Fatalf("invalid binary type id. got=%v, want=%v", got, want)
}
- if got, want := nt.Name(), "null"; got != want {
- t.Fatalf("invalid null type name. got=%q, want=%q", got, want)
+ if got, want := nt.Name(), "binary"; got != want {
+ t.Fatalf("invalid binary type name. got=%v, want=%v", got, want)
+ }
+
+ if got, want := nt.String(), "binary"; got != want {
+ t.Fatalf("invalid binary type stringer. got=%v, want=%v", got,
want)
+ }
+}
+
+func TestStringType(t *testing.T) {
+ var nt *arrow.StringType
+ if got, want := nt.ID(), arrow.STRING; got != want {
+ t.Fatalf("invalid string type id. got=%v, want=%v", got, want)
+ }
+
+ if got, want := nt.Name(), "utf8"; got != want {
+ t.Fatalf("invalid string type name. got=%v, want=%v", got, want)
+ }
+
+ if got, want := nt.String(), "utf8"; got != want {
+ t.Fatalf("invalid string type stringer. got=%v, want=%v", got,
want)
}
}
diff --git a/go/arrow/datatype_fixedwidth_test.go
b/go/arrow/datatype_fixedwidth_test.go
index 5fb02e0..3f5153c 100644
--- a/go/arrow/datatype_fixedwidth_test.go
+++ b/go/arrow/datatype_fixedwidth_test.go
@@ -67,3 +67,231 @@ func TestDecimal128Type(t *testing.T) {
})
}
}
+
+func TestFixedSizeBinaryType(t *testing.T) {
+ for _, tc := range []struct {
+ byteWidth int
+ want string
+ }{
+ {1, "fixed_size_binary[1]"},
+ {8, "fixed_size_binary[8]"},
+ {100, "fixed_size_binary[100]"},
+ {100000000, "fixed_size_binary[100000000]"},
+ } {
+ t.Run(tc.want, func(t *testing.T) {
+ dt := arrow.FixedSizeBinaryType{tc.byteWidth}
+ if got, want := dt.BitWidth(), 8 * tc.byteWidth; got !=
want {
+ t.Fatalf("invalid bitwidth: got=%d, want=%d",
got, want)
+ }
+
+ if got, want := dt.Name(), "fixed_size_binary"; got !=
want {
+ t.Fatalf("invalid type name: got=%q, want=%q",
got, want)
+ }
+
+ if got, want := dt.ID(), arrow.FIXED_SIZE_BINARY; got
!= want {
+ t.Fatalf("invalid type ID: got=%v, want=%v",
got, want)
+ }
+
+ if got, want := dt.String(), tc.want; got != want {
+ t.Fatalf("invalid type stringer: got=%q,
want=%q", got, want)
+ }
+ })
+ }
+}
+
+func TestTimestampType(t *testing.T) {
+ for _, tc := range []struct {
+ unit arrow.TimeUnit
+ timeZone string
+ want string
+ }{
+ {arrow.Nanosecond, "CST", "timestamp[ns, tz=CST]"},
+ {arrow.Microsecond, "EST", "timestamp[us, tz=EST]"},
+ {arrow.Millisecond, "UTC", "timestamp[ms, tz=UTC]"},
+ {arrow.Second, "", "timestamp[s]"},
+ } {
+ t.Run(tc.want, func(t *testing.T) {
+ dt := arrow.TimestampType{tc.unit, tc.timeZone}
+ if got, want := dt.BitWidth(), 64; got != want {
+ t.Fatalf("invalid bitwidth: got=%d, want=%d",
got, want)
+ }
+
+ if got, want := dt.Name(), "timestamp"; got != want {
+ t.Fatalf("invalid type name: got=%q, want=%q",
got, want)
+ }
+
+ if got, want := dt.ID(), arrow.TIMESTAMP; got != want {
+ t.Fatalf("invalid type ID: got=%v, want=%v",
got, want)
+ }
+
+ if got, want := dt.String(), tc.want; got != want {
+ t.Fatalf("invalid type stringer: got=%q,
want=%q", got, want)
+ }
+ })
+ }
+}
+
+func TestTime32Type(t *testing.T) {
+ for _, tc := range []struct {
+ unit arrow.TimeUnit
+ want string
+ }{
+ {arrow.Millisecond, "time32[ms]"},
+ {arrow.Second, "time32[s]"},
+ } {
+ t.Run(tc.want, func(t *testing.T) {
+ dt := arrow.Time32Type{tc.unit}
+ if got, want := dt.BitWidth(), 32; got != want {
+ t.Fatalf("invalid bitwidth: got=%d, want=%d",
got, want)
+ }
+
+ if got, want := dt.Name(), "time32"; got != want {
+ t.Fatalf("invalid type name: got=%q, want=%q",
got, want)
+ }
+
+ if got, want := dt.ID(), arrow.TIME32; got != want {
+ t.Fatalf("invalid type ID: got=%v, want=%v",
got, want)
+ }
+
+ if got, want := dt.String(), tc.want; got != want {
+ t.Fatalf("invalid type stringer: got=%q,
want=%q", got, want)
+ }
+ })
+ }
+}
+
+func TestTime64Type(t *testing.T) {
+ for _, tc := range []struct {
+ unit arrow.TimeUnit
+ want string
+ }{
+ {arrow.Nanosecond, "time64[ns]"},
+ {arrow.Microsecond, "time64[us]"},
+ } {
+ t.Run(tc.want, func(t *testing.T) {
+ dt := arrow.Time64Type{tc.unit}
+ if got, want := dt.BitWidth(), 64; got != want {
+ t.Fatalf("invalid bitwidth: got=%d, want=%d",
got, want)
+ }
+
+ if got, want := dt.Name(), "time64"; got != want {
+ t.Fatalf("invalid type name: got=%q, want=%q",
got, want)
+ }
+
+ if got, want := dt.ID(), arrow.TIME64; got != want {
+ t.Fatalf("invalid type ID: got=%v, want=%v",
got, want)
+ }
+
+ if got, want := dt.String(), tc.want; got != want {
+ t.Fatalf("invalid type stringer: got=%q,
want=%q", got, want)
+ }
+ })
+ }
+}
+
+func TestDurationType(t *testing.T) {
+ for _, tc := range []struct {
+ unit arrow.TimeUnit
+ want string
+ }{
+ {arrow.Nanosecond, "duration[ns]"},
+ {arrow.Microsecond, "duration[us]"},
+ {arrow.Millisecond, "duration[ms]"},
+ {arrow.Second, "duration[s]"},
+ } {
+ t.Run(tc.want, func(t *testing.T) {
+ dt := arrow.DurationType{tc.unit}
+ if got, want := dt.BitWidth(), 64; got != want {
+ t.Fatalf("invalid bitwidth: got=%d, want=%d",
got, want)
+ }
+
+ if got, want := dt.Name(), "duration"; got != want {
+ t.Fatalf("invalid type name: got=%q, want=%q",
got, want)
+ }
+
+ if got, want := dt.ID(), arrow.DURATION; got != want {
+ t.Fatalf("invalid type ID: got=%v, want=%v",
got, want)
+ }
+
+ if got, want := dt.String(), tc.want; got != want {
+ t.Fatalf("invalid type stringer: got=%q,
want=%q", got, want)
+ }
+ })
+ }
+}
+
+func TestBooleanType(t *testing.T) {
+ dt := arrow.BooleanType{}
+ if got, want := dt.BitWidth(), 1; got != want {
+ t.Fatalf("invalid bitwidth: got=%d, want=%d", got, want)
+ }
+
+ if got, want := dt.Name(), "bool"; got != want {
+ t.Fatalf("invalid type name: got=%q, want=%q", got, want)
+ }
+
+ if got, want := dt.ID(), arrow.BOOL; got != want {
+ t.Fatalf("invalid type ID: got=%v, want=%v", got, want)
+ }
+
+ if got, want := dt.String(), "bool"; got != want {
+ t.Fatalf("invalid type stringer: got=%q, want=%q", got, want)
+ }
+}
+
+func TestFloat16Type(t *testing.T) {
+ dt := arrow.Float16Type{}
+ if got, want := dt.BitWidth(), 16; got != want {
+ t.Fatalf("invalid bitwidth: got=%d, want=%d", got, want)
+ }
+
+ if got, want := dt.Name(), "float16"; got != want {
+ t.Fatalf("invalid type name: got=%q, want=%q", got, want)
+ }
+
+ if got, want := dt.ID(), arrow.FLOAT16; got != want {
+ t.Fatalf("invalid type ID: got=%v, want=%v", got, want)
+ }
+
+ if got, want := dt.String(), "float16"; got != want {
+ t.Fatalf("invalid type stringer: got=%q, want=%q", got, want)
+ }
+}
+
+func TestDayTimeIntervalType(t *testing.T) {
+ dt := arrow.DayTimeIntervalType{}
+ if got, want := dt.BitWidth(), 64; got != want {
+ t.Fatalf("invalid bitwidth: got=%d, want=%d", got, want)
+ }
+
+ if got, want := dt.Name(), "day_time_interval"; got != want {
+ t.Fatalf("invalid type name: got=%q, want=%q", got, want)
+ }
+
+ if got, want := dt.ID(), arrow.INTERVAL; got != want {
+ t.Fatalf("invalid type ID: got=%v, want=%v", got, want)
+ }
+
+ if got, want := dt.String(), "day_time_interval"; got != want {
+ t.Fatalf("invalid type stringer: got=%q, want=%q", got, want)
+ }
+}
+
+func TestMonthIntervalType(t *testing.T) {
+ dt := arrow.MonthIntervalType{}
+ if got, want := dt.BitWidth(), 32; got != want {
+ t.Fatalf("invalid bitwidth: got=%d, want=%d", got, want)
+ }
+
+ if got, want := dt.Name(), "month_interval"; got != want {
+ t.Fatalf("invalid type name: got=%q, want=%q", got, want)
+ }
+
+ if got, want := dt.ID(), arrow.INTERVAL; got != want {
+ t.Fatalf("invalid type ID: got=%v, want=%v", got, want)
+ }
+
+ if got, want := dt.String(), "month_interval"; got != want {
+ t.Fatalf("invalid type stringer: got=%q, want=%q", got, want)
+ }
+}
diff --git a/go/arrow/datatype_null_test.go b/go/arrow/datatype_null_test.go
index e773cc4..1549ac3 100644
--- a/go/arrow/datatype_null_test.go
+++ b/go/arrow/datatype_null_test.go
@@ -31,4 +31,8 @@ func TestNullType(t *testing.T) {
if got, want := nt.Name(), "null"; got != want {
t.Fatalf("invalid null type name. got=%q, want=%q", got, want)
}
+
+ if got, want := nt.String(), "null"; got != want {
+ t.Fatalf("invalid null type stringer. got=%q, want=%q", got,
want)
+ }
}
diff --git a/go/arrow/schema_test.go b/go/arrow/schema_test.go
index a37b94c..31f8739 100644
--- a/go/arrow/schema_test.go
+++ b/go/arrow/schema_test.go
@@ -28,24 +28,28 @@ func TestMetadata(t *testing.T) {
kvs map[string]string
keys, values []string
err string
+ serialize string
}{
{
md: Metadata{
keys: []string{"k1", "k2"},
values: []string{"v1", "v2"},
},
- keys: []string{"k1", "k2"},
- values: []string{"v1", "v2"},
+ keys: []string{"k1", "k2"},
+ values: []string{"v1", "v2"},
+ serialize: `["k1": "v1", "k2": "v2"]`,
},
{
- md: Metadata{},
+ md: Metadata{},
+ serialize: "[]",
},
{
md: Metadata{
keys: []string{"k1", "k2"},
values: []string{"v1", "v2"},
},
- kvs: map[string]string{"k1": "v1", "k2": "v2"},
+ kvs: map[string]string{"k1": "v1", "k2": "v2"},
+ serialize: `["k1": "v1", "k2": "v2"]`,
},
{
md: Metadata{},
@@ -89,6 +93,10 @@ func TestMetadata(t *testing.T) {
if !reflect.DeepEqual(clone, md) {
t.Fatalf("invalid clone: got=%#v, want=%#v",
clone, md)
}
+
+ if got, want := tc.md.String(), tc.serialize; got !=
want {
+ t.Fatalf("invalid stringer: got=%q, want=%q",
got, want)
+ }
})
}
@@ -123,9 +131,10 @@ func TestMetadata(t *testing.T) {
func TestSchema(t *testing.T) {
for _, tc := range []struct {
- fields []Field
- md *Metadata
- err error
+ fields []Field
+ md *Metadata
+ err error
+ serialize string
}{
{
fields: []Field{
@@ -136,6 +145,11 @@ func TestSchema(t *testing.T) {
md := MetadataFrom(map[string]string{"k1":
"v1", "k2": "v2"})
return &md
}(),
+ serialize: `schema:
+ fields: 2
+ - f1: type=int32
+ - f2: type=int64
+ metadata: ["k1": "v1", "k2": "v2"]`,
},
{
fields: []Field{
@@ -143,6 +157,10 @@ func TestSchema(t *testing.T) {
{Name: "f2", Type: PrimitiveTypes.Int64},
},
md: nil,
+ serialize: `schema:
+ fields: 2
+ - f1: type=int32
+ - f2: type=int64`,
},
{
fields: []Field{
@@ -160,6 +178,12 @@ func TestSchema(t *testing.T) {
{Name: "dup", Type: PrimitiveTypes.Int64}, //
duplicate
},
md: nil,
+ serialize: `schema:
+ fields: 4
+ - f1: type=int32
+ - f2: type=int64
+ - dup: type=int32
+ - dup: type=int64`,
},
} {
t.Run("", func(t *testing.T) {
@@ -240,6 +264,10 @@ func TestSchema(t *testing.T) {
t.Fatalf("invalid duplicate fields:
got=%v, want=%v", got, want)
}
}
+
+ if got, want := s.String(), tc.serialize; got != want {
+ t.Fatalf("invalid stringer: got=%q, want=%q",
got, want)
+ }
})
}
}
@@ -264,6 +292,16 @@ func TestSchemaEqual(t *testing.T) {
want: true,
},
{
+ a: nil,
+ b: NewSchema(nil, nil),
+ want: false,
+ },
+ {
+ a: NewSchema(nil, nil),
+ b: nil,
+ want: false,
+ },
+ {
a: NewSchema(nil, nil),
b: NewSchema(nil, nil),
want: true,