diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index d1175352e9..80cc618eb0 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -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() diff --git a/superset/sql_lab.py b/superset/sql_lab.py index dba3beff36..5ee6546819 100644 --- a/superset/sql_lab.py +++ b/superset/sql_lab.py @@ -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)