zhaoyongjie commented on code in PR #21729: URL: https://github.com/apache/superset/pull/21729#discussion_r990706488
########## superset/connectors/sqla/models.py: ########## @@ -1438,15 +1438,24 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma select_exprs.append(outer) elif columns: for selected in columns: + if is_adhoc_column(selected): + sql = selected.get("sqlExpression") or "" + column_label = selected.get("label") or "" + elif isinstance(selected, str): + sql = selected + column_label = selected + selected = validate_adhoc_subquery( - selected, + sql, self.database_id, self.schema, ) select_exprs.append( columns_by_name[selected].get_sqla_col() - if selected in columns_by_name - else self.make_sqla_column_compatible(literal_column(selected)) + if not is_adhoc_column(selected) and selected in columns_by_name Review Comment: keeping the same logic as previous ``` if instance(selected, str) and selected in columns_by_name ``` ########## superset/connectors/sqla/models.py: ########## @@ -1314,7 +1315,6 @@ 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 } - Review Comment: keep the black line. ########## superset/connectors/sqla/models.py: ########## @@ -1438,15 +1438,24 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma select_exprs.append(outer) elif columns: for selected in columns: + if is_adhoc_column(selected): + sql = selected.get("sqlExpression") or "" Review Comment: @mayurnewase, I looked at the codebase then I think the `is_adhoc_column` should change to like below. ``` def is_adhoc_column(column: Column) -> TypeGuard[AdhocColumn]: return isinstance(column, dict) and ({"label", "sqlExpression"}).issubset(column.keys()) ``` Since the columns are either `AdhocColumn` or `string type`, the condition express should be ``` if is_adhoc_column(selected): _sql = selected.get("sqlExpression") # the `get_sqla_query` has too many statements so we should avoid naming conflict. _column_label = selected.get("label") else: .... ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org