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

Add quoting support #131

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion dbt/adapters/athena/relation.py
Expand Up @@ -13,9 +13,24 @@ class AthenaIncludePolicy(Policy):

@dataclass(frozen=True, eq=False, repr=False)
class AthenaRelation(BaseRelation):
quote_character: str = ""
quote_character: str = '"' # Presto quote character
include_policy: Policy = AthenaIncludePolicy()

def render_hive(self):
"""
Render relation with Hive format. Athena uses Hive format for some DDL statements.

See:
- https://aws.amazon.com/athena/faqs/ "Q: How do I create tables and schemas for my data on Amazon S3?"
- https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL
"""

old_value = self.quote_character
object.__setattr__(self, 'quote_character', "`") # Hive quote char
rendered = self.render()
object.__setattr__(self, 'quote_character', old_value)
return rendered

class AthenaSchemaSearchMap(Dict[InformationSchema, Dict[str, Set[Optional[str]]]]):
"""A utility class to keep track of what information_schema tables to
search for what schemas and relations. The schema and relation values are all
Expand Down
5 changes: 4 additions & 1 deletion dbt/include/athena/macros/adapters/relation.sql
Expand Up @@ -3,6 +3,9 @@
{%- do adapter.clean_up_table(relation.schema, relation.table) -%}
{% endif %}
{% call statement('drop_relation', auto_begin=False) -%}
drop {{ relation.type }} if exists {{ relation }}
drop {{ relation.type }} if exists
{%- if relation.type == 'table' %} {{ relation.render_hive() -}}
{%- else %} {{ relation -}}
{%- endif -%}
{%- endcall %}
{% endmacro %}
12 changes: 12 additions & 0 deletions dbt/include/athena/macros/adapters/schema.sql
@@ -0,0 +1,12 @@
{% macro default__create_schema(relation) -%}
{%- call statement('create_schema') -%}
create schema if not exists {{ relation.without_identifier().render_hive() }}
{% endcall %}
{% endmacro %}


{% macro default__drop_schema(relation) -%}
{%- call statement('drop_schema') -%}
drop schema if exists {{ relation.without_identifier().render_hive() }} cascade
{% endcall %}
{% endmacro %}
Expand Up @@ -2,6 +2,6 @@
{%- set format = config.get('format', default=default_value) -%}

{% call statement('set_table_classification', auto_begin=False) -%}
alter table {{ relation }} set tblproperties ('classification' = '{{ format }}')
alter table {{ relation.render_hive() }} set tblproperties ('classification' = '{{ format }}')
{%- endcall %}
{%- endmacro %}
Expand Up @@ -12,7 +12,7 @@
{%- set quote_seed_column = model['config'].get('quote_columns', None) -%}

{% set sql %}
create external table {{ this.render() }} (
create external table {{ this.render_hive() }} (
{%- for col_name in agate_table.column_names -%}
{%- set inferred_type = adapter.convert_type(agate_table, loop.index0) -%}
{%- set type = column_override.get(col_name, inferred_type) -%}
Expand Down