From db54aca0c9554c9bd1affbc82fefe839e05d1adf Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Wed, 20 Nov 2024 09:20:43 -0800 Subject: [PATCH] Adding Databricks DDL. --- clients/databricks/dialect/ddl.go | 13 ++++--------- clients/databricks/dialect/dialect_test.go | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/clients/databricks/dialect/ddl.go b/clients/databricks/dialect/ddl.go index d02be6296..f38429022 100644 --- a/clients/databricks/dialect/ddl.go +++ b/clients/databricks/dialect/ddl.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - "github.com/artie-labs/transfer/lib/config/constants" "github.com/artie-labs/transfer/lib/sql" ) @@ -13,18 +12,14 @@ func (DatabricksDialect) BuildCreateTableQuery(tableID sql.TableIdentifier, _ bo return fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (%s)", tableID.FullyQualifiedName(), strings.Join(colSQLParts, ", ")) } -func (d DatabricksDialect) BuildAddColumnQuery(tableID sql.TableIdentifier, sqlPart string) string { - return d.buildAlterColumnQuery(tableID, constants.Add, sqlPart) +func (DatabricksDialect) BuildAddColumnQuery(tableID sql.TableIdentifier, sqlPart string) string { + return fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s", tableID.FullyQualifiedName(), sqlPart) } -func (d DatabricksDialect) BuildDropColumnQuery(tableID sql.TableIdentifier, colName string) string { - return d.buildAlterColumnQuery(tableID, constants.Delete, colName) +func (DatabricksDialect) BuildDropColumnQuery(tableID sql.TableIdentifier, colName string) string { + return fmt.Sprintf("ALTER TABLE %s DROP COLUMN %s", tableID.FullyQualifiedName(), colName) } func (DatabricksDialect) BuildDescribeTableQuery(tableID sql.TableIdentifier) (string, []any, error) { return fmt.Sprintf("DESCRIBE TABLE %s", tableID.FullyQualifiedName()), nil, nil } - -func (DatabricksDialect) buildAlterColumnQuery(tableID sql.TableIdentifier, columnOp constants.ColumnOperation, colSQLPart string) string { - return fmt.Sprintf("ALTER TABLE %s %s COLUMN %s", tableID.FullyQualifiedName(), columnOp, colSQLPart) -} diff --git a/clients/databricks/dialect/dialect_test.go b/clients/databricks/dialect/dialect_test.go index eea131d2d..59c0c6b4d 100644 --- a/clients/databricks/dialect/dialect_test.go +++ b/clients/databricks/dialect/dialect_test.go @@ -73,13 +73,13 @@ func TestDatabricksDialect_BuildCreateTableQuery(t *testing.T) { func TestDatabricksDialect_BuildAddColumnQuery(t *testing.T) { fakeTableID := &mocks.FakeTableIdentifier{} fakeTableID.FullyQualifiedNameReturns("{TABLE}") - assert.Equal(t, "ALTER TABLE {TABLE} add COLUMN {SQL_PART} {DATA_TYPE}", DatabricksDialect{}.BuildAddColumnQuery(fakeTableID, "{SQL_PART} {DATA_TYPE}")) + assert.Equal(t, "ALTER TABLE {TABLE} ADD COLUMN {SQL_PART} {DATA_TYPE}", DatabricksDialect{}.BuildAddColumnQuery(fakeTableID, "{SQL_PART} {DATA_TYPE}")) } func TestDatabricksDialect_BuildDropColumnQuery(t *testing.T) { fakeTableID := &mocks.FakeTableIdentifier{} fakeTableID.FullyQualifiedNameReturns("{TABLE}") - assert.Equal(t, "ALTER TABLE {TABLE} drop COLUMN {SQL_PART}", DatabricksDialect{}.BuildDropColumnQuery(fakeTableID, "{SQL_PART}")) + assert.Equal(t, "ALTER TABLE {TABLE} DROP COLUMN {SQL_PART}", DatabricksDialect{}.BuildDropColumnQuery(fakeTableID, "{SQL_PART}")) } func TestDatabricksDialect_BuildDedupeQueries(t *testing.T) {