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

feat(bigquery): support type alias names for numeric/bignumeric schemas #3760

Merged
merged 2 commits into from Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions bigquery/schema.go
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
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