Fix filter values populating for views (#2816)

This commit is contained in:
Maxime Beauchemin 2017-05-30 10:51:34 -07:00 committed by GitHub
parent dfbba84400
commit 4ffc1f613e
1 changed files with 11 additions and 8 deletions

View File

@ -292,10 +292,9 @@ class SqlaTable(Model, BaseDatasource):
cols = {col.column_name: col for col in self.columns}
target_col = cols[column_name]
tbl = self.get_sqla_table()
qry = (
select([target_col.sqla_col])
.select_from(tbl)
.select_from(self.get_from_clause())
.distinct(column_name)
)
if limit:
@ -338,6 +337,15 @@ class SqlaTable(Model, BaseDatasource):
tbl.schema = self.schema
return tbl
def get_from_clause(self):
# Supporting arbitrary SQL statements in place of tables
if self.sql:
tp = self.get_template_processor()
from_sql = tp.process_template(self.sql)
return TextAsFrom(sa.text(from_sql), []).alias('expr_qry')
return self.get_sqla_table()
def get_sqla_query( # sqla
self,
groupby, metrics,
@ -436,12 +444,7 @@ class SqlaTable(Model, BaseDatasource):
select_exprs += metrics_exprs
qry = sa.select(select_exprs)
# Supporting arbitrary SQL statements in place of tables
if self.sql:
from_sql = template_processor.process_template(self.sql)
tbl = TextAsFrom(sa.text(from_sql), []).alias('expr_qry')
else:
tbl = self.get_sqla_table()
tbl = self.get_from_clause()
if not columns:
qry = qry.group_by(*groupby_exprs)