Skip to content

Commit

Permalink
Handle empty schemas better
Browse files Browse the repository at this point in the history
On Athena, referencing a NULL as a struct does not work (but it does in
DuckDB, annoyingly - so this is hard to unit test).

Rule of thumb: don't have any bare "NULL AS field_name" lines - always
have a CAST(NULL AS ...) bit there.
  • Loading branch information
mikix committed Dec 4, 2024
1 parent aacc0ea commit 22965df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tmp_attachment_flat AS (
{% if schema["content"]["attachment"] %}
u.content.attachment.contenttype
{% else %}
NULL AS contenttype
CAST(NULL AS VARCHAR) AS contenttype
{% endif %}

FROM {{ src }},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@

WITH

{% if schema["content"]["format"] %}
tmp_content_flat AS (
SELECT
id,

{% if schema["content"]["format"] %}
u.content.format
{% else %}
NULL AS format
{% endif %}

FROM {{ src }},
UNNEST(content) AS u (content)
),
Expand All @@ -27,6 +22,11 @@ tmp_content_grouped AS (
FROM tmp_content_flat
GROUP BY id
),
{% else %}
tmp_content_grouped AS (
SELECT id, FALSE AS valid_format FROM {{ src }} WHERE 1=0 -- return an empty table
),
{% endif %}

tmp_encounters AS (
SELECT
Expand Down

0 comments on commit 22965df

Please sign in to comment.