Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 30, 2024
1 parent 6d3cc45 commit bbd06ae
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
101 changes: 101 additions & 0 deletions clients/databricks/dialect/typing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,104 @@ func TestDatabricksDialect_DataTypeForKind(t *testing.T) {
}
}
}

func TestDatabricksDialect_KindForDataType(t *testing.T) {
{
// Decimal
{
// Invalid
_, err := DatabricksDialect{}.KindForDataType("DECIMAL(9", "")
assert.ErrorContains(t, err, "missing closing parenthesis")
}
{
// Valid
kd, err := DatabricksDialect{}.KindForDataType("DECIMAL(10, 2)", "")
assert.NoError(t, err)
assert.Equal(t, typing.KindDetails{Kind: typing.EDecimal.Kind, ExtendedDecimalDetails: typing.ToPtr(decimal.NewDetails(10, 2))}, kd)
}
}
{
// Array
kd, err := DatabricksDialect{}.KindForDataType("ARRAY<string>", "")
assert.NoError(t, err)
assert.Equal(t, typing.Array, kd)
}
{
// String
kd, err := DatabricksDialect{}.KindForDataType("STRING", "")
assert.NoError(t, err)
assert.Equal(t, typing.String, kd)
}
{
// Binary
kd, err := DatabricksDialect{}.KindForDataType("BINARY", "")
assert.NoError(t, err)
assert.Equal(t, typing.String, kd)
}
{
// BigInt
kd, err := DatabricksDialect{}.KindForDataType("BIGINT", "")
assert.NoError(t, err)
assert.Equal(t, typing.KindDetails{Kind: typing.Integer.Kind, OptionalIntegerKind: typing.ToPtr(typing.BigIntegerKind)}, kd)
}
{
// Boolean
kd, err := DatabricksDialect{}.KindForDataType("BOOLEAN", "")
assert.NoError(t, err)
assert.Equal(t, typing.Boolean, kd)
}
{
// Date
kd, err := DatabricksDialect{}.KindForDataType("DATE", "")
assert.NoError(t, err)
assert.Equal(t, typing.KindDetails{Kind: typing.ETime.Kind, ExtendedTimeDetails: &ext.NestedKind{Type: ext.DateKindType}}, kd)
}
{
// Double
kd, err := DatabricksDialect{}.KindForDataType("DOUBLE", "")
assert.NoError(t, err)
assert.Equal(t, typing.Float, kd)
}
{
// Float
kd, err := DatabricksDialect{}.KindForDataType("FLOAT", "")
assert.NoError(t, err)
assert.Equal(t, typing.Float, kd)
}
{
// Integer
kd, err := DatabricksDialect{}.KindForDataType("INT", "")
assert.NoError(t, err)
assert.Equal(t, typing.KindDetails{Kind: typing.Integer.Kind, OptionalIntegerKind: typing.ToPtr(typing.IntegerKind)}, kd)
}
{
// Small Int
kd, err := DatabricksDialect{}.KindForDataType("SMALLINT", "")
assert.NoError(t, err)
assert.Equal(t, typing.KindDetails{Kind: typing.Integer.Kind, OptionalIntegerKind: typing.ToPtr(typing.SmallIntegerKind)}, kd)
}
{
// Timestamp
kd, err := DatabricksDialect{}.KindForDataType("TIMESTAMP", "")
assert.NoError(t, err)
assert.Equal(t, typing.NewKindDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType), kd)
}
{
// Timestamp NTZ
kd, err := DatabricksDialect{}.KindForDataType("TIMESTAMP_NTZ", "")
assert.NoError(t, err)
assert.Equal(t, typing.NewKindDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType), kd)
}
{
// Variant
kd, err := DatabricksDialect{}.KindForDataType("VARIANT", "")
assert.NoError(t, err)
assert.Equal(t, typing.KindDetails{Kind: typing.Struct.Kind}, kd)
}
{
// Object
kd, err := DatabricksDialect{}.KindForDataType("OBJECT", "")
assert.NoError(t, err)
assert.Equal(t, typing.KindDetails{Kind: typing.Struct.Kind}, kd)
}
}
1 change: 1 addition & 0 deletions lib/typing/numeric.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/artie-labs/transfer/lib/typing/decimal"
)

// TODO: This function should return an error
func ParseNumeric(parts []string) KindDetails {
if len(parts) == 0 || len(parts) > 2 {
return Invalid
Expand Down

0 comments on commit bbd06ae

Please sign in to comment.