Skip to content

Commit

Permalink
fix: alias column when fetching values (#26120)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7223633)
  • Loading branch information
betodealmeida authored and michael-s-molina committed Dec 4, 2023
1 parent a3212cc commit 3edbb9f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,13 @@ def values_for_column(self, column_name: str, limit: int = 10000) -> list[Any]:
tbl, cte = self.get_from_clause(tp)

qry = (
sa.select([target_col.get_sqla_col(template_processor=tp)])
sa.select(
# The alias (label) here is important because some dialects will
# automatically add a random alias to the projection because of the
# call to DISTINCT; others will uppercase the column names. This
# gives us a deterministic column name in the dataframe.
[target_col.get_sqla_col(template_processor=tp).label("column_values")]
)
.select_from(tbl)
.distinct()
)
Expand All @@ -1359,7 +1365,7 @@ def values_for_column(self, column_name: str, limit: int = 10000) -> list[Any]:
sql = self.mutate_query_from_config(sql)

df = pd.read_sql_query(sql=sql, con=engine)
return df[denormalized_col_name].to_list()
return df["column_values"].to_list()

def get_timestamp_expression(
self,
Expand Down

0 comments on commit 3edbb9f

Please sign in to comment.