From 6151f1c0895f8d4f8d66ad39790e64bb6c0ab01f Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 12 Dec 2024 15:12:35 -0800 Subject: [PATCH] Redshift Toast. --- clients/redshift/dialect/dialect.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/clients/redshift/dialect/dialect.go b/clients/redshift/dialect/dialect.go index 0036c094e..064ab52f9 100644 --- a/clients/redshift/dialect/dialect.go +++ b/clients/redshift/dialect/dialect.go @@ -31,12 +31,15 @@ func (RedshiftDialect) IsTableDoesNotExistErr(_ error) bool { } func (rd RedshiftDialect) BuildIsNotToastValueExpression(tableAlias constants.TableAlias, column columns.Column) string { + toastedValue := "%" + constants.ToastUnavailableValuePlaceholder + "%" colName := sql.QuoteTableAliasColumn(tableAlias, column, rd) - if column.KindDetails == typing.Struct { - return fmt.Sprintf(`COALESCE(%s != JSON_PARSE('{"key":"%s"}'), true)`, - colName, constants.ToastUnavailableValuePlaceholder) + + switch column.KindDetails { + case typing.Struct, typing.Array: + return fmt.Sprintf("COALESCE(JSON_SERIALIZE(%s) NOT LIKE '%s', TRUE)", colName, toastedValue) + default: + return fmt.Sprintf(`COALESCE(%s NOT LIKE '%s', TRUE)`, colName, toastedValue) } - return fmt.Sprintf("COALESCE(%s != '%s', true)", colName, constants.ToastUnavailableValuePlaceholder) } func (rd RedshiftDialect) BuildDedupeTableQuery(tableID sql.TableIdentifier, _ []string) string {