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/21 18:23:54 UTC

[superset] branch cpq-x-axis-fix created (now 43d2fcc428)

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

hugh pushed a change to branch cpq-x-axis-fix
in repository https://gitbox.apache.org/repos/asf/superset.git


      at 43d2fcc428 fix x-axis issue for cpq

This branch includes the following new commits:

     new 43d2fcc428 fix x-axis issue for cpq

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[superset] 01/01: fix x-axis issue for cpq

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch cpq-x-axis-fix
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 43d2fcc42854a000e634e68927081d74a2c1ab4e
Author: hughhhh <hu...@gmail.com>
AuthorDate: Fri Apr 21 12:48:46 2023 -0400

    fix x-axis issue for cpq
---
 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"""