Skip to content

Commit

Permalink
Support column hashing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 19, 2024
1 parent bf79e25 commit cbffa14
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
3 changes: 1 addition & 2 deletions models/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import (
"strings"
"time"

"github.com/artie-labs/transfer/lib/cryptography"

"github.com/artie-labs/transfer/lib/artie"
"github.com/artie-labs/transfer/lib/cdc"
"github.com/artie-labs/transfer/lib/config"
"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/cryptography"
"github.com/artie-labs/transfer/lib/kafkalib"
"github.com/artie-labs/transfer/lib/optimization"
"github.com/artie-labs/transfer/lib/stringutil"
Expand Down
61 changes: 54 additions & 7 deletions models/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ var idMap = map[string]any{

func (e *EventsTestSuite) TestEvent_IsValid() {
{
_evt := Event{
Table: "foo",
}
_evt := Event{Table: "foo"}
assert.False(e.T(), _evt.IsValid())
}
{
_evt := Event{
Table: "foo",
PrimaryKeyMap: idMap,
}
_evt := Event{Table: "foo", PrimaryKeyMap: idMap}
assert.False(e.T(), _evt.IsValid())
}
{
Expand Down Expand Up @@ -57,6 +52,58 @@ func (e *EventsTestSuite) TestEvent_IsValid() {
}
}

func (e *EventsTestSuite) TestEvent_HashData() {
{
// No columns to hash
event := Event{
Data: map[string]any{
"foo": "bar",
"abc": "def",
},
}

event.hashData(kafkalib.TopicConfig{})
assert.Equal(e.T(), map[string]any{"foo": "bar", "abc": "def"}, event.Data)
}
{
// There's a column to hash, but the event does not have any data
event := Event{
Data: map[string]any{
"foo": "bar",
"abc": "def",
},
}

event.hashData(kafkalib.TopicConfig{ColumnsToHash: []string{"super duper"}})
assert.Equal(e.T(), map[string]any{"foo": "bar", "abc": "def"}, event.Data)
}
{
// Hash the column foo (value is set)
event := Event{
Data: map[string]any{
"foo": "bar",
"abc": "def",
},
}

event.hashData(kafkalib.TopicConfig{ColumnsToHash: []string{"foo"}})
assert.Equal(e.T(), map[string]any{"foo": "fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9", "abc": "def"}, event.Data)
}
{
// Hash the column foo (value is nil)
event := Event{
Data: map[string]any{
"foo": nil,
"abc": "def",
},
}

event.hashData(kafkalib.TopicConfig{ColumnsToHash: []string{"foo"}})
assert.Equal(e.T(), map[string]any{"foo": nil, "abc": "def"}, event.Data)
}

}

func (e *EventsTestSuite) TestEvent_TableName() {
{
// Don't pass in tableName.
Expand Down

0 comments on commit cbffa14

Please sign in to comment.