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

Prepend "-- " to default query_comment #64

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions dbt/adapters/athena/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dbt.adapters.athena.connections import AthenaConnectionManager
from dbt.adapters.athena.connections import AthenaCredentials
from dbt.adapters.athena.impl import AthenaAdapter
import dbt.adapters.athena.query_headers

from dbt.adapters.base import AdapterPlugin
from dbt.include import athena
Expand Down
27 changes: 27 additions & 0 deletions dbt/adapters/athena/query_headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import dbt.adapters.base.query_headers

class _QueryComment(dbt.adapters.base.query_headers._QueryComment):
"""
Athena DDL does not always respect /* ... */ block quotations.
This function is the same as _QueryComment.add except that
a leading "-- " is prepended to the query_comment and any newlines
in the query_comment are replaced with " ". This allows the default
query_comment to be added to `create external table` statements.
"""
def add(self, sql: str) -> str:
if not self.query_comment:
return sql

if self.append:
# replace last ';' with '<comment>;'
sql = sql.rstrip()
if sql[-1] == ";":
daniel-cortez-stevenson marked this conversation as resolved.
Show resolved Hide resolved
sql = sql[:-1]
return "{}\n-- /* {} */;".format(sql, self.query_comment.strip().replace("\n", " "))
daniel-cortez-stevenson marked this conversation as resolved.
Show resolved Hide resolved

return "{}\n-- /* {} */".format(sql, self.query_comment.strip().replace("\n", " "))

return "-- /* {} */\n{}".format(self.query_comment.strip().replace("\n", " "), sql)


dbt.adapters.base.query_headers._QueryComment = _QueryComment