diff --git a/clients/databricks/dialect/typing_test.go b/clients/databricks/dialect/typing_test.go index 790cc1147..1c38946e5 100644 --- a/clients/databricks/dialect/typing_test.go +++ b/clients/databricks/dialect/typing_test.go @@ -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", "") + 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) + } +} diff --git a/lib/typing/numeric.go b/lib/typing/numeric.go index af86164c5..cc2ba7087 100644 --- a/lib/typing/numeric.go +++ b/lib/typing/numeric.go @@ -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