Skip to content

Commit

Permalink
Edge case for object properties with empty schemas (#86)
Browse files Browse the repository at this point in the history
Co-authored-by: Ruben Vereecken <[email protected]>
  • Loading branch information
rubenvereecken and Ruben Vereecken authored May 23, 2024
1 parent 654920c commit f48f1d4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion target_bigquery/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,15 @@ def _translate_record_to_bigquery_schema(
self, name: str, schema_property: dict, mode: str = "NULLABLE"
) -> SchemaField:
"""Translate a JSON schema record into a BigQuery schema."""
properties = list(schema_property.get("properties", {}).items())

# If no properties defined, store as JSON instead of RECORD
if len(properties) == 0:
return SchemaField(name, "JSON", mode)

fields = [
self._jsonschema_property_to_bigquery_column(col, t)
for col, t in schema_property.get("properties", {}).items()
for col, t in properties
]
return SchemaField(name, "RECORD", mode, fields=fields)

Expand Down

0 comments on commit f48f1d4

Please sign in to comment.