Skip to content

Commit

Permalink
feat(bigquery): support type alias names for numeric/bignumeric schem…
Browse files Browse the repository at this point in the history
…as. (#3760)
  • Loading branch information
shollyman authored Mar 2, 2021
1 parent 94a6850 commit 2ee6bf4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions bigquery/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ var (
}
// The API will accept alias names for the types based on the Standard SQL type names.
fieldAliases = map[FieldType]FieldType{
"BOOL": BooleanFieldType,
"FLOAT64": FloatFieldType,
"INT64": IntegerFieldType,
"STRUCT": RecordFieldType,
"BOOL": BooleanFieldType,
"FLOAT64": FloatFieldType,
"INT64": IntegerFieldType,
"STRUCT": RecordFieldType,
"DECIMAL": NumericFieldType,
"BIGDECIMAL": BigNumericFieldType,
}
)

Expand Down
4 changes: 3 additions & 1 deletion bigquery/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,8 @@ func TestSchemaFromJSON(t *testing.T) {
{"name":"aliased_integer","type":"INT64","mode":"REQUIRED","description":"Aliased required integer"},
{"name":"aliased_boolean","type":"BOOL","mode":"NULLABLE","description":"Aliased nullable boolean"},
{"name":"aliased_float","type":"FLOAT64","mode":"REQUIRED","description":"Aliased required float"},
{"name":"aliased_record","type":"STRUCT","mode":"NULLABLE","description":"Aliased nullable record"}
{"name":"aliased_record","type":"STRUCT","mode":"NULLABLE","description":"Aliased nullable record"},
{"name":"aliased_bignumeric","type":"BIGDECIMAL","mode":"NULLABLE","description":"Aliased nullable bignumeric"}
]`),
expectedSchema: Schema{
fieldSchema("Flat nullable string", "flat_string", "STRING", false, false, nil),
Expand All @@ -1066,6 +1067,7 @@ func TestSchemaFromJSON(t *testing.T) {
fieldSchema("Aliased nullable boolean", "aliased_boolean", "BOOLEAN", false, false, nil),
fieldSchema("Aliased required float", "aliased_float", "FLOAT", false, true, nil),
fieldSchema("Aliased nullable record", "aliased_record", "RECORD", false, false, nil),
fieldSchema("Aliased nullable bignumeric", "aliased_bignumeric", "BIGNUMERIC", false, false, nil),
},
},
{
Expand Down

0 comments on commit 2ee6bf4

Please sign in to comment.