mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
[sqllab] adding a sql preprocessor for Presto (#1670)
* [sqllab] adding a sql preprocessor for Presto * fixing tests
This commit is contained in:
parent
b370ef0229
commit
cef4a8296a
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user