diff --git a/clients/mssql/queries.go b/clients/mssql/queries.go index 636aa6052..e23feadcf 100644 --- a/clients/mssql/queries.go +++ b/clients/mssql/queries.go @@ -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 diff --git a/clients/mssql/store.go b/clients/mssql/store.go index 0c8e31758..66704e93e 100644 --- a/clients/mssql/store.go +++ b/clients/mssql/store.go @@ -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{ diff --git a/clients/shared/table_config.go b/clients/shared/table_config.go index 47bd2502a..03698150b 100644 --- a/clients/shared/table_config.go +++ b/clients/shared/table_config.go @@ -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 @@ -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) diff --git a/lib/typing/columns/columns.go b/lib/typing/columns/columns.go index 40dd0b9e4..779fdc839 100644 --- a/lib/typing/columns/columns.go +++ b/lib/typing/columns/columns.go @@ -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 {