You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2023/04/22 22:57:29 UTC

[superset] branch master updated: fix: [chart power query] error show when user input column with x-axis (#23776)

This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 669e1802a6 fix: [chart power query] error show when user input column with x-axis (#23776)
669e1802a6 is described below

commit 669e1802a602f36005c130f11d46d1fa9f72dd44
Author: Hugh A. Miles II <hu...@gmail.com>
AuthorDate: Sat Apr 22 18:57:20 2023 -0400

    fix: [chart power query] error show when user input column with x-axis (#23776)
---
 superset/models/sql_lab.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/superset/models/sql_lab.py b/superset/models/sql_lab.py
index d37ed440db..b2f0c8c1ed 100644
--- a/superset/models/sql_lab.py
+++ b/superset/models/sql_lab.py
@@ -41,6 +41,7 @@ from sqlalchemy import (
 )
 from sqlalchemy.engine.url import URL
 from sqlalchemy.orm import backref, relationship
+from sqlalchemy.sql.elements import ColumnElement, literal_column
 
 from superset import security_manager
 from superset.jinja_context import BaseTemplateProcessor, get_template_processor
@@ -52,7 +53,7 @@ from superset.models.helpers import (
 )
 from superset.sql_parse import CtasMethod, ParsedQuery, Table
 from superset.sqllab.limiting_factor import LimitingFactor
-from superset.utils.core import QueryStatus, user_label
+from superset.utils.core import get_column_name, QueryStatus, user_label
 
 if TYPE_CHECKING:
     from superset.connectors.sqla.models import TableColumn
@@ -329,6 +330,29 @@ class Query(
                 return col
         return None
 
+    def adhoc_column_to_sqla(
+        self,
+        col: "AdhocColumn",  # type: ignore
+        force_type_check: bool = False,
+        template_processor: Optional[BaseTemplateProcessor] = None,
+    ) -> ColumnElement:
+        """
+        Turn an adhoc column into a sqlalchemy column.
+        :param col: Adhoc column definition
+        :param template_processor: template_processor instance
+        :returns: The metric defined as a sqlalchemy column
+        :rtype: sqlalchemy.sql.column
+        """
+        label = get_column_name(col)
+        expression = self._process_sql_expression(
+            expression=col["sqlExpression"],
+            database_id=self.database_id,
+            schema=self.schema,
+            template_processor=template_processor,
+        )
+        sqla_column = literal_column(expression)
+        return self.make_sqla_column_compatible(sqla_column, label)
+
 
 class SavedQuery(Model, AuditMixinNullable, ExtraJSONMixin, ImportExportMixin):
     """ORM model for SQL query"""