Skip to content

Commit

Permalink
Update rowData arg in tests; remove empty check
Browse files Browse the repository at this point in the history
  • Loading branch information
danafallon committed Jun 25, 2024
1 parent 4caf734 commit ab8aabe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
5 changes: 1 addition & 4 deletions lib/optimization/table_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,8 @@ func (t *TableData) InsertRow(pk string, rowData map[string]any, delete bool) {
if isOk {
prevRowSize = size.GetApproxSize(prevRow)
if delete {
// If the row was deleted, preserve the previous values if we have them in memory
// If the row was deleted, preserve the previous values that we have in memory
rowData = prevRow
if len(rowData) == 0 {
rowData = map[string]any{}
}
rowData[constants.DeleteColumnMarker] = true
} else {
for key, val := range rowData {
Expand Down
18 changes: 10 additions & 8 deletions lib/optimization/table_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/typing/columns"

"github.com/artie-labs/transfer/lib/config"
Expand Down Expand Up @@ -208,7 +209,7 @@ func TestTableData_ContainsHardDeletes(t *testing.T) {
td := NewTableData(nil, config.Replication, nil, kafkalib.TopicConfig{}, "foo")
assert.Equal(t, 0, int(td.NumberOfRows()))

td.InsertRow("123", nil, true)
td.InsertRow("123", map[string]any{"id": "123"}, true)
assert.Equal(t, 1, int(td.NumberOfRows()))

assert.True(t, td.ContainsHardDeletes())
Expand All @@ -218,7 +219,7 @@ func TestTableData_ContainsHardDeletes(t *testing.T) {
td := NewTableData(nil, config.Replication, nil, kafkalib.TopicConfig{SoftDelete: true}, "foo")
assert.Equal(t, 0, int(td.NumberOfRows()))

td.InsertRow("123", nil, true)
td.InsertRow("123", map[string]any{"id": "123"}, true)
assert.Equal(t, 1, int(td.NumberOfRows()))
assert.False(t, td.ContainsHardDeletes())
}
Expand Down Expand Up @@ -270,12 +271,12 @@ func TestTableData_InsertRowIntegrity(t *testing.T) {
assert.False(t, td.ContainOtherOperations())

for i := 0; i < 100; i++ {
td.InsertRow("123", nil, true)
td.InsertRow("123", map[string]any{"id": "123"}, true)
assert.False(t, td.ContainOtherOperations())
}

for i := 0; i < 100; i++ {
td.InsertRow("123", nil, false)
td.InsertRow("123", map[string]any{"id": "123"}, false)
assert.True(t, td.ContainOtherOperations())
}
}
Expand All @@ -284,16 +285,17 @@ func TestTableData_InsertRowSoftDelete(t *testing.T) {
td := NewTableData(nil, config.Replication, nil, kafkalib.TopicConfig{SoftDelete: true}, "foo")
assert.Equal(t, 0, int(td.NumberOfRows()))

td.InsertRow("123", map[string]any{"name": "dana"}, false)
td.InsertRow("123", map[string]any{"id": "123", "name": "dana"}, false)
assert.Equal(t, 1, int(td.NumberOfRows()))
assert.Equal(t, "dana", td.Rows()[0]["name"])

td.InsertRow("123", map[string]any{"name": "dana2"}, false)
td.InsertRow("123", map[string]any{"id": "123", "name": "dana2"}, false)
assert.Equal(t, 1, int(td.NumberOfRows()))
assert.Equal(t, "dana2", td.Rows()[0]["name"])

td.InsertRow("123", map[string]any{}, true)
td.InsertRow("123", map[string]any{"id": "123", constants.DeleteColumnMarker: true}, true)
assert.Equal(t, 1, int(td.NumberOfRows()))
// The previous value should be preserved
// The previous value should be preserved, along with the delete marker
assert.Equal(t, "dana2", td.Rows()[0]["name"])
assert.Equal(t, true, td.Rows()[0][constants.DeleteColumnMarker])
}

0 comments on commit ab8aabe

Please sign in to comment.