Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BQ Plugin needs to support JSON and TIMESTAMP data types #304

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/bigquery/driver/rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion pkg/bigquery/driver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"math/big"
"strings"

"time"
"cloud.google.com/go/bigquery"
"cloud.google.com/go/civil"
)
Expand Down Expand Up @@ -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() {
Expand Down
17 changes: 17 additions & 0 deletions pkg/bigquery/driver/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"testing"
"time"

"cloud.google.com/go/bigquery"
"cloud.google.com/go/civil"
Expand Down Expand Up @@ -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 {
Expand Down