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

[Debezium] Int64 Passthrough #878

Merged
merged 2 commits into from
Sep 4, 2024
Merged
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
6 changes: 3 additions & 3 deletions lib/debezium/converters/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ func (JSON) ToKindDetails() typing.KindDetails {
return typing.Struct
}

type Year struct{}
type Int64Passthrough struct{}

func (Year) ToKindDetails() typing.KindDetails {
func (Int64Passthrough) ToKindDetails() typing.KindDetails {
return typing.Integer
}

func (Year) Convert(value any) (any, error) {
func (Int64Passthrough) Convert(value any) (any, error) {
if _, err := typing.AssertType[int64](value); err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions lib/debezium/converters/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ func TestJSON_Convert(t *testing.T) {
}
}

func TestYear_Convert(t *testing.T) {
func TestInt64Passthrough_Convert(t *testing.T) {
{
// Wrong data type
_, err := Year{}.Convert("123")
_, err := Int64Passthrough{}.Convert("123")
assert.ErrorContains(t, err, "expected type int64, got string")
}
{
// Valid data type
value, err := Year{}.Convert(int64(2024))
value, err := Int64Passthrough{}.Convert(int64(2024))
assert.NoError(t, err)
assert.Equal(t, int64(2024), value)
}
Expand Down
6 changes: 4 additions & 2 deletions lib/debezium/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ func (f Field) GetScaleAndPrecision() (int32, *int32, error) {

func (f Field) ToValueConverter() converters.ValueConverter {
switch f.DebeziumType {
// Passthrough converters
case UUID, LTree, Enum:
return converters.StringPassthrough{}
case Year, MicroDuration:
return &converters.Int64Passthrough{}
case DateTimeWithTimezone:
return converters.DateTimeWithTimezone{}
case TimeWithTimezone:
Expand All @@ -97,8 +100,7 @@ func (f Field) ToValueConverter() converters.ValueConverter {
return converters.JSON{}
case Date, DateKafkaConnect:
return converters.Date{}
case Year:
return &converters.Year{}

// Time
case Time, TimeKafkaConnect:
return converters.Time{}
Expand Down
7 changes: 6 additions & 1 deletion lib/debezium/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ func TestField_ToKindDetails(t *testing.T) {
}
{
// Basic
assert.Equal(t, typing.Integer, Field{DebeziumType: Year}.ToKindDetails())
{
// Int64 Passthrough
assert.Equal(t, typing.Integer, Field{DebeziumType: Year}.ToKindDetails())
assert.Equal(t, typing.Integer, Field{DebeziumType: MicroDuration}.ToKindDetails())
}

assert.Equal(t, typing.Struct, Field{DebeziumType: JSON}.ToKindDetails())
}
}
Loading