From a3263321153b9369b89e3c6f710c31d001ea222e Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 17 Oct 2024 10:54:47 -0700 Subject: [PATCH] WIP. --- clients/bigquery/storagewrite_test.go | 32 ++++++++++++++++++----- clients/databricks/dialect/typing_test.go | 9 ++++++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/clients/bigquery/storagewrite_test.go b/clients/bigquery/storagewrite_test.go index 67d70c775..ed9ce591a 100644 --- a/clients/bigquery/storagewrite_test.go +++ b/clients/bigquery/storagewrite_test.go @@ -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:") } { @@ -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), @@ -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), } diff --git a/clients/databricks/dialect/typing_test.go b/clients/databricks/dialect/typing_test.go index 8f50c26ac..8333550ae 100644 --- a/clients/databricks/dialect/typing_test.go +++ b/clients/databricks/dialect/typing_test.go @@ -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