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

[mysql,postgres] Change Debezium conversion for timestamp types #317

Merged
merged 3 commits into from
Mar 28, 2024

Conversation

nathan-artie
Copy link
Collaborator

@nathan-artie nathan-artie commented Mar 27, 2024

Logged the schema that Debezium outputs when run against Postgres:

{
    "type": "int64",
    "optional": true,
    "name": "io.debezium.time.MicroTimestamp",
    "version": 1,
    "field": "c_timestamp_without_timezone"
},
{
    "type": "string",
    "optional": true,
    "name": "io.debezium.time.ZonedTimestamp",
    "version": 1,
    "field": "c_timestamp_with_timezone"
},

And the data:

"c_timestamp_without_timezone": 982355920000000,
"c_timestamp_with_timezone": "2001-02-16T13:38:40.000000Z",

This changes the converters used for MySQL and Postgres to be in line with what Debezium does:

return timeValue.UnixMicro(), nil
}

type ZonedTimestampConverter struct{}
Copy link
Collaborator Author

@nathan-artie nathan-artie Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically renamed ZonedTimestampConverter to TimestampConverter and updated the DebeziumType appropriately.

@@ -67,18 +67,37 @@ func (DateConverter) Convert(value any) (any, error) {
return int32(timeValue.Unix() / (60 * 60 * 24)), nil
}

type TimestampConverter struct{}
type MicroTimestampConverter struct{}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new MicroTimestampConverter.

_, err := converter.Convert(1234)
assert.ErrorContains(t, err, "expected time.Time got int with value: 1234")
}
{
Copy link
Collaborator Author

@nathan-artie nathan-artie Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to worry about dates > 9999 or < 0 for MicroTimestamps since it uses an int64 and won't have JSON encoding issues.

@nathan-artie nathan-artie requested a review from Tang8330 March 27, 2024 22:57
@nathan-artie nathan-artie marked this pull request as ready for review March 27, 2024 22:57
}
{
// Date < 0
value, err := converter.Convert(time.Date(-1, 2, 3, 4, 5, 0, 0, time.UTC))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these tests, can we have it also run against Transfer to ensure Transfer is able to parse it correctly?

Like run it against this function: https://github.com/artie-labs/transfer/blob/52a52c9cbe92e506c7d4a24757440979d28ef8a8/lib/debezium/types.go#L72

Copy link
Collaborator

@Tang8330 Tang8330 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@nathan-artie nathan-artie merged commit eb117e4 into master Mar 28, 2024
3 checks passed
@nathan-artie nathan-artie deleted the nv/change-dbz-timestamp-conversion branch March 28, 2024 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants