Skip to content

Commit

Permalink
Quote local parquet CTAS queries
Browse files Browse the repository at this point in the history
  • Loading branch information
dogversioning committed Nov 11, 2024
1 parent b6483c5 commit b238d99
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 4 additions & 2 deletions cumulus_library/template_sql/ctas_from_parquet.sql.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
{%- if db_type == 'athena' -%}
CREATE EXTERNAL TABLE IF NOT EXISTS `{{ schema_name }}`.`{{ table_name }}` (
{%- elif db_type == 'duckdb' -%}
CREATE TABLE IF NOT EXISTS {{ table_name }} AS SELECT
CREATE TABLE IF NOT EXISTS "{{ table_name }}" AS SELECT
{%- endif %}
{%- for col in table_cols %}
{{ col }}{% if db_type == 'athena' %} {{ remote_table_cols_types[loop.index0] }}{%- endif -%}
{%- if db_type == 'athena' %} {{ col }} {{ remote_table_cols_types[loop.index0] }}
{%- elif db_type == 'duckdb' %} "{{ col }}"
{%- endif -%}
{{- syntax.comma_delineate(loop) }}
{%- endfor %}
{%- if db_type == 'athena' %}
Expand Down
8 changes: 2 additions & 6 deletions tests/test_base_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,7 @@ def test_ctas_empty_query_creation(expected, schema, table, cols, types):
"expected,db_type,schema,table,cols,remote_types",
[
(
"""CREATE EXTERNAL TABLE IF NOT EXISTS `test_athena`.`remote_table` (
a String,
b Int
"""CREATE EXTERNAL TABLE IF NOT EXISTS `test_athena`.`remote_table` ( a String, b Int
)
STORED AS PARQUET
LOCATION 's3://bucket/data/'
Expand All @@ -559,9 +557,7 @@ def test_ctas_empty_query_creation(expected, schema, table, cols, types):
["String", "Int"],
),
(
"""CREATE TABLE IF NOT EXISTS local_table AS SELECT
a,
b
"""CREATE TABLE IF NOT EXISTS "local_table" AS SELECT "a", "b"
FROM read_parquet('./tests/test_data/*.parquet')""",
"duckdb",
"test_duckdb",
Expand Down

0 comments on commit b238d99

Please sign in to comment.