Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Nov 19, 2024
1 parent fe29043 commit 530a9b3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
12 changes: 4 additions & 8 deletions clients/bigquery/dialect/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions clients/bigquery/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
)
}
Expand All @@ -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}"),
)
}
Expand Down
4 changes: 2 additions & 2 deletions clients/mssql/dialect/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions clients/redshift/dialect/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions lib/destination/ddl/ddl_bq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 530a9b3

Please sign in to comment.