Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Databricks] Implement Sweep #951

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading