Skip to content

Commit

Permalink
Update more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 19, 2024
1 parent c0a45e9 commit 1a20e0e
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions lib/optimization/table_data_merge_columns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func TestTableData_UpdateInMemoryColumnsFromDestination(t *testing.T) {
{
tableDataCols := &columns.Columns{}
tableData := &TableData{inMemoryColumns: tableDataCols}

{
// In-memory column is NUMERIC and destination column is an INTEGER
tableDataCols.AddColumn(columns.NewColumn("numeric_test", typing.EDecimal))
Expand All @@ -52,9 +51,39 @@ func TestTableData_UpdateInMemoryColumnsFromDestination(t *testing.T) {
assert.True(t, isOk)
assert.Equal(t, typing.Integer.Kind, numericCol.KindDetails.Kind)
}
{
// Boolean column that has been backfilled
tableDataCols.AddColumn(columns.NewColumn("bool_backfill", typing.Boolean))
backfilledCol := columns.NewColumn("bool_backfill", typing.Boolean)
backfilledCol.SetBackfilled(true)

// Backfill was not set
column, isOk := tableData.inMemoryColumns.GetColumn("bool_backfill")
assert.True(t, isOk)
assert.False(t, column.Backfilled())

assert.NoError(t, tableData.MergeColumnsFromDestination(backfilledCol))
// Backfill is set after merge.
column, isOk = tableData.inMemoryColumns.GetColumn("bool_backfill")
assert.True(t, isOk)
assert.True(t, column.Backfilled())
}
{
// Non-existent columns should not be copied over.
nonExistentTableCols := []string{"dusty", "the", "mini", "aussie"}
var nonExistentCols []columns.Column
for _, nonExistentTableCol := range nonExistentTableCols {
nonExistentCols = append(nonExistentCols, columns.NewColumn(nonExistentTableCol, typing.String))
}

assert.NoError(t, tableData.MergeColumnsFromDestination(nonExistentCols...))
for _, nonExistentTableCol := range nonExistentTableCols {
_, isOk := tableData.inMemoryColumns.GetColumn(nonExistentTableCol)
assert.False(t, isOk, nonExistentTableCol)
}
}

tableDataCols.AddColumn(columns.NewColumn("name", typing.String))
tableDataCols.AddColumn(columns.NewColumn("bool_backfill", typing.Boolean))
tableDataCols.AddColumn(columns.NewColumn("prev_invalid", typing.Invalid))

// Casting these as STRING so tableColumn via this f(x) will set it correctly.
Expand All @@ -65,43 +94,14 @@ func TestTableData_UpdateInMemoryColumnsFromDestination(t *testing.T) {

extDecimalType := typing.NewDecimalDetailsFromTemplate(typing.EDecimal, decimal.NewDetails(22, 2))
tableDataCols.AddColumn(columns.NewColumn("ext_dec_filled", extDecimalType))

tableDataCols.AddColumn(columns.NewColumn(strCol, typing.String))

nonExistentTableCols := []string{"dusty", "the", "mini", "aussie"}
var nonExistentCols []columns.Column
for _, nonExistentTableCol := range nonExistentTableCols {
nonExistentCols = append(nonExistentCols, columns.NewColumn(nonExistentTableCol, typing.String))
}

// Testing to make sure we don't copy over non-existent columns
assert.NoError(t, tableData.MergeColumnsFromDestination(nonExistentCols...))
for _, nonExistentTableCol := range nonExistentTableCols {
_, isOk := tableData.inMemoryColumns.GetColumn(nonExistentTableCol)
assert.False(t, isOk, nonExistentTableCol)
}

// Testing to make sure we're copying the kindDetails over.
assert.NoError(t, tableData.MergeColumnsFromDestination(columns.NewColumn("prev_invalid", typing.String)))
prevInvalidCol, isOk := tableData.inMemoryColumns.GetColumn("prev_invalid")
assert.True(t, isOk)
assert.Equal(t, typing.String, prevInvalidCol.KindDetails)

// Testing backfill
for _, inMemoryCol := range tableData.inMemoryColumns.GetColumns() {
assert.False(t, inMemoryCol.Backfilled(), inMemoryCol.Name())
}
backfilledCol := columns.NewColumn("bool_backfill", typing.Boolean)
backfilledCol.SetBackfilled(true)
assert.NoError(t, tableData.MergeColumnsFromDestination(backfilledCol))
for _, inMemoryCol := range tableData.inMemoryColumns.GetColumns() {
if inMemoryCol.Name() == backfilledCol.Name() {
assert.True(t, inMemoryCol.Backfilled(), inMemoryCol.Name())
} else {
assert.False(t, inMemoryCol.Backfilled(), inMemoryCol.Name())
}
}

// Testing extTimeDetails
for _, extTimeDetailsCol := range []string{"ext_date", "ext_time", "ext_datetime"} {
col, isOk := tableData.inMemoryColumns.GetColumn(extTimeDetailsCol)
Expand Down

0 comments on commit 1a20e0e

Please sign in to comment.