Skip to content

Commit

Permalink
[sqllab] adding a sql preprocessor for Presto (#1670)
Browse files Browse the repository at this point in the history
* [sqllab] adding a sql preprocessor for Presto

* fixing tests
  • Loading branch information
mistercrunch authored Nov 23, 2016
1 parent b370ef0 commit cef4a82
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def handle_cursor(cls, cursor, query, session):
query object"""
pass

@classmethod
def sql_preprocessor(cls, sql):
"""If the SQL needs to be altered prior to running it
For example Presto needs to double `%` characters
"""
return sql


class PostgresEngineSpec(BaseEngineSpec):
engine = 'postgresql'
Expand Down Expand Up @@ -172,6 +180,10 @@ class PrestoEngineSpec(BaseEngineSpec):
"date_add('day', 1, CAST({col} AS TIMESTAMP))))"),
)

@classmethod
def sql_preprocessor(cls, sql):
return sql.replace('%', '%%')

@classmethod
def convert_dttm(cls, target_type, dttm):
tt = target_type.upper()
Expand Down
1 change: 1 addition & 0 deletions superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def handle_error(msg):
template_processor = get_template_processor(
database=database, query=query)
executed_sql = template_processor.process_template(executed_sql)
executed_sql = db_engine_spec.sql_preprocessor(executed_sql)
except Exception as e:
logging.exception(e)
msg = "Template rendering failed: " + utils.error_msg_from_exception(e)
Expand Down

0 comments on commit cef4a82

Please sign in to comment.