mirror of
https://github.com/apache/superset.git
synced 2024-09-17 11:09:47 -04:00
Add parens for custom where and having (#1337)
This commit is contained in:
parent
b2f7081c6f
commit
458651fa3e
@ -55,7 +55,9 @@ import caravel
|
||||
from caravel import app, db, db_engine_specs, get_session, utils, sm
|
||||
from caravel.source_registry import SourceRegistry
|
||||
from caravel.viz import viz_types
|
||||
from caravel.utils import flasher, MetricPermException, DimSelector
|
||||
from caravel.utils import (
|
||||
flasher, MetricPermException, DimSelector, wrap_clause_in_parens
|
||||
)
|
||||
|
||||
config = app.config
|
||||
|
||||
@ -1005,9 +1007,9 @@ class SqlaTable(Model, Queryable, AuditMixinNullable, ImportMixin):
|
||||
cond = ~cond
|
||||
where_clause_and.append(cond)
|
||||
if extras and 'where' in extras:
|
||||
where_clause_and += [text(extras['where'])]
|
||||
where_clause_and += [wrap_clause_in_parens(extras['where'])]
|
||||
if extras and 'having' in extras:
|
||||
having_clause_and += [text(extras['having'])]
|
||||
having_clause_and += [wrap_clause_in_parens(extras['having'])]
|
||||
if granularity:
|
||||
qry = qry.where(and_(*(time_filter + where_clause_and)))
|
||||
else:
|
||||
|
@ -491,3 +491,10 @@ class timeout(object):
|
||||
except ValueError as e:
|
||||
logging.warning("timeout can't be used in the current context")
|
||||
logging.exception(e)
|
||||
|
||||
|
||||
def wrap_clause_in_parens(sql):
|
||||
"""Wrap where/having clause with parenthesis if necessary"""
|
||||
if sql.strip():
|
||||
sql = '({})'.format(sql)
|
||||
return sa.text(sql)
|
||||
|
Loading…
Reference in New Issue
Block a user