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

Reading default values #912

Merged
merged 5 commits into from
Sep 18, 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
3 changes: 2 additions & 1 deletion clients/mssql/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ SELECT
ELSE
DATA_TYPE
END AS DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH
CHARACTER_MAXIMUM_LENGTH,
COLUMN_DEFAULT AS DEFAULT_VALUE
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
Expand Down
1 change: 0 additions & 1 deletion clients/mssql/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func (s *Store) Dedupe(_ sql.TableIdentifier, _ []string, _ bool) error {
}

func (s *Store) GetTableConfig(tableData *optimization.TableData) (*types.DwhTableConfig, error) {
// TODO: Figure out how to leave a comment.
tableID := s.specificIdentifierFor(tableData.TopicConfig(), tableData.Name())
query, args := describeTableQuery(tableID)
return shared.GetTableCfgArgs{
Expand Down
26 changes: 19 additions & 7 deletions clients/shared/table_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/artie-labs/transfer/lib/typing/columns"
)

// TODO: Simplify this function

type GetTableCfgArgs struct {
Dwh destination.DataWarehouse
TableID sql.TableIdentifier
Expand Down Expand Up @@ -104,14 +106,24 @@ func (g GetTableCfgArgs) GetTableConfig() (*types.DwhTableConfig, error) {
}

col := columns.NewColumn(row[g.ColumnNameForName], kindDetails)
// We need to check to make sure the comment is not an empty string
if comment, isOk := row[g.ColumnNameForComment]; isOk && comment != "" {
var _colComment constants.ColComment
if err = json.Unmarshal([]byte(comment), &_colComment); err != nil {
return nil, fmt.Errorf("failed to unmarshal comment %q: %w", comment, err)
strategy := g.Dwh.Dialect().GetDefaultValueStrategy()
switch strategy {
case sql.Backfill:
// We need to check to make sure the comment is not an empty string
if comment, isOk := row[g.ColumnNameForComment]; isOk && comment != "" {
var _colComment constants.ColComment
if err = json.Unmarshal([]byte(comment), &_colComment); err != nil {
return nil, fmt.Errorf("failed to unmarshal comment %q: %w", comment, err)
}

col.SetBackfilled(_colComment.Backfilled)
}

col.SetBackfilled(_colComment.Backfilled)
case sql.Native:
if value, isOk := row["default_value"]; isOk && value != "" {
col.SetBackfilled(true)
}
default:
return nil, fmt.Errorf("unknown default value strategy: %q", strategy)
}

cols.AddColumn(col)
Expand Down
3 changes: 2 additions & 1 deletion lib/typing/columns/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ type Column struct {
// Whenever we see the same column where there's an opposite value in `toastColumn`, we will trigger a flush
ToastColumn bool
defaultValue any
backfilled bool
// TODO: Instead of using a boolean, we should be setting the value at some point.
backfilled bool
}

func (c *Column) PrimaryKey() bool {
Expand Down
Loading