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


##########
superset/connectors/sqla/models.py:
##########
@@ -1379,15 +1379,23 @@ def get_sqla_query(  # pylint: 
disable=too-many-arguments,too-many-locals,too-ma
                 select_exprs.append(outer)
         elif columns:
             for selected in columns:
-                selected = validate_adhoc_subquery(
-                    selected,
+                selected_query = (
+                    selected["sqlExpression"]
+                    if "sqlExpression" in selected
+                    else selected
+                )
+                label_expected = selected["label"] if "label" in selected else 
selected
+                selected_query = validate_adhoc_subquery(
+                    selected_query,
                     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))
+                    columns_by_name[selected_query].get_sqla_col()
+                    if selected_query in columns_by_name
+                    else self.make_sqla_column_compatible(
+                        literal_column(selected_query), label_expected
+                    )
                 )

Review Comment:
   There is a method for converting AdHoc Column to ColumnClause, for instance:
   
   ```python
                   if is_adhoc_column(selected):
                       select_exprs.append(self.adhoc_column_to_sqla(selected))
                       continue
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to