[sqllab] adding a sql preprocessor for Presto (#1670)

* [sqllab] adding a sql preprocessor for Presto

* fixing tests
This commit is contained in:
Maxime Beauchemin 2016-11-22 21:24:38 -08:00 committed by GitHub
parent b370ef0229
commit cef4a8296a
2 changed files with 13 additions and 0 deletions

View File

@ -63,6 +63,14 @@ class BaseEngineSpec(object):
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'
@ -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()

View File

@ -103,6 +103,7 @@ def get_sql_results(self, query_id, return_results=True, store_results=False):
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)