zhaoyongjie commented on code in PR #21729:
URL: https://github.com/apache/superset/pull/21729#discussion_r990705291


##########
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.
   
   ```
   class AdhocColumn(TypedDict, total=False):
       hasCustomLabel: Optional[bool]
       label: str
       sqlExpression: str
       columnType: Optional[Literal["BASE_AXIS", "SERIES"]]
       timeGrain: Optional[str]
   ...
   ...
   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

Reply via email to