Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Oct 17, 2024
1 parent 0adb8c1 commit 03d52d8
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 24 deletions.
35 changes: 28 additions & 7 deletions clients/bigquery/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ func TestBigQueryDialect_KindForDataType(t *testing.T) {
}
}

_datetime, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType, "")
assert.NoError(t, err)

_timestamp, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType, "")
assert.NoError(t, err)

_time, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType, "")
assert.NoError(t, err)

_date, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType, "")
assert.NoError(t, err)

bqColToExpectedKind := map[string]typing.KindDetails{
// Number
"numeric": typing.EDecimal,
Expand Down Expand Up @@ -92,10 +104,10 @@ func TestBigQueryDialect_KindForDataType(t *testing.T) {
"record": typing.Struct,
"json": typing.Struct,
// Datetime
"datetime": typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType),
"timestamp": typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType),
"time": typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType),
"date": typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType),
"datetime": _datetime,
"timestamp": _timestamp,
"time": _time,
"date": _date,
//Invalid
"foo": typing.Invalid,
"foofoo": typing.Invalid,
Expand Down Expand Up @@ -129,10 +141,19 @@ func TestBigQueryDialect_KindForDataType(t *testing.T) {
}

func TestBigQueryDialect_KindForDataType_NoDataLoss(t *testing.T) {
_timestampTZ, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType, "")
assert.NoError(t, err)

_time, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType, "")
assert.NoError(t, err)

_date, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType, "")
assert.NoError(t, err)

kindDetails := []typing.KindDetails{
typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType),
typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType),
typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType),
_timestampTZ,
_time,
_date,
typing.String,
typing.Boolean,
typing.Struct,
Expand Down
10 changes: 8 additions & 2 deletions clients/databricks/dialect/typing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,19 @@ func TestDatabricksDialect_KindForDataType(t *testing.T) {
// Timestamp
kd, err := DatabricksDialect{}.KindForDataType("TIMESTAMP", "")
assert.NoError(t, err)
assert.Equal(t, typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType), kd)

_kd, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType, "")
assert.NoError(t, err)
assert.Equal(t, _kd, kd)
}
{
// Timestamp NTZ
kd, err := DatabricksDialect{}.KindForDataType("TIMESTAMP_NTZ", "")
assert.NoError(t, err)
assert.Equal(t, typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType), kd)

_kd, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType, "")
assert.NoError(t, err)
assert.Equal(t, _kd, kd)
}
{
// Variant
Expand Down
20 changes: 16 additions & 4 deletions clients/mssql/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ func TestMSSQLDialect_DataTypeForKind(t *testing.T) {
func TestMSSQLDialect_KindForDataType(t *testing.T) {
dialect := MSSQLDialect{}

_date, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType, "")
assert.NoError(t, err)

_time, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType, "")
assert.NoError(t, err)

_datetime, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType, "")
assert.NoError(t, err)

_datetime2, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType, "")
assert.NoError(t, err)

colToExpectedKind := map[string]typing.KindDetails{
"char": typing.String,
"varchar": typing.String,
Expand All @@ -62,10 +74,10 @@ func TestMSSQLDialect_KindForDataType(t *testing.T) {
"float": typing.Float,
"real": typing.Float,
"bit": typing.Boolean,
"date": typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType),
"time": typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType),
"datetime": typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType),
"datetime2": typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType),
"date": _date,
"time": _time,
"datetime": _datetime,
"datetime2": _datetime2,
}

for col, expectedKind := range colToExpectedKind {
Expand Down
15 changes: 12 additions & 3 deletions clients/snowflake/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,19 @@ func TestSnowflakeDialect_KindForDataType_DateTime(t *testing.T) {
}

func TestSnowflakeDialect_KindForDataType_NoDataLoss(t *testing.T) {
_timestampTZ, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType, "")
assert.NoError(t, err)

_time, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType, "")
assert.NoError(t, err)

_date, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType, "")
assert.NoError(t, err)

kindDetails := []typing.KindDetails{
typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType),
typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType),
typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType),
_timestampTZ,
_time,
_date,
typing.String,
typing.Boolean,
typing.Struct,
Expand Down
4 changes: 2 additions & 2 deletions lib/debezium/converters/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func (JSON) Convert(value any) (any, error) {
return jsonutil.SanitizePayload(valueString)
}

func (JSON) ToKindDetails() typing.KindDetails {
return typing.Struct
func (JSON) ToKindDetails() (typing.KindDetails, error) {
return typing.Struct, nil
}

type Int64Passthrough struct{}
Expand Down
8 changes: 4 additions & 4 deletions lib/debezium/converters/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ type VariableDecimal struct {
details decimal.Details
}

func (v VariableDecimal) ToKindDetails() typing.KindDetails {
return typing.NewDecimalDetailsFromTemplate(typing.EDecimal, v.details)
func (v VariableDecimal) ToKindDetails() (typing.KindDetails, error) {
return typing.NewDecimalDetailsFromTemplate(typing.EDecimal, v.details), nil
}

func (v VariableDecimal) Convert(value any) (any, error) {
Expand Down Expand Up @@ -134,8 +134,8 @@ func NewDecimal(details decimal.Details) Decimal {
return Decimal{details: details}
}

func (d Decimal) ToKindDetails() typing.KindDetails {
return typing.NewDecimalDetailsFromTemplate(typing.EDecimal, d.details)
func (d Decimal) ToKindDetails() (typing.KindDetails, error) {
return typing.NewDecimalDetailsFromTemplate(typing.EDecimal, d.details), nil
}

func (d Decimal) Convert(value any) (any, error) {
Expand Down
4 changes: 2 additions & 2 deletions lib/debezium/converters/geometry.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func (GeometryPoint) Convert(value any) (any, error) {

type Geometry struct{}

func (Geometry) ToKindDetails() typing.KindDetails {
func (Geometry) ToKindDetails() (typing.KindDetails, error) {
// We will return this in GeoJSON format.
return typing.Struct
return typing.Struct, nil
}

func (Geometry) Convert(value any) (any, error) {
Expand Down

0 comments on commit 03d52d8

Please sign in to comment.