Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 30, 2024
1 parent 0743b71 commit 0641ae2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
51 changes: 51 additions & 0 deletions clients/databricks/dialect/dialect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package dialect

import (
"fmt"

"github.com/artie-labs/transfer/lib/typing/ext"

"github.com/artie-labs/transfer/lib/typing"
)

type DatabricksDialect struct{}

func (DatabricksDialect) QuoteIdentifier(identifier string) string {
return fmt.Sprintf("`%s`", identifier)
}

func (DatabricksDialect) EscapeStruct(value string) string {
panic("not implemented")
}

func (DatabricksDialect) DataTypeForKind(kindDetails typing.KindDetails, isPk bool) string {
switch kindDetails.Kind {
case typing.Float.Kind:
return "DOUBLE"
case typing.Integer.Kind:
return "INT"
case typing.Struct.Kind:
return "VARIANT"
case typing.Array.Kind:
// Databricks requires arrays to be typed. As such, we're going to use an array of strings.
return "ARRAY<string>"
case typing.String.Kind:
return "STRING"
case typing.Boolean.Kind:
return "BOOLEAN"
case typing.ETime.Kind:
switch kindDetails.ExtendedTimeDetails.Type {
case ext.TimestampTzKindType:
// Using datetime2 because it's the recommendation, and it provides more precision: https://stackoverflow.com/a/1884088
return "TIMESTAMP"
case ext.DateKindType:
return "DATE"
case ext.TimeKindType:
return "STRING"
}
case typing.EDecimal.Kind:
return kindDetails.ExtendedDecimalDetails.DatabricksKind()
}

return kindDetails.Kind
}
6 changes: 6 additions & 0 deletions lib/typing/decimal/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ func (d Details) SnowflakeKind() string {
return d.toKind(MaxPrecisionBeforeString, "STRING")
}

// DatabricksKind - is used to determine whether a NUMERIC data type should be a STRING or NUMERIC(p, s).
// Ref: https://docs.databricks.com/en/sql/language-manual/data-types/decimal-type.html
func (d Details) DatabricksKind() string {
return d.toKind(MaxPrecisionBeforeString, "STRING")
}

// MsSQLKind - Has the same limitation as Redshift
// Spec: https://learn.microsoft.com/en-us/sql/t-sql/data-types/decimal-and-numeric-transact-sql?view=sql-server-ver16#arguments
func (d Details) MsSQLKind() string {
Expand Down

0 comments on commit 0641ae2

Please sign in to comment.