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