Skip to content

Commit

Permalink
Fix filter values populating for views
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed May 25, 2017
1 parent a4a2bf7 commit 435d5e7
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,9 @@ def values_for_column(self, column_name, limit=10000):
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:
Expand Down Expand Up @@ -338,6 +337,15 @@ def get_sqla_table(self):
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,
Expand Down Expand Up @@ -436,12 +444,7 @@ def get_sqla_query( # sqla
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)
Expand Down

0 comments on commit 435d5e7

Please sign in to comment.