-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create table fast follow + enabling MySQL (#564)
- Loading branch information
Showing
6 changed files
with
105 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package transfer | ||
|
||
import ( | ||
"fmt" | ||
"github.com/artie-labs/transfer/lib/typing" | ||
"github.com/artie-labs/transfer/lib/typing/columns" | ||
|
||
"github.com/artie-labs/reader/lib/debezium/transformer" | ||
) | ||
|
||
type Adapter interface { | ||
FieldConverters() []transformer.FieldConverter | ||
PartitionKeys() []string | ||
} | ||
|
||
func BuildTransferColumns(adapter Adapter) ([]columns.Column, error) { | ||
var cols columns.Columns | ||
for _, fc := range adapter.FieldConverters() { | ||
kd, err := fc.ValueConverter.ToField(fc.Name).ToKindDetails() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to convert field %q to kind details: %w", fc.Name, err) | ||
} | ||
|
||
cols.AddColumn(columns.NewColumn(fc.Name, kd)) | ||
} | ||
|
||
for _, pk := range adapter.PartitionKeys() { | ||
err := cols.UpsertColumn(pk, columns.UpsertColumnArg{ | ||
PrimaryKey: typing.ToPtr(true), | ||
}) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("failed to upsert primary key column %q: %w", pk, err) | ||
} | ||
} | ||
|
||
return cols.GetColumns(), nil | ||
} |
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,52 @@ | ||
package transfer | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/artie-labs/transfer/lib/typing" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/artie-labs/reader/lib/debezium/converters" | ||
"github.com/artie-labs/reader/lib/debezium/transformer" | ||
) | ||
|
||
type mockAdapter struct { | ||
fieldConverters []transformer.FieldConverter | ||
partitionKeys []string | ||
} | ||
|
||
func (m mockAdapter) FieldConverters() []transformer.FieldConverter { | ||
return m.fieldConverters | ||
} | ||
|
||
func (m mockAdapter) PartitionKeys() []string { | ||
return m.partitionKeys | ||
} | ||
|
||
func TestBuildTransferColumns(t *testing.T) { | ||
adapter := mockAdapter{ | ||
partitionKeys: []string{"id"}, | ||
fieldConverters: []transformer.FieldConverter{ | ||
{ | ||
Name: "id", | ||
ValueConverter: converters.StringPassthrough{}, | ||
}, | ||
{ | ||
Name: "name", | ||
ValueConverter: converters.StringPassthrough{}, | ||
}, | ||
}, | ||
} | ||
|
||
cols, err := BuildTransferColumns(adapter) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, 2, len(cols)) | ||
assert.Equal(t, "id", cols[0].Name()) | ||
assert.Equal(t, typing.String, cols[0].KindDetails) | ||
assert.True(t, cols[0].PrimaryKey()) | ||
|
||
assert.Equal(t, "name", cols[1].Name()) | ||
assert.Equal(t, typing.String, cols[1].KindDetails) | ||
assert.False(t, cols[1].PrimaryKey()) | ||
} |
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 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