-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ui/remove-pub-load-check
- Loading branch information
Showing
6 changed files
with
94 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package shared | ||
|
||
import ( | ||
"log/slog" | ||
"slices" | ||
|
||
"go.temporal.io/sdk/log" | ||
"golang.org/x/exp/maps" | ||
|
||
"github.com/PeerDB-io/peer-flow/generated/protos" | ||
) | ||
|
||
func AdditionalTablesHasOverlap(currentTableMappings []*protos.TableMapping, | ||
additionalTableMappings []*protos.TableMapping, | ||
) bool { | ||
currentSrcTables := make([]string, 0, len(currentTableMappings)) | ||
currentDstTables := make([]string, 0, len(currentTableMappings)) | ||
additionalSrcTables := make([]string, 0, len(additionalTableMappings)) | ||
additionalDstTables := make([]string, 0, len(additionalTableMappings)) | ||
|
||
for _, currentTableMapping := range currentTableMappings { | ||
currentSrcTables = append(currentSrcTables, currentTableMapping.SourceTableIdentifier) | ||
currentDstTables = append(currentDstTables, currentTableMapping.DestinationTableIdentifier) | ||
} | ||
for _, additionalTableMapping := range additionalTableMappings { | ||
additionalSrcTables = append(additionalSrcTables, additionalTableMapping.SourceTableIdentifier) | ||
additionalDstTables = append(additionalDstTables, additionalTableMapping.DestinationTableIdentifier) | ||
} | ||
|
||
return ArraysHaveOverlap(currentSrcTables, additionalSrcTables) || | ||
ArraysHaveOverlap(currentDstTables, additionalDstTables) | ||
} | ||
|
||
// given the output of GetTableSchema, processes it to be used by CDCFlow | ||
// 1) changes the map key to be the destination table name instead of the source table name | ||
// 2) performs column exclusion using protos.TableMapping as input. | ||
func BuildProcessedSchemaMapping(tableMappings []*protos.TableMapping, | ||
tableNameSchemaMapping map[string]*protos.TableSchema, | ||
logger log.Logger, | ||
) map[string]*protos.TableSchema { | ||
processedSchemaMapping := make(map[string]*protos.TableSchema) | ||
sortedSourceTables := maps.Keys(tableNameSchemaMapping) | ||
slices.Sort(sortedSourceTables) | ||
|
||
for _, srcTableName := range sortedSourceTables { | ||
tableSchema := tableNameSchemaMapping[srcTableName] | ||
var dstTableName string | ||
for _, mapping := range tableMappings { | ||
if mapping.SourceTableIdentifier == srcTableName { | ||
dstTableName = mapping.DestinationTableIdentifier | ||
if len(mapping.Exclude) != 0 { | ||
columnCount := len(tableSchema.Columns) | ||
columns := make([]*protos.FieldDescription, 0, columnCount) | ||
for _, column := range tableSchema.Columns { | ||
if !slices.Contains(mapping.Exclude, column.Name) { | ||
columns = append(columns, column) | ||
} | ||
} | ||
tableSchema = &protos.TableSchema{ | ||
TableIdentifier: tableSchema.TableIdentifier, | ||
PrimaryKeyColumns: tableSchema.PrimaryKeyColumns, | ||
IsReplicaIdentityFull: tableSchema.IsReplicaIdentityFull, | ||
Columns: columns, | ||
} | ||
} | ||
break | ||
} | ||
} | ||
processedSchemaMapping[dstTableName] = tableSchema | ||
|
||
logger.Info("normalized table schema", | ||
slog.String("table", dstTableName), | ||
slog.Any("schema", tableSchema)) | ||
} | ||
return processedSchemaMapping | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters