Skip to content

Commit

Permalink
[Databricks] Implement Sweep (#951)
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Tang <[email protected]>
  • Loading branch information
Tang8330 authored Oct 7, 2024
1 parent 33451a0 commit b808151
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 12 additions & 0 deletions clients/databricks/dialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"strings"

dbsql "github.com/databricks/databricks-sql-go"

"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/sql"
"github.com/artie-labs/transfer/lib/typing"
Expand Down Expand Up @@ -143,6 +145,16 @@ WHEN NOT MATCHED AND IFNULL(%s, false) = false THEN INSERT (%s) VALUES (%s);`,
)}, nil
}

func (d DatabricksDialect) BuildSweepQuery(dbName, schemaName string) (string, []any) {
return fmt.Sprintf(`
SELECT
table_schema, table_name
FROM
%s.information_schema.tables
WHERE
UPPER(table_schema) = UPPER(:p_schema) AND table_name ILIKE :p_artie_prefix`, d.QuoteIdentifier(dbName)), []any{dbsql.Parameter{Name: "p_schema", Value: schemaName}, dbsql.Parameter{Name: "p_artie_prefix", Value: "%" + constants.ArtiePrefix + "%"}}
}

func (d DatabricksDialect) GetDefaultValueStrategy() sql.DefaultValueStrategy {
return sql.Native
}
13 changes: 11 additions & 2 deletions clients/databricks/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (s Store) IdentifierFor(topicConfig kafkalib.TopicConfig, table string) sql
}

func (s Store) Dialect() sql.Dialect {
return s.dialect()
}

func (s Store) dialect() dialect.DatabricksDialect {
return dialect.DatabricksDialect{}
}

Expand Down Expand Up @@ -185,8 +189,13 @@ func (s Store) writeTemporaryTableFile(tableData *optimization.TableData, newTab
}

func (s Store) SweepTemporaryTables() error {
// TODO
return nil
// TODO: We should also remove old volumes
tcs, err := s.cfg.TopicConfigs()
if err != nil {
return err
}

return shared.Sweep(s, tcs, s.dialect().BuildSweepQuery)
}

func LoadStore(cfg config.Config) (Store, error) {
Expand Down

0 comments on commit b808151

Please sign in to comment.