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/12 17:52:03 UTC

[superset] branch fix-preset-ci created (now 4fe2decff7)

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

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


      at 4fe2decff7 ok testing

This branch includes the following new commits:

     new 4fe2decff7 ok testing

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: ok testing

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

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

commit 4fe2decff78ac5c25a1fdf009b6517252e12e64f
Author: hughhhh <hu...@gmail.com>
AuthorDate: Wed Apr 12 13:51:33 2023 -0400

    ok testing
---
 superset/connectors/sqla/models.py | 58 +++++++++++++++++++-------------------
 superset/models/helpers.py         | 24 +++++++++++++---
 2 files changed, 49 insertions(+), 33 deletions(-)

diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index 6180a546e7..c1a8336f20 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -379,35 +379,35 @@ class TableColumn(Model, BaseColumn, CertificationMixin):
         time_expr = self.db_engine_spec.get_timestamp_expr(col, pdf, time_grain)
         return self.table.make_sqla_column_compatible(time_expr, label)
 
-    def dttm_sql_literal(self, dttm: DateTime) -> str:
-        """Convert datetime object to a SQL expression string"""
-        sql = (
-            self.db_engine_spec.convert_dttm(self.type, dttm, db_extra=self.db_extra)
-            if self.type
-            else None
-        )
-
-        if sql:
-            return sql
-
-        tf = self.python_date_format
-
-        # Fallback to the default format (if defined).
-        if not tf:
-            tf = self.db_extra.get("python_date_format_by_column_name", {}).get(
-                self.column_name
-            )
-
-        if tf:
-            if tf in ["epoch_ms", "epoch_s"]:
-                seconds_since_epoch = int(dttm.timestamp())
-                if tf == "epoch_s":
-                    return str(seconds_since_epoch)
-                return str(seconds_since_epoch * 1000)
-            return f"'{dttm.strftime(tf)}'"
-
-        # TODO(john-bodley): SIP-15 will explicitly require a type conversion.
-        return f"""'{dttm.strftime("%Y-%m-%d %H:%M:%S.%f")}'"""
+    # def dttm_sql_literal(self, dttm: DateTime) -> str:
+    #     """Convert datetime object to a SQL expression string"""
+    #     sql = (
+    #         self.db_engine_spec.convert_dttm(self.type, dttm, db_extra=self.db_extra)
+    #         if self.type
+    #         else None
+    #     )
+
+    #     if sql:
+    #         return sql
+
+    #     tf = self.python_date_format
+
+    #     # Fallback to the default format (if defined).
+    #     if not tf:
+    #         tf = self.db_extra.get("python_date_format_by_column_name", {}).get(
+    #             self.column_name
+    #         )
+
+    #     if tf:
+    #         if tf in ["epoch_ms", "epoch_s"]:
+    #             seconds_since_epoch = int(dttm.timestamp())
+    #             if tf == "epoch_s":
+    #                 return str(seconds_since_epoch)
+    #             return str(seconds_since_epoch * 1000)
+    #         return f"'{dttm.strftime(tf)}'"
+
+    #     # TODO(john-bodley): SIP-15 will explicitly require a type conversion.
+    #     return f"""'{dttm.strftime("%Y-%m-%d %H:%M:%S.%f")}'"""
 
     @property
     def data(self) -> Dict[str, Any]:
diff --git a/superset/models/helpers.py b/superset/models/helpers.py
index cc3b34ae62..38d04def69 100644
--- a/superset/models/helpers.py
+++ b/superset/models/helpers.py
@@ -1304,17 +1304,33 @@ class ExploreMixin:  # pylint: disable=too-many-public-methods
 
     def dttm_sql_literal(self, dttm: sa.DateTime, col_type: Optional[str]) -> str:
         """Convert datetime object to a SQL expression string"""
-
         sql = (
-            self.db_engine_spec.convert_dttm(col_type, dttm, db_extra=None)
-            if col_type
+            self.db_engine_spec.convert_dttm(self.type, dttm, db_extra=self.db_extra)
+            if self.type
             else None
         )
 
         if sql:
             return sql
 
-        return f'{dttm.strftime("%Y-%m-%d %H:%M:%S.%f")}'
+        tf = self.python_date_format
+
+        # Fallback to the default format (if defined).
+        if not tf:
+            tf = self.db_extra.get("python_date_format_by_column_name", {}).get(
+                self.column_name
+            )
+
+        if tf:
+            if tf in ["epoch_ms", "epoch_s"]:
+                seconds_since_epoch = int(dttm.timestamp())
+                if tf == "epoch_s":
+                    return str(seconds_since_epoch)
+                return str(seconds_since_epoch * 1000)
+            return f"'{dttm.strftime(tf)}'"
+
+        # TODO(john-bodley): SIP-15 will explicitly require a type conversion.
+        return f"""'{dttm.strftime("%Y-%m-%d %H:%M:%S.%f")}'"""
 
     def get_time_filter(  # pylint: disable=too-many-arguments
         self,