This is an automated email from the ASF dual-hosted git repository.
hugh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 81bd4968d0 fix: set allow `filter_select` for Query objects in Explore
(#20754)
81bd4968d0 is described below
commit 81bd4968d0a916cb2a20e47b20e31a1434be4f46
Author: Hugh A. Miles II <[email protected]>
AuthorDate: Wed Jul 20 09:08:02 2022 -0400
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
---
superset/models/helpers.py | 32 ++++++++++++++++++++++++++++++++
superset/models/sql_lab.py | 1 +
2 files changed, 33 insertions(+)
diff --git a/superset/models/helpers.py b/superset/models/helpers.py
index 77707201b5..6cd6d17c7b 100644
--- a/superset/models/helpers.py
+++ b/superset/models/helpers.py
@@ -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,
diff --git a/superset/models/sql_lab.py b/superset/models/sql_lab.py
index e7fd2c3833..22f565032c 100644
--- a/superset/models/sql_lab.py
+++ b/superset/models/sql_lab.py
@@ -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": [],