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 03d52d8 commit a326332
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
32 changes: 25 additions & 7 deletions clients/bigquery/storagewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,34 @@ func TestColumnToTableFieldSchema(t *testing.T) {
}
{
// ETime - Time:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType)))
_time, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType, "")
assert.NoError(t, err)

fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", _time))
assert.NoError(t, err)
assert.Equal(t, storagepb.TableFieldSchema_TIME, fieldSchema.Type)
}
{
// ETime - Date:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType)))
_date, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType, "")
assert.NoError(t, err)

fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", _date))
assert.NoError(t, err)
assert.Equal(t, storagepb.TableFieldSchema_DATE, fieldSchema.Type)
}
{
// ETime - TimestampTz:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType)))
_timestampTZ, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType, "")
assert.NoError(t, err)

fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", _timestampTZ))
assert.NoError(t, err)
assert.Equal(t, storagepb.TableFieldSchema_TIMESTAMP, fieldSchema.Type)
}
{
// ETime - Invalid:
_, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.NewTimeDetailsFromTemplate(typing.ETime, "")))
_, err := typing.NewTimeDetailsFromTemplate(typing.ETime, "", "")
assert.ErrorContains(t, err, "unsupported extended time details type:")
}
{
Expand Down Expand Up @@ -99,6 +108,15 @@ func TestEncodePacked64TimeMicros(t *testing.T) {
}

func TestRowToMessage(t *testing.T) {
_time, err := typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType, "")
assert.NoError(t, err)

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

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

columns := []columns.Column{
columns.NewColumn("c_bool", typing.Boolean),
columns.NewColumn("c_int", typing.Integer),
Expand All @@ -112,9 +130,9 @@ func TestRowToMessage(t *testing.T) {
columns.NewColumn("c_numeric", typing.EDecimal),
columns.NewColumn("c_string", typing.String),
columns.NewColumn("c_string_decimal", typing.String),
columns.NewColumn("c_time", typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimeKindType)),
columns.NewColumn("c_date", typing.NewTimeDetailsFromTemplate(typing.ETime, ext.DateKindType)),
columns.NewColumn("c_datetime", typing.NewTimeDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType)),
columns.NewColumn("c_time", _time),
columns.NewColumn("c_date", _date),
columns.NewColumn("c_datetime", _timestampTZ),
columns.NewColumn("c_struct", typing.Struct),
columns.NewColumn("c_array", typing.Array),
}
Expand Down
9 changes: 8 additions & 1 deletion clients/databricks/dialect/typing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ func TestDatabricksDialect_KindForDataType(t *testing.T) {
// 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)
assert.Equal(t,
typing.KindDetails{
Kind: typing.ETime.Kind,
ExtendedTimeDetails: &ext.NestedKind{
Type: ext.DateKindType,
Format: ext.PostgresDateFormat,
},
}, kd)
}
{
// Double
Expand Down

0 comments on commit a326332

Please sign in to comment.