Skip to content

Commit

Permalink
Reading default values (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 authored Sep 18, 2024
1 parent 16e8422 commit ecf1d2e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
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

0 comments on commit ecf1d2e

Please sign in to comment.