-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathvalidators_test.go
56 lines (50 loc) · 1.42 KB
/
validators_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package schema
import (
"fmt"
"testing"
"github.com/apache/arrow-go/v18/arrow"
"github.com/apache/arrow-go/v18/arrow/array"
"github.com/apache/arrow-go/v18/arrow/memory"
"github.com/cloudquery/plugin-sdk/v4/types"
"github.com/stretchr/testify/require"
)
func TestFindEmptyColumns(t *testing.T) {
table := TestTable("test", TestSourceOptions{})
tg := NewTestDataGenerator(0)
record := tg.Generate(table, GenTestDataOptions{
MaxRows: 1,
NullRows: true,
})
v := FindEmptyColumns(table, []arrow.Record{record})
require.NotEmpty(t, v)
require.Len(t, v, len(table.Columns)-1) // exclude "id"
}
func TestFindEmptyColumnsNotEmpty(t *testing.T) {
table := TestTable("test", TestSourceOptions{})
tg := NewTestDataGenerator(0)
record := tg.Generate(table, GenTestDataOptions{
MaxRows: 1,
NullRows: false,
})
v := FindEmptyColumns(table, []arrow.Record{record})
require.Empty(t, v)
}
func TestFindEmptyColumnsJSON(t *testing.T) {
table := &Table{
Name: "test",
Columns: ColumnList{
{Name: "json", Type: types.ExtensionTypes.JSON},
},
}
sc := table.ToArrowSchema()
bldr := array.NewRecordBuilder(memory.DefaultAllocator, sc)
err := bldr.Field(0).UnmarshalJSON([]byte(`[{}]`))
if err != nil {
panic(fmt.Sprintf("failed to unmarshal json for column: %v", err))
}
records := []arrow.Record{bldr.NewRecord()}
bldr.Release()
v := FindEmptyColumns(table, records)
require.NotEmpty(t, v)
require.Len(t, v, 1)
}