From fb30e5f25e45d13ba032c91ebc943442f65d4bff Mon Sep 17 00:00:00 2001 From: Kevin Biju Date: Tue, 9 Jan 2024 03:01:50 +0530 Subject: [PATCH] undo me not understanding PG merge --- .../postgres/normalize_stmt_generator.go | 2 +- .../postgres/normalize_stmt_generator_test.go | 40 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/flow/connectors/postgres/normalize_stmt_generator.go b/flow/connectors/postgres/normalize_stmt_generator.go index e3af2f48f0..b541543fe2 100644 --- a/flow/connectors/postgres/normalize_stmt_generator.go +++ b/flow/connectors/postgres/normalize_stmt_generator.go @@ -194,7 +194,7 @@ func (n *normalizeStmtGenerator) generateUpdateStatements(allCols []string) []st unquotedUnchangedColsArray := strings.Split(cols, ",") unchangedColsArray := make([]string, 0, len(unquotedUnchangedColsArray)) for _, unchangedToastCol := range unquotedUnchangedColsArray { - unchangedColsArray = append(unchangedColsArray, unchangedToastCol) + unchangedColsArray = append(unchangedColsArray, fmt.Sprintf(`"%s"`, unchangedToastCol)) } otherCols := utils.ArrayMinus(allCols, unchangedColsArray) tmpArray := make([]string, 0, len(otherCols)) diff --git a/flow/connectors/postgres/normalize_stmt_generator_test.go b/flow/connectors/postgres/normalize_stmt_generator_test.go index 46ffd058df..637c69f2bc 100644 --- a/flow/connectors/postgres/normalize_stmt_generator_test.go +++ b/flow/connectors/postgres/normalize_stmt_generator_test.go @@ -9,12 +9,12 @@ import ( ) func TestGenerateMergeUpdateStatement(t *testing.T) { - allCols := []string{"col1", "col2", "col3"} + allCols := []string{`"col1"`, `"col2"`, `"col3"`} unchangedToastCols := []string{""} expected := []string{ `WHEN MATCHED AND src._peerdb_record_type!=2 AND _peerdb_unchanged_toast_columns='' - THEN UPDATE SET col1=src.col1,col2=src.col2,col3=src.col3, + THEN UPDATE SET "col1"=src."col1","col2"=src."col2","col3"=src."col3", "_peerdb_synced_at"=CURRENT_TIMESTAMP`, } normalizeGen := &normalizeStmtGenerator{ @@ -38,15 +38,15 @@ func TestGenerateMergeUpdateStatement(t *testing.T) { } func TestGenerateMergeUpdateStatement_WithSoftDelete(t *testing.T) { - allCols := []string{"col1", "col2", "col3"} + allCols := []string{`"col1"`, `"col2"`, `"col3"`} unchangedToastCols := []string{""} expected := []string{ `WHEN MATCHED AND src._peerdb_record_type!=2 AND _peerdb_unchanged_toast_columns='' - THEN UPDATE SET col1=src.col1,col2=src.col2,col3=src.col3, + THEN UPDATE SET "col1"=src."col1","col2"=src."col2","col3"=src."col3", "_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=FALSE`, `WHEN MATCHED AND src._peerdb_record_type=2 AND _peerdb_unchanged_toast_columns='' - THEN UPDATE SET col1=src.col1,col2=src.col2,col3=src.col3, + THEN UPDATE SET "col1"=src."col1","col2"=src."col2","col3"=src."col3", "_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=TRUE`, } normalizeGen := &normalizeStmtGenerator{ @@ -70,18 +70,18 @@ func TestGenerateMergeUpdateStatement_WithSoftDelete(t *testing.T) { } func TestGenerateMergeUpdateStatement_WithUnchangedToastCols(t *testing.T) { - allCols := []string{"col1", "col2", "col3"} + allCols := []string{`"col1"`, `"col2"`, `"col3"`} unchangedToastCols := []string{"", "col2,col3", "col2", "col3"} expected := []string{ `WHEN MATCHED AND src._peerdb_record_type!=2 AND _peerdb_unchanged_toast_columns='' - THEN UPDATE SET col1=src.col1,col2=src.col2,col3=src.col3,"_peerdb_synced_at"=CURRENT_TIMESTAMP`, + THEN UPDATE SET "col1"=src."col1","col2"=src."col2","col3"=src."col3","_peerdb_synced_at"=CURRENT_TIMESTAMP`, `WHEN MATCHED AND src._peerdb_record_type!=2 AND _peerdb_unchanged_toast_columns='col2,col3' - THEN UPDATE SET col1=src.col1,"_peerdb_synced_at"=CURRENT_TIMESTAMP`, + THEN UPDATE SET "col1"=src."col1","_peerdb_synced_at"=CURRENT_TIMESTAMP`, `WHEN MATCHED AND src._peerdb_record_type!=2 AND _peerdb_unchanged_toast_columns='col2' - THEN UPDATE SET col1=src.col1,col3=src.col3,"_peerdb_synced_at"=CURRENT_TIMESTAMP`, + THEN UPDATE SET "col1"=src."col1","col3"=src."col3","_peerdb_synced_at"=CURRENT_TIMESTAMP`, `WHEN MATCHED AND src._peerdb_record_type!=2 AND _peerdb_unchanged_toast_columns='col3' - THEN UPDATE SET col1=src.col1,col2=src.col2,"_peerdb_synced_at"=CURRENT_TIMESTAMP`, + THEN UPDATE SET "col1"=src."col1","col2"=src."col2","_peerdb_synced_at"=CURRENT_TIMESTAMP`, } normalizeGen := &normalizeStmtGenerator{ unchangedToastColumns: unchangedToastCols, @@ -104,26 +104,28 @@ func TestGenerateMergeUpdateStatement_WithUnchangedToastCols(t *testing.T) { } func TestGenerateMergeUpdateStatement_WithUnchangedToastColsAndSoftDelete(t *testing.T) { - allCols := []string{"col1", "col2", "col3"} + allCols := []string{`"col1"`, `"col2"`, `"col3"`} unchangedToastCols := []string{"", "col2,col3", "col2", "col3"} expected := []string{ `WHEN MATCHED AND src._peerdb_record_type!=2 AND _peerdb_unchanged_toast_columns='' - THEN UPDATE SET col1=src.col1,col2=src.col2,col3=src.col3,"_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=FALSE`, + THEN UPDATE SET "col1"=src."col1","col2"=src."col2","col3"=src."col3", + "_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=FALSE`, `WHEN MATCHED AND src._peerdb_record_type=2 AND _peerdb_unchanged_toast_columns='' - THEN UPDATE SET col1=src.col1,col2=src.col2,col3=src.col3,"_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=TRUE`, + THEN UPDATE SET "col1"=src."col1","col2"=src."col2","col3"=src."col3", + "_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=TRUE`, `WHEN MATCHED AND src._peerdb_record_type!=2 AND _peerdb_unchanged_toast_columns='col2,col3' - THEN UPDATE SET col1=src.col1,"_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=FALSE`, + THEN UPDATE SET "col1"=src."col1","_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=FALSE`, `WHEN MATCHED AND src._peerdb_record_type=2 AND _peerdb_unchanged_toast_columns='col2,col3' - THEN UPDATE SET col1=src.col1,"_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=TRUE`, + THEN UPDATE SET "col1"=src."col1","_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=TRUE`, `WHEN MATCHED AND src._peerdb_record_type!=2 AND _peerdb_unchanged_toast_columns='col2' - THEN UPDATE SET col1=src.col1,col3=src.col3,"_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=FALSE`, + THEN UPDATE SET "col1"=src."col1","col3"=src."col3","_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=FALSE`, `WHEN MATCHED AND src._peerdb_record_type=2 AND _peerdb_unchanged_toast_columns='col2' - THEN UPDATE SET col1=src.col1,col3=src.col3,"_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=TRUE`, + THEN UPDATE SET "col1"=src."col1","col3"=src."col3","_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=TRUE`, `WHEN MATCHED AND src._peerdb_record_type!=2 AND _peerdb_unchanged_toast_columns='col3' - THEN UPDATE SET col1=src.col1,col2=src.col2,"_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=FALSE`, + THEN UPDATE SET "col1"=src."col1","col2"=src."col2","_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=FALSE`, `WHEN MATCHED AND src._peerdb_record_type=2 AND _peerdb_unchanged_toast_columns='col3' - THEN UPDATE SET col1=src.col1,col2=src.col2,"_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=TRUE`, + THEN UPDATE SET "col1"=src."col1","col2"=src."col2","_peerdb_synced_at"=CURRENT_TIMESTAMP,"_peerdb_soft_delete"=TRUE`, } normalizeGen := &normalizeStmtGenerator{ unchangedToastColumns: unchangedToastCols,