Skip to content

Commit

Permalink
Merge branch 'master' into refactor-storage-writer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 authored Aug 27, 2024
2 parents 43f9aef + 95cd7fe commit 98a8cc2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
3 changes: 1 addition & 2 deletions clients/shared/default_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ func BackfillColumn(dwh destination.DataWarehouse, column columns.Column, tableI
slog.String("table", tableID.FullyQualifiedName()),
)

_, err = dwh.Exec(query)
if err != nil {
if _, err = dwh.Exec(query); err != nil {
return fmt.Errorf("failed to backfill, err: %w, query: %v", err, query)
}

Expand Down
18 changes: 18 additions & 0 deletions lib/debezium/converters/string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package converters

import "github.com/artie-labs/transfer/lib/typing"

type StringPassthrough struct{}

func (StringPassthrough) Convert(value any) (any, error) {
castedValue, err := typing.AssertType[string](value)
if err != nil {
return nil, err
}

return castedValue, nil
}

func (StringPassthrough) ToKindDetails() typing.KindDetails {
return typing.String
}
21 changes: 21 additions & 0 deletions lib/debezium/converters/string_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package converters

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestStringPassthrough_Convert(t *testing.T) {
{
// Non string
_, err := StringPassthrough{}.Convert(1)
assert.ErrorContains(t, err, "expected type string, got int")
}
{
// String
value, err := StringPassthrough{}.Convert("test")
assert.Nil(t, err)
assert.Equal(t, "test", value)
}
}
2 changes: 2 additions & 0 deletions lib/debezium/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func (f Field) GetScaleAndPrecision() (int32, *int32, error) {

func (f Field) ToValueConverter() converters.ValueConverter {
switch f.DebeziumType {
case UUID:
return converters.StringPassthrough{}
case DateTimeWithTimezone:
return converters.DateTimeWithTimezone{}
case TimeWithTimezone:
Expand Down
5 changes: 5 additions & 0 deletions lib/debezium/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ func TestField_ToKindDetails(t *testing.T) {
},
expectedKindDetails: typing.Struct,
},
{
name: "UUID",
field: Field{DebeziumType: UUID, Type: String},
expectedKindDetails: typing.String,
},
}

for _, tc := range tcs {
Expand Down

0 comments on commit 98a8cc2

Please sign in to comment.