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

Patch to handle JSON that's not inside an array. #37

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions target_bigquery/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,18 +862,18 @@ def _wrap_json_array(
field, path="$", depth=depth, base=f"{field.name}__rows"
)
v = _v.as_sql().rstrip(", \n")

return (" " * depth * 2) + indent(


# This is a patch to get around the fact that JSON_QUERY_ARRAY doesn't work with
# fields that contain a single JSON blob instead of a an array of JSON blobs.
dedent(
f"""
ARRAY(
SELECT {v}
FROM UNNEST(
JSON_QUERY_ARRAY({base}, '{path}.{field.name}')
) AS {field.name}__rows
WHERE {_v.projection} IS NOT NULL
"""
JSON_QUERY({base}, '{path}.{field.name}')
"""
+ (" " * depth * 2)
+ f") AS {field.name},\n"
+ f" AS {field.name},\n"
).lstrip(),
" " * depth * 2,
)
Expand Down