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

[WIP] Support primary key overrides #923

Draft
wants to merge 3 commits into
base: master
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
1 change: 0 additions & 1 deletion lib/debezium/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func ParsePartitionKey(key []byte, cdcKeyFormat string) (map[string]any, error)
return parsePartitionKeyStruct(key)
case kafkalib.StringKeyFmt:
return parsePartitionKeyString(key)

}
return nil, fmt.Errorf("format: %s is not supported", cdcKeyFormat)
}
Expand Down
18 changes: 18 additions & 0 deletions processes/consumer/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ func (p processArgs) process(ctx context.Context, cfg config.Config, inMemDB *mo
return "", fmt.Errorf("cannot unmarshall event: %w", err)
}

if len(topicConfig.tc.PrimaryKeysOverride) > 0 {
data, err := _event.GetData(map[string]any{}, topicConfig.tc)
if err != nil {
tags["what"] = "get_data_err"
return "", fmt.Errorf("failed to get data: %w", err)
}

for _, primaryKey := range topicConfig.tc.PrimaryKeysOverride {
value, isOk := data[primaryKey]
if !isOk {
tags["what"] = "missing_pk"
return "", fmt.Errorf("missing primary key: %q", primaryKey)
}

pkMap[primaryKey] = value
}
}

tags["op"] = _event.Operation()
evt, err := event.ToMemoryEvent(_event, pkMap, topicConfig.tc, cfg.Mode)
if err != nil {
Expand Down