Skip to content

Commit

Permalink
Remove createTable as an arg (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 authored Nov 15, 2024
1 parent 9e9d904 commit 8da8b57
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion clients/shared/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func Append(ctx context.Context, dwh destination.DataWarehouse, tableData *optim
)

tableID := dwh.IdentifierFor(tableData.TopicConfig(), tableData.Name())

if tableConfig.CreateTable() {
if err = CreateTable(ctx, dwh, tableData, tableConfig, tableID, false); err != nil {
return fmt.Errorf("failed to create table: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion clients/shared/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ func CreateTable(ctx context.Context, dwh destination.DataWarehouse, tableData *
}

// Update cache with the new columns that we've added.
tc.MutateInMemoryColumns(false, constants.Add, tableData.ReadOnlyInMemoryCols().GetColumns()...)
tc.MutateInMemoryColumns(constants.Add, tableData.ReadOnlyInMemoryCols().GetColumns()...)
return nil
}
2 changes: 1 addition & 1 deletion clients/snowflake/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *SnowflakeTestSuite) TestMutateColumnsWithMemoryCacheDeletions() {
assert.Equal(s.T(), len(s.stageStore.configMap.TableConfigCache(tableID).ReadOnlyColumnsToDelete()), 1)

// Now let's try to add this column back, it should delete it from the cache.
tc.MutateInMemoryColumns(false, constants.Add, nameCol)
tc.MutateInMemoryColumns(constants.Add, nameCol)
assert.Equal(s.T(), len(s.stageStore.configMap.TableConfigCache(tableID).ReadOnlyColumnsToDelete()), 0)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/destination/ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (a AlterTableArgs) AlterTable(dwh destination.DataWarehouse, cols ...column
}

// createTable = false since it all successfully updated.
a.Tc.MutateInMemoryColumns(false, a.ColumnOp, mutateCol...)
a.Tc.MutateInMemoryColumns(a.ColumnOp, mutateCol...)

return nil
}
5 changes: 3 additions & 2 deletions lib/destination/types/table_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (d *DwhTableConfig) Columns() *columns.Columns {
return d.columns
}

func (d *DwhTableConfig) MutateInMemoryColumns(createTable bool, columnOp constants.ColumnOperation, cols ...columns.Column) {
func (d *DwhTableConfig) MutateInMemoryColumns(columnOp constants.ColumnOperation, cols ...columns.Column) {
d.Lock()
defer d.Unlock()
switch columnOp {
Expand All @@ -78,7 +78,8 @@ func (d *DwhTableConfig) MutateInMemoryColumns(createTable bool, columnOp consta
delete(d.columnsToDelete, col.Name())
}

d.createTable = createTable
// If we're adding columns, then the table should have either been created or already exists.
d.createTable = false
case constants.Delete:
for _, col := range cols {
// Delete from the permissions and in-memory table
Expand Down
6 changes: 3 additions & 3 deletions lib/destination/types/table_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestDwhTableConfig_ColumnsConcurrency(t *testing.T) {
func TestDwhTableConfig_MutateInMemoryColumns(t *testing.T) {
tc := types.NewDwhTableConfig(nil, false)
for _, col := range []string{"a", "b", "c", "d", "e"} {
tc.MutateInMemoryColumns(false, constants.Add, columns.NewColumn(col, typing.String))
tc.MutateInMemoryColumns(constants.Add, columns.NewColumn(col, typing.String))
}

assert.Len(t, tc.GetColumns(), 5)
Expand All @@ -91,15 +91,15 @@ func TestDwhTableConfig_MutateInMemoryColumns(t *testing.T) {
wg.Add(1)
go func(colName string) {
defer wg.Done()
tc.MutateInMemoryColumns(false, constants.Add, columns.NewColumn(colName, typing.String))
tc.MutateInMemoryColumns(constants.Add, columns.NewColumn(colName, typing.String))
}(addCol)
}

for _, removeCol := range []string{"a", "b", "c", "d", "e"} {
wg.Add(1)
go func(colName string) {
defer wg.Done()
tc.MutateInMemoryColumns(false, constants.Delete, columns.NewColumn(colName, typing.Invalid))
tc.MutateInMemoryColumns(constants.Delete, columns.NewColumn(colName, typing.Invalid))
}(removeCol)
}

Expand Down

0 comments on commit 8da8b57

Please sign in to comment.