Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Jun 14, 2024
1 parent afa50e3 commit 4bd885e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clients/bigquery/storagewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ func columnToTableFieldSchema(column columns.Column) (*storagepb.TableFieldSchem
case ext.DateTimeKindType:
fieldType = storagepb.TableFieldSchema_TIMESTAMP
default:
return nil, fmt.Errorf("unsupported extended time details type: %s", column.KindDetails.ExtendedTimeDetails.Type)
return nil, fmt.Errorf("unsupported extended time details type: %q", column.KindDetails.ExtendedTimeDetails.Type)
}
case typing.Struct.Kind:
fieldType = storagepb.TableFieldSchema_STRING
case typing.Array.Kind:
fieldType = storagepb.TableFieldSchema_STRING
mode = storagepb.TableFieldSchema_REPEATED
default:
return nil, fmt.Errorf("unsupported column kind: %s", column.KindDetails.Kind)
return nil, fmt.Errorf("unsupported column kind: %q", column.KindDetails.Kind)
}

return &storagepb.TableFieldSchema{
Expand Down
71 changes: 71 additions & 0 deletions clients/bigquery/storagewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"cloud.google.com/go/bigquery/storage/apiv1/storagepb"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/columns"
"github.com/artie-labs/transfer/lib/typing/decimal"
Expand All @@ -14,6 +15,76 @@ import (
"google.golang.org/protobuf/encoding/protojson"
)

func TestColumnToTableFieldSchema(t *testing.T) {
{
// Boolean:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.Boolean))
assert.NoError(t, err)
assert.Equal(t, "foo", fieldSchema.Name)
assert.Equal(t, storagepb.TableFieldSchema_NULLABLE, fieldSchema.Mode)
assert.Equal(t, storagepb.TableFieldSchema_BOOL, fieldSchema.Type)
}
{
// Integer:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.Integer))
assert.NoError(t, err)
assert.Equal(t, storagepb.TableFieldSchema_INT64, fieldSchema.Type)
}
{
// Float:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.Float))
assert.NoError(t, err)
assert.Equal(t, storagepb.TableFieldSchema_DOUBLE, fieldSchema.Type)
}
{
// EDecimal:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.EDecimal))
assert.NoError(t, err)
assert.Equal(t, storagepb.TableFieldSchema_STRING, fieldSchema.Type)
}
{
// ETime - Time:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.NewKindDetailsFromTemplate(typing.ETime, ext.TimeKindType)))
assert.NoError(t, err)
assert.Equal(t, storagepb.TableFieldSchema_TIME, fieldSchema.Type)
}
{
// ETime - Date:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.NewKindDetailsFromTemplate(typing.ETime, ext.DateKindType)))
assert.NoError(t, err)
assert.Equal(t, storagepb.TableFieldSchema_DATE, fieldSchema.Type)
}
{
// ETime - DateTime:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.NewKindDetailsFromTemplate(typing.ETime, ext.DateTimeKindType)))
assert.NoError(t, err)
assert.Equal(t, storagepb.TableFieldSchema_TIMESTAMP, fieldSchema.Type)
}
{
// ETime - Invalid:
_, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.NewKindDetailsFromTemplate(typing.ETime, "")))
assert.ErrorContains(t, err, "unsupported extended time details type:")
}
{
// Struct:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.Struct))
assert.NoError(t, err)
assert.Equal(t, storagepb.TableFieldSchema_STRING, fieldSchema.Type)
}
{
// Array:
fieldSchema, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.Array))
assert.NoError(t, err)
assert.Equal(t, storagepb.TableFieldSchema_STRING, fieldSchema.Type)
assert.Equal(t, storagepb.TableFieldSchema_REPEATED, fieldSchema.Mode)
}
{
// Invalid:
_, err := columnToTableFieldSchema(columns.NewColumn("foo", typing.KindDetails{}))
assert.ErrorContains(t, err, "unsupported column kind: ")
}
}

func TestEncodePacked64TimeMicros(t *testing.T) {
epoch := time.Date(0, 0, 0, 0, 0, 0, 0, time.UTC)

Expand Down

0 comments on commit 4bd885e

Please sign in to comment.