-
Notifications
You must be signed in to change notification settings - Fork 31
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
Pass Dialect
to Column.DefaultValue
#536
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ package columns | |
import ( | ||
"fmt" | ||
|
||
"github.com/artie-labs/transfer/lib/config/constants" | ||
"github.com/artie-labs/transfer/lib/sql" | ||
|
||
"github.com/artie-labs/transfer/lib/typing/ext" | ||
|
||
|
@@ -12,29 +12,27 @@ import ( | |
"github.com/artie-labs/transfer/lib/typing/decimal" | ||
) | ||
|
||
type DefaultValueArgs struct { | ||
Escape bool | ||
DestKind constants.DestinationKind | ||
} | ||
|
||
func (c *Column) RawDefaultValue() any { | ||
return c.defaultValue | ||
} | ||
|
||
func (c *Column) DefaultValue(args *DefaultValueArgs, additionalDateFmts []string) (any, error) { | ||
if args == nil || !args.Escape || c.defaultValue == nil { | ||
func (c *Column) DefaultValue(dialect sql.Dialect, additionalDateFmts []string) (any, error) { | ||
if c.defaultValue == nil { | ||
return c.defaultValue, nil | ||
} | ||
|
||
switch c.KindDetails.Kind { | ||
case typing.Struct.Kind, typing.Array.Kind: | ||
switch args.DestKind { | ||
case constants.BigQuery: | ||
switch dialect.(type) { | ||
case sql.BigQueryDialect: | ||
return "JSON" + stringutil.Wrap(c.defaultValue, false), nil | ||
case constants.Redshift: | ||
case sql.RedshiftDialect: | ||
return fmt.Sprintf("JSON_PARSE(%s)", stringutil.Wrap(c.defaultValue, false)), nil | ||
case constants.Snowflake: | ||
case sql.SnowflakeDialect: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Tang8330 it doesn't seem like we're doing anything for MS SQL here, do we need a case for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we're not. We don't support backfill default values in MSSQL yet. Do you want to leave a comment? |
||
return stringutil.Wrap(c.defaultValue, false), nil | ||
default: | ||
// Note that we don't currently support backfills for MS SQL. | ||
return nil, fmt.Errorf("not implemented for %v dialect", dialect) | ||
} | ||
case typing.ETime.Kind: | ||
if c.KindDetails.ExtendedTimeDetails == nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only place we call
DefaultValue
so I removed theEscape
argument.