Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: set allow filter_select for Query objects in Explore #20754

Merged
merged 4 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ const AdhocFilterEditPopoverSimpleTabContent: React.FC<Props> = props => {
const col = props.adhocFilter.subject;
const having = props.adhocFilter.clause === CLAUSES.HAVING;

if (col && datasource && datasource.filter_select && !having) {
if (col && datasource?.filter_select !== false && !having) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are adding the "filter_select": true in sql_lab.py we can remove this change. If we keep this change we don't need to make the change in sql_lab.py.

If we do keep this change, I realized we should actually do a check on datasource because datasource. operations are used within the if block. so recommend changing to this this:

if (col && datasource && datasource.filter_select !== false && !having) {

const controller = new AbortController();
const { signal } = controller;
if (loadingComparatorSuggestions) {
Expand Down
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]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that a better idea here is to use the Max display limit.

"""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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to my comment in the frontend change. If we add this here, the frontend change should not be needed.

"name": self.tab_name,
"columns": self.columns,
"metrics": [],
Expand Down