Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize setup flow for table addition #2141

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion flow/activities/flowable.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ func (a *FlowableActivity) CreateNormalizedTable(
defer shutdown()

tableExistsMapping := make(map[string]bool, len(tableNameSchemaMapping))
for tableIdentifier, tableSchema := range tableNameSchemaMapping {
for _, tableMapping := range config.TableMappings {
tableIdentifier := tableMapping.DestinationTableIdentifier
tableSchema := tableNameSchemaMapping[tableMapping.DestinationTableIdentifier]
existing, err := conn.SetupNormalizedTable(
ctx,
tx,
Expand Down
12 changes: 6 additions & 6 deletions flow/connectors/clickhouse/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ func (c *ClickHouseConnector) SetupNormalizedTable(
ctx context.Context,
tx interface{},
config *protos.SetupNormalizedTableBatchInput,
tableIdentifier string,
tableSchema *protos.TableSchema,
destinationTableIdentifier string,
sourceTableSchema *protos.TableSchema,
) (bool, error) {
tableAlreadyExists, err := c.checkIfTableExists(ctx, c.config.Database, tableIdentifier)
tableAlreadyExists, err := c.checkIfTableExists(ctx, c.config.Database, destinationTableIdentifier)
if err != nil {
return false, fmt.Errorf("error occurred while checking if normalized table exists: %w", err)
}
if tableAlreadyExists && !config.IsResync {
c.logger.Info("[ch] normalized table already exists, skipping", "table", tableIdentifier)
c.logger.Info("[ch] normalized table already exists, skipping", "table", destinationTableIdentifier)
return true, nil
}

normalizedTableCreateSQL, err := generateCreateTableSQLForNormalizedTable(
config,
tableIdentifier,
tableSchema,
destinationTableIdentifier,
sourceTableSchema,
)
if err != nil {
return false, fmt.Errorf("error while generating create table sql for normalized table: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions flow/connectors/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ type NormalizedTablesConnector interface {
ctx context.Context,
tx any,
config *protos.SetupNormalizedTableBatchInput,
tableIdentifier string,
tableSchema *protos.TableSchema,
destinationTableIdentifier string,
sourceTableSchema *protos.TableSchema,
) (bool, error)
}

Expand Down
Loading