diff --git a/pkg/bigquery/driver/rows.go b/pkg/bigquery/driver/rows.go index 3c893c5..952417e 100644 --- a/pkg/bigquery/driver/rows.go +++ b/pkg/bigquery/driver/rows.go @@ -78,7 +78,7 @@ func (r *rows) bigqueryTypeOf(columnType *string) (reflect.Type, error) { return reflect.TypeOf(time.Time{}), nil case "DATE", "TIME", "DATETIME": return reflect.TypeOf(""), nil - case "RECORD", "GEOGRAPHY": + case "RECORD", "GEOGRAPHY", "JSON": return reflect.TypeOf(""), nil default: return nil, fmt.Errorf("unknown column type `%s`", *columnType) diff --git a/pkg/bigquery/driver/utils.go b/pkg/bigquery/driver/utils.go index 9ef1227..152e04f 100644 --- a/pkg/bigquery/driver/utils.go +++ b/pkg/bigquery/driver/utils.go @@ -6,7 +6,7 @@ import ( "fmt" "math/big" "strings" - + "time" "cloud.google.com/go/bigquery" "cloud.google.com/go/civil" ) @@ -48,6 +48,8 @@ func ConvertColumnValue(v bigquery.Value, fieldSchema *bigquery.FieldSchema) (dr return v.(bool), nil case "TIME": return bigquery.CivilTimeString(v.(civil.Time)), nil + case "TIMESTAMP": + return v.(time.Time), nil case "DATE": res := v.(civil.Date) if !res.IsValid() { diff --git a/pkg/bigquery/driver/utils_test.go b/pkg/bigquery/driver/utils_test.go index 9995237..f1f4e2b 100644 --- a/pkg/bigquery/driver/utils_test.go +++ b/pkg/bigquery/driver/utils_test.go @@ -5,6 +5,7 @@ import ( "fmt" "math/big" "testing" + "time" "cloud.google.com/go/bigquery" "cloud.google.com/go/civil" @@ -365,6 +366,22 @@ func Test_ConvertColumnValue(t *testing.T) { expectedType: "[]interface {}", expectedValue: "[null,{\"col1\":2,\"col2\":2.99999,\"col3\":\"text value 2\",\"col4\":\"02:02:02\",\"col5\":\"2019-02-02 01:01:01\"}]", }, + { + name: "TIMESTAMP", + value: bigquery.Value(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)), + columnType: "TIMESTAMP", + schema: &bigquery.FieldSchema{Type: "TIMESTAMP"}, + expectedType: "string", + expectedValue: "2009-11-10 23:00:00.000000 UTC", + }, + { + name: "TIMESTAMP repeated", + value: bigquery.Value([]bigquery.Value{time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC), time.Date(2019, time.November, 10, 23, 30, 0, 0, time.UTC)}), + columnType: "TIMESTAMP", + schema: &bigquery.FieldSchema{Type: "TIMESTAMP", Repeated: true}, + expectedType: "string", + expectedValue: "2009-11-10 23:00:00.000000 UTC,2019-11-10 23:30:00.000000 UTC", + }, } for _, tt := range tests {