Skip to content

Commit 99fb000

Browse files
authored
fix: Fix test column generation (#872)
There was a bug in the last implementation causing many types to be missing; it's always that final refactor you do 😄 This time I added a sanity check for the testdata generation to make sure it can't be catastrophically broken without us knowing about it.
1 parent dcce06c commit 99fb000

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

schema/testdata.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,24 +228,34 @@ func removeDuplicates(columns []Column) []Column {
228228

229229
func removeColumnsByType(columns []Column, t ...arrow.Type) []Column {
230230
var newColumns []Column
231-
for _, d := range t {
232-
for _, c := range columns {
231+
for _, c := range columns {
232+
shouldRemove := false
233+
for _, d := range t {
233234
if c.Type.ID() == d {
234-
newColumns = append(newColumns, c)
235+
shouldRemove = true
236+
break
235237
}
236238
}
239+
if !shouldRemove {
240+
newColumns = append(newColumns, c)
241+
}
237242
}
238243
return newColumns
239244
}
240245

241246
func removeColumnsByDataType(columns []Column, dt ...arrow.DataType) []Column {
242247
var newColumns []Column
243-
for _, d := range dt {
244-
for _, c := range columns {
248+
for _, c := range columns {
249+
shouldRemove := false
250+
for _, d := range dt {
245251
if arrow.TypeEqual(c.Type, d) {
246-
newColumns = append(newColumns, c)
252+
shouldRemove = true
253+
break
247254
}
248255
}
256+
if !shouldRemove {
257+
newColumns = append(newColumns, c)
258+
}
249259
}
250260
return newColumns
251261
}

schema/testdata_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package schema
2+
3+
import "testing"
4+
5+
func TestTestSourceColumns_Default(t *testing.T) {
6+
// basic sanity check for tested columns
7+
defaults := TestSourceColumns()
8+
if len(defaults) < 100 {
9+
t.Fatal("expected at least 100 columns by default")
10+
}
11+
// test some specific columns
12+
checkColumnsExist(t, defaults, []string{"int64", "date32", "timestamp_us", "string", "struct", "string_map", "string_list"})
13+
}
14+
15+
func TestTestSourceColumns_SkipAll(t *testing.T) {
16+
skipAll := ColumnList(TestSourceColumns(
17+
WithTestSourceSkipStructs(),
18+
WithTestSourceSkipMaps(),
19+
WithTestSourceSkipDates(),
20+
WithTestSourceSkipTimes(),
21+
WithTestSourceSkipTimestamps(),
22+
WithTestSourceSkipDurations(),
23+
WithTestSourceSkipIntervals(),
24+
WithTestSourceSkipLargeTypes(),
25+
))
26+
// test some specific columns
27+
checkColumnsExist(t, skipAll, []string{"int64", "timestamp_us", "string", "string_list"})
28+
checkColumnsDontExist(t, skipAll, []string{"date32", "struct", "string_map"})
29+
}
30+
31+
func checkColumnsExist(t *testing.T, list ColumnList, cols []string) {
32+
for _, col := range cols {
33+
if list.Get(col) == nil {
34+
t.Errorf("expected column %s to be present", col)
35+
}
36+
}
37+
}
38+
39+
func checkColumnsDontExist(t *testing.T, list ColumnList, cols []string) {
40+
for _, col := range cols {
41+
if list.Get(col) != nil {
42+
t.Errorf("expected no %s column", col)
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)