mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix: set allow filter_select for Query objects in Explore (#20754)
* set allow filter select * add small comment * add better logic * remove condition and reference it in backend
This commit is contained in:
@@ -1189,6 +1189,38 @@ class ExploreMixin: # pylint: disable=too-many-public-methods
|
||||
|
||||
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,
|
||||
|
||||
@@ -212,6 +212,7 @@ class Query(Model, ExtraJSONMixin, ExploreMixin): # pylint: disable=abstract-me
|
||||
@property
|
||||
def data(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"filter_select": True,
|
||||
"name": self.tab_name,
|
||||
"columns": self.columns,
|
||||
"metrics": [],
|
||||
|
||||
Reference in New Issue
Block a user