Skip to content

Commit

Permalink
Remove more usages of columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Nov 15, 2024
1 parent 02ccba7 commit f8a0f58
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions clients/shared/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Append(ctx context.Context, dwh destination.DataWarehouse, tableData *optim
// We don't care about srcKeysMissing because we don't drop columns when we append.
_, targetKeysMissing := columns.Diff(
tableData.ReadOnlyInMemoryCols().GetColumns(),
tableConfig.Columns().GetColumns(),
tableConfig.GetColumns(),
tableData.TopicConfig().SoftDelete,
tableData.TopicConfig().IncludeArtieUpdatedAt,
tableData.TopicConfig().IncludeDatabaseUpdatedAt,
Expand All @@ -48,7 +48,7 @@ func Append(ctx context.Context, dwh destination.DataWarehouse, tableData *optim
return fmt.Errorf("failed to alter table: %w", err)
}

if err = tableData.MergeColumnsFromDestination(tableConfig.Columns().GetColumns()...); err != nil {
if err = tableData.MergeColumnsFromDestination(tableConfig.GetColumns()...); err != nil {
return fmt.Errorf("failed to merge columns from destination: %w", err)
}

Expand Down
4 changes: 2 additions & 2 deletions clients/shared/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Merge(ctx context.Context, dwh destination.DataWarehouse, tableData *optimi

srcKeysMissing, targetKeysMissing := columns.Diff(
tableData.ReadOnlyInMemoryCols().GetColumns(),
tableConfig.Columns().GetColumns(),
tableConfig.GetColumns(),
tableData.TopicConfig().SoftDelete,
tableData.TopicConfig().IncludeArtieUpdatedAt,
tableData.TopicConfig().IncludeDatabaseUpdatedAt,
Expand Down Expand Up @@ -70,7 +70,7 @@ func Merge(ctx context.Context, dwh destination.DataWarehouse, tableData *optimi
}

tableConfig.AuditColumnsToDelete(srcKeysMissing)
if err = tableData.MergeColumnsFromDestination(tableConfig.Columns().GetColumns()...); err != nil {
if err = tableData.MergeColumnsFromDestination(tableConfig.GetColumns()...); err != nil {
return fmt.Errorf("failed to merge columns from destination: %w", err)
}

Expand Down
7 changes: 7 additions & 0 deletions lib/destination/types/table_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func (d *DwhTableConfig) DropDeletedColumns() bool {
return d.dropDeletedColumns
}

func (d *DwhTableConfig) GetColumns() []columns.Column {
d.RLock()
defer d.RUnlock()

return d.columns.GetColumns()
}

func (d *DwhTableConfig) Columns() *columns.Columns {
if d == nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions lib/destination/types/table_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestDwhTableConfig_MutateInMemoryColumns(t *testing.T) {
tc.MutateInMemoryColumns(false, constants.Add, columns.NewColumn(col, typing.String))
}

assert.Len(t, tc.Columns().GetColumns(), 5)
assert.Len(t, tc.GetColumns(), 5)
var wg sync.WaitGroup
for _, addCol := range []string{"aa", "bb", "cc", "dd", "ee", "ff"} {
wg.Add(1)
Expand All @@ -104,7 +104,7 @@ func TestDwhTableConfig_MutateInMemoryColumns(t *testing.T) {
}

wg.Wait()
assert.Len(t, tc.Columns().GetColumns(), 6)
assert.Len(t, tc.GetColumns(), 6)
}

func TestDwhTableConfig_ReadOnlyColumnsToDelete(t *testing.T) {
Expand Down

0 comments on commit f8a0f58

Please sign in to comment.