Skip to content

Commit

Permalink
Fix parsing of optional mode field in BigQuery Result Schema (#26786)
Browse files Browse the repository at this point in the history
  • Loading branch information
patricker authored Oct 1, 2022
1 parent b7203cd commit cee610a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion airflow/providers/google/cloud/hooks/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2999,14 +2999,15 @@ def _format_schema_for_description(schema: dict) -> list:
"""
description = []
for field in schema["fields"]:
mode = field.get("mode", "NULLABLE")
field_description = (
field["name"],
field["type"],
None,
None,
None,
None,
field["mode"] == "NULLABLE",
mode == "NULLABLE",
)
description.append(field_description)
return description
Expand Down
8 changes: 7 additions & 1 deletion tests/providers/google/cloud/hooks/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,11 +1255,17 @@ def test_format_schema_for_description(self):
"schema": {
"fields": [
{"name": "field_1", "type": "STRING", "mode": "NULLABLE"},
{"name": "field_2", "type": "STRING"},
{"name": "field_3", "type": "STRING", "mode": "REPEATED"},
]
},
}
description = _format_schema_for_description(test_query_result["schema"])
assert description == [('field_1', 'STRING', None, None, None, None, True)]
assert description == [
('field_1', 'STRING', None, None, None, None, True),
('field_2', 'STRING', None, None, None, None, True),
('field_3', 'STRING', None, None, None, None, False),
]

@mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_service")
@mock.patch("airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.insert_job")
Expand Down

0 comments on commit cee610a

Please sign in to comment.
  翻译: