Skip to content

Commit

Permalink
fix: set allow filter_select for Query objects in Explore (#20754)
Browse files Browse the repository at this point in the history
* set allow filter select

* add small comment

* add better logic

* remove condition and reference it in backend
  • Loading branch information
hughhhh committed Jul 20, 2022
1 parent 9c7bcfc commit 81bd496
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,38 @@ def _get_top_groups(

return or_(*groups)

def values_for_column(self, column_name: str, limit: int = 10000) -> List[Any]:
"""Runs query against sqla to retrieve some
sample values for the given column.
"""
cols = {}
for col in self.columns:
if isinstance(col, dict):
cols[col.get("column_name")] = col
else:
cols[col.column_name] = col

target_col = cols[column_name]
tp = None # todo(hughhhh): add back self.get_template_processor()
tbl, cte = self.get_from_clause(tp)

if isinstance(target_col, dict):
sql_column = sa.column(target_col.get("name"))
else:
sql_column = target_col

qry = sa.select([sql_column]).select_from(tbl).distinct()
if limit:
qry = qry.limit(limit)

engine = self.database.get_sqla_engine()
sql = qry.compile(engine, compile_kwargs={"literal_binds": True})
sql = self._apply_cte(sql, cte)
sql = self.mutate_query_from_config(sql)

df = pd.read_sql_query(sql=sql, con=engine)
return df[column_name].to_list()

def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
self,
apply_fetch_values_predicate: bool = False,
Expand Down
1 change: 1 addition & 0 deletions superset/models/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def columns(self) -> List[ResultSetColumnType]:
@property
def data(self) -> Dict[str, Any]:
return {
"filter_select": True,
"name": self.tab_name,
"columns": self.columns,
"metrics": [],
Expand Down

0 comments on commit 81bd496

Please sign in to comment.