Skip to content

Commit

Permalink
revision 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurnewase committed Oct 10, 2022
1 parent c8b20b8 commit 4a6eaa8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 8 additions & 7 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
columns_by_name: Dict[str, TableColumn] = {
col.column_name: col for col in self.columns
}

metrics_by_name: Dict[str, SqlMetric] = {m.metric_name: m for m in self.metrics}

if not granularity and is_timeseries:
Expand Down Expand Up @@ -1439,22 +1440,22 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
elif columns:
for selected in columns:
if is_adhoc_column(selected):
sql = selected.get("sqlExpression") or ""
column_label = selected.get("label") or ""
_sql = selected["sqlExpression"]
_column_label = selected["label"]
elif isinstance(selected, str):
sql = selected
column_label = selected
_sql = selected
_column_label = selected

selected = validate_adhoc_subquery(
sql,
_sql,
self.database_id,
self.schema,
)
select_exprs.append(
columns_by_name[selected].get_sqla_col()
if not is_adhoc_column(selected) and selected in columns_by_name
if isinstance(selected, str) and selected in columns_by_name
else self.make_sqla_column_compatible(
literal_column(selected), column_label
literal_column(selected), _column_label
)
)
metrics_exprs = []
Expand Down
4 changes: 2 additions & 2 deletions superset/superset_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class AdhocMetric(TypedDict, total=False):

class AdhocColumn(TypedDict, total=False):
hasCustomLabel: Optional[bool]
label: Optional[str]
sqlExpression: Optional[str]
label: str
sqlExpression: str
columnType: Optional[Literal["BASE_AXIS", "SERIES"]]
timeGrain: Optional[str]

Expand Down
4 changes: 3 additions & 1 deletion superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,9 @@ def is_adhoc_metric(metric: Metric) -> TypeGuard[AdhocMetric]:


def is_adhoc_column(column: Column) -> TypeGuard[AdhocColumn]:
return isinstance(column, dict)
return isinstance(column, dict) and ({"label", "sqlExpression"}).issubset(
column.keys()
)


def get_base_axis_labels(columns: Optional[List[Column]]) -> Tuple[str, ...]:
Expand Down

0 comments on commit 4a6eaa8

Please sign in to comment.