diff --git a/clients/bigquery/dialect/ddl.go b/clients/bigquery/dialect/ddl.go index 0b18440fd..41df8ef88 100644 --- a/clients/bigquery/dialect/ddl.go +++ b/clients/bigquery/dialect/ddl.go @@ -24,16 +24,12 @@ func (BigQueryDialect) BuildCreateTableQuery(tableID sql.TableIdentifier, tempor } } -func (bd BigQueryDialect) BuildAddColumnQuery(tableID sql.TableIdentifier, sqlPart string) string { - return bd.buildAlterColumnQuery(tableID, constants.Add, sqlPart) +func (BigQueryDialect) BuildAddColumnQuery(tableID sql.TableIdentifier, sqlPart string) string { + return fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s", tableID.FullyQualifiedName(), sqlPart) } -func (bd BigQueryDialect) BuildDropColumnQuery(tableID sql.TableIdentifier, colName string) string { - return bd.buildAlterColumnQuery(tableID, constants.Delete, colName) -} - -func (BigQueryDialect) buildAlterColumnQuery(tableID sql.TableIdentifier, columnOp constants.ColumnOperation, colSQLPart string) string { - return fmt.Sprintf("ALTER TABLE %s %s COLUMN %s", tableID.FullyQualifiedName(), columnOp, colSQLPart) +func (BigQueryDialect) BuildDropColumnQuery(tableID sql.TableIdentifier, colName string) string { + return fmt.Sprintf("ALTER TABLE %s DROP COLUMN %s", tableID.FullyQualifiedName(), colName) } func (BigQueryDialect) BuildDescribeTableQuery(tableID sql.TableIdentifier) (string, []interface{}, error) { diff --git a/clients/bigquery/dialect/dialect_test.go b/clients/bigquery/dialect/dialect_test.go index f292a4748..06dbce1ee 100644 --- a/clients/bigquery/dialect/dialect_test.go +++ b/clients/bigquery/dialect/dialect_test.go @@ -71,7 +71,7 @@ func TestBigQueryDialect_BuildDropColumnQuery(t *testing.T) { fakeTableID.FullyQualifiedNameReturns("{TABLE}") assert.Equal(t, - "ALTER TABLE {TABLE} drop COLUMN {SQL_PART}", + "ALTER TABLE {TABLE} DROP COLUMN {SQL_PART}", BigQueryDialect{}.BuildDropColumnQuery(fakeTableID, "{SQL_PART}"), ) } @@ -81,7 +81,7 @@ func TestBigQueryDialect_BuildAddColumnQuery(t *testing.T) { fakeTableID.FullyQualifiedNameReturns("{TABLE}") assert.Equal(t, - "ALTER TABLE {TABLE} add COLUMN {SQL_PART}", + "ALTER TABLE {TABLE} ADD COLUMN {SQL_PART}", BigQueryDialect{}.BuildAddColumnQuery(fakeTableID, "{SQL_PART}"), ) } diff --git a/clients/mssql/dialect/ddl.go b/clients/mssql/dialect/ddl.go index 12e106aaa..c810239f3 100644 --- a/clients/mssql/dialect/ddl.go +++ b/clients/mssql/dialect/ddl.go @@ -33,11 +33,11 @@ WHERE LOWER(TABLE_NAME) = LOWER(?) AND LOWER(TABLE_SCHEMA) = LOWER(?);`, []any{mssql.VarChar(mssqlTableID.Table()), mssql.VarChar(mssqlTableID.Schema())}, nil } -func (md MSSQLDialect) BuildAddColumnQuery(tableID sql.TableIdentifier, sqlPart string) string { +func (MSSQLDialect) BuildAddColumnQuery(tableID sql.TableIdentifier, sqlPart string) string { return fmt.Sprintf("ALTER TABLE %s ADD %s", tableID.FullyQualifiedName(), sqlPart) } -func (md MSSQLDialect) BuildDropColumnQuery(tableID sql.TableIdentifier, colName string) string { +func (MSSQLDialect) BuildDropColumnQuery(tableID sql.TableIdentifier, colName string) string { return fmt.Sprintf("ALTER TABLE %s DROP %s", tableID.FullyQualifiedName(), colName) } diff --git a/clients/redshift/dialect/ddl.go b/clients/redshift/dialect/ddl.go index d6daa565e..88e8ccbcd 100644 --- a/clients/redshift/dialect/ddl.go +++ b/clients/redshift/dialect/ddl.go @@ -40,11 +40,11 @@ WHERE `, constants.StrPrecisionCol), []any{redshiftTableID.Schema(), redshiftTableID.Table()}, nil } -func (rd RedshiftDialect) BuildAddColumnQuery(tableID sql.TableIdentifier, sqlPart string) string { +func (RedshiftDialect) BuildAddColumnQuery(tableID sql.TableIdentifier, sqlPart string) string { return fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s", tableID.FullyQualifiedName(), sqlPart) } -func (rd RedshiftDialect) BuildDropColumnQuery(tableID sql.TableIdentifier, colName string) string { +func (RedshiftDialect) BuildDropColumnQuery(tableID sql.TableIdentifier, colName string) string { return fmt.Sprintf("ALTER TABLE %s DROP COLUMN %s", tableID.FullyQualifiedName(), colName) } diff --git a/lib/destination/ddl/ddl_bq_test.go b/lib/destination/ddl/ddl_bq_test.go index a2e5ad98b..7d1dab513 100644 --- a/lib/destination/ddl/ddl_bq_test.go +++ b/lib/destination/ddl/ddl_bq_test.go @@ -63,7 +63,7 @@ func (d *DDLTestSuite) TestAlterTableDropColumnsBigQuery() { for _, column := range cols.GetColumns() { assert.NoError(d.T(), shared.AlterTableDropColumns(context.Background(), d.bigQueryStore, tc, tableID, []columns.Column{column}, ts.Add(2*constants.DeletionConfidencePadding), true)) _, query, _ := d.fakeBigQueryStore.ExecContextArgsForCall(callIdx) - assert.Equal(d.T(), fmt.Sprintf("ALTER TABLE %s drop COLUMN %s", fqName, d.bigQueryStore.Dialect().QuoteIdentifier(column.Name())), query) + assert.Equal(d.T(), fmt.Sprintf("ALTER TABLE %s DROP COLUMN %s", fqName, d.bigQueryStore.Dialect().QuoteIdentifier(column.Name())), query) callIdx += 1 } @@ -109,7 +109,7 @@ func (d *DDLTestSuite) TestAlterTableAddColumns() { assert.NoError(d.T(), shared.AlterTableAddColumns(context.Background(), d.bigQueryStore, tc, config.SharedDestinationColumnSettings{}, tableID, []columns.Column{col})) _, query, _ := d.fakeBigQueryStore.ExecContextArgsForCall(callIdx) - assert.Equal(d.T(), fmt.Sprintf("ALTER TABLE %s %s COLUMN %s %s", fqName, constants.Add, d.bigQueryStore.Dialect().QuoteIdentifier(col.Name()), + assert.Equal(d.T(), fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s %s", fqName, d.bigQueryStore.Dialect().QuoteIdentifier(col.Name()), d.bigQueryStore.Dialect().DataTypeForKind(kind, false, config.SharedDestinationColumnSettings{})), query) callIdx += 1 } @@ -158,7 +158,7 @@ func (d *DDLTestSuite) TestAlterTableAddColumnsSomeAlreadyExist() { assert.NoError(d.T(), shared.AlterTableAddColumns(context.Background(), d.bigQueryStore, tc, config.SharedDestinationColumnSettings{}, tableID, []columns.Column{column})) _, query, _ := d.fakeBigQueryStore.ExecContextArgsForCall(callIdx) - assert.Equal(d.T(), fmt.Sprintf("ALTER TABLE %s %s COLUMN %s %s", fqName, constants.Add, d.bigQueryStore.Dialect().QuoteIdentifier(column.Name()), + assert.Equal(d.T(), fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s %s", fqName, d.bigQueryStore.Dialect().QuoteIdentifier(column.Name()), d.bigQueryStore.Dialect().DataTypeForKind(column.KindDetails, false, config.SharedDestinationColumnSettings{})), query) callIdx += 1 }