From 8b1ee04fac9fe2876e838f3d27953796a6062cfd Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 12 Dec 2024 13:02:27 -0800 Subject: [PATCH] TOAST. --- clients/snowflake/dialect/dialect.go | 9 ++++++--- lib/sql/tests/columns_test.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/clients/snowflake/dialect/dialect.go b/clients/snowflake/dialect/dialect.go index 811bb7d5..ad8e17b6 100644 --- a/clients/snowflake/dialect/dialect.go +++ b/clients/snowflake/dialect/dialect.go @@ -37,11 +37,14 @@ func (SnowflakeDialect) IsTableDoesNotExistErr(err error) bool { } func (sd SnowflakeDialect) BuildIsNotToastValueExpression(tableAlias constants.TableAlias, column columns.Column) string { + toastedValue := "%" + constants.ToastUnavailableValuePlaceholder + "%" colName := sql.QuoteTableAliasColumn(tableAlias, column, sd) - if column.KindDetails == typing.Struct { - return fmt.Sprintf("COALESCE(%s != {'key': '%s'}, true)", colName, constants.ToastUnavailableValuePlaceholder) + switch column.KindDetails { + case typing.String: + return fmt.Sprintf("COALESCE(%s NOT LIKE '%s', TRUE)", colName, toastedValue) + default: + return fmt.Sprintf("COALESCE(TO_VARCHAR(%s) NOT LIKE '%s', TRUE)", colName, toastedValue) } - return fmt.Sprintf("COALESCE(%s != '%s', true)", colName, constants.ToastUnavailableValuePlaceholder) } func (SnowflakeDialect) BuildDedupeTableQuery(tableID sql.TableIdentifier, primaryKeys []string) string { diff --git a/lib/sql/tests/columns_test.go b/lib/sql/tests/columns_test.go index c2010cf0..1799cac8 100644 --- a/lib/sql/tests/columns_test.go +++ b/lib/sql/tests/columns_test.go @@ -181,7 +181,7 @@ func TestBuildColumnsUpdateFragment_Snowflake(t *testing.T) { } actualQuery := sql.BuildColumnsUpdateFragment(stringAndToastCols, "stg", "tgt", snowflakeDialect.SnowflakeDialect{}) - assert.Equal(t, `"FOO"= CASE WHEN COALESCE(stg."FOO" != '__debezium_unavailable_value', true) THEN stg."FOO" ELSE tgt."FOO" END,"BAR"=stg."BAR"`, actualQuery) + assert.Equal(t, `"FOO"= CASE WHEN stg."FOO" NOT LIKE %__debezium_unavailable_value% THEN stg.\"FOO\" ELSE tgt.\"FOO\" END,\"BAR\"=stg.\"BAR\""`, actualQuery) } func TestBuildColumnComparison(t *testing.T) {