From ebf081d0de49df5e77b4ee2f9132b849ed3c8e3a Mon Sep 17 00:00:00 2001 From: Shruti Hegde <189654939+hegdeshruti23@users.noreply.github.com> Date: Tue, 26 Nov 2024 22:56:51 +0530 Subject: [PATCH 1/2] support-more-datatypes BQ Plugin needs to support JSON and TIMESTAMP data types --- pkg/bigquery/driver/rows.go | 2 +- pkg/bigquery/driver/utils.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/bigquery/driver/rows.go b/pkg/bigquery/driver/rows.go index 3c893c5b..952417e9 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 9ef12275..152e04fe 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() { From d962eb19c09759e053f602c71678d6e38187456e Mon Sep 17 00:00:00 2001 From: Shruti Hegde <189654939+hegdeshruti23@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:18:22 +0530 Subject: [PATCH 2/2] Update utils_test.go Adding test cases --- pkg/bigquery/driver/utils_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/bigquery/driver/utils_test.go b/pkg/bigquery/driver/utils_test.go index 9995237f..f1f4e2bb 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 {