Skip to content

Commit

Permalink
fix(chart-filter): Avoid column denormalization if not enabled (apach…
Browse files Browse the repository at this point in the history
…e#26199)

(cherry picked from commit 05d7060)
  • Loading branch information
Vitor-Avila authored and josedev-union committed Jan 22, 2024
1 parent be900c8 commit 581877c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion superset/datasource/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ def get_column_values(
return self.response(403, message=ex.message)

row_limit = apply_max_row_limit(app.config["FILTER_SELECT_ROW_LIMIT"])
denormalize_column = not datasource.normalize_columns
try:
payload = datasource.values_for_column(
column_name=column_name, limit=row_limit
column_name=column_name,
limit=row_limit,
denormalize_column=denormalize_column,
)
return self.response(200, result=payload)
except KeyError:
Expand Down
17 changes: 11 additions & 6 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ def get_fetch_values_predicate(
self,
template_processor: Optional[ # pylint: disable=unused-argument
BaseTemplateProcessor
] = None, # pylint: disable=unused-argument
] = None,
) -> TextClause:
return self.fetch_values_predicate

Expand Down Expand Up @@ -1340,14 +1340,19 @@ def get_time_filter( # pylint: disable=too-many-arguments
)
return and_(*l)

def values_for_column(self, column_name: str, limit: int = 10000) -> list[Any]:
# always denormalize column name before querying for values
def values_for_column(
self, column_name: str, limit: int = 10000, denormalize_column: bool = False
) -> list[Any]:
# denormalize column name before querying for values
# unless disabled in the dataset configuration
db_dialect = self.database.get_dialect()
denormalized_col_name = self.database.db_engine_spec.denormalize_name(
db_dialect, column_name
column_name_ = (
self.database.db_engine_spec.denormalize_name(db_dialect, column_name)
if denormalize_column
else column_name
)
cols = {col.column_name: col for col in self.columns}
target_col = cols[denormalized_col_name]
target_col = cols[column_name_]
tp = self.get_template_processor()
tbl, cte = self.get_from_clause(tp)

Expand Down

0 comments on commit 581877c

Please sign in to comment.