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


##########
superset/connectors/sqla/models.py:
##########
@@ -1011,7 +1013,7 @@ def adhoc_column_to_sqla(  # pylint: 
disable=too-many-locals
         if is_dttm and has_timegrain:
             sqla_column = self.db_engine_spec.get_timestamp_expr(
                 col=sqla_column,
-                pdf=None,
+                pdf=pdf,

Review Comment:
   @ege-st 
   
   The design of current Pinot DB spec is completely incorrect. Maintaining our 
own Pinot driver and db_spec should solve your issue. 
   
   
   ```python
   class PinotEngineSpec(BaseEngineSpec):  # pylint: disable=abstract-method
       engine = "pinot"
       engine_name = "Apache Pinot"
       allows_subqueries = False
       allows_joins = False
       allows_alias_in_select = True
       allows_alias_in_orderby = False
   
       # 
https://docs.pinot.apache.org/users/user-guide-query/supported-transformations#datetime-functions
       _time_grain_expressions = {
           None: "{col}",
           "PT1S": "CAST(DATE_TRUNC('second', CAST({col} AS TIMESTAMP)) AS 
TIMESTAMP)",
           "PT1M": "CAST(DATE_TRUNC('minute', CAST({col} AS TIMESTAMP)) AS 
TIMESTAMP)",
           "PT5M": "CAST(ROUND(DATE_TRUNC('minute', CAST({col} AS TIMESTAMP)), 
300000) as TIMESTAMP)",
           "PT10M": "CAST(ROUND(DATE_TRUNC('minute', CAST({col} AS TIMESTAMP)), 
600000) as TIMESTAMP)",
           "PT15M": "CAST(ROUND(DATE_TRUNC('minute', CAST({col} AS TIMESTAMP)), 
900000) as TIMESTAMP)",
           "PT30M": "CAST(ROUND(DATE_TRUNC('minute', CAST({col} AS TIMESTAMP)), 
1800000) as TIMESTAMP)",
           "PT1H": "CAST(DATE_TRUNC('hour', CAST({col} AS TIMESTAMP)) AS 
TIMESTAMP)",
           "P1D": "CAST(DATE_TRUNC('day', CAST({col} AS TIMESTAMP)) AS 
TIMESTAMP)",
           "P1W": "CAST(DATE_TRUNC('week', CAST({col} AS TIMESTAMP)) AS 
TIMESTAMP)",
           "P1M": "CAST(DATE_TRUNC('month', CAST({col} AS TIMESTAMP)) AS 
TIMESTAMP)",
           "P3M": "CAST(DATE_TRUNC('quarter', CAST({col} AS TIMESTAMP)) AS 
TIMESTAMP)",
           "P1Y": "CAST(DATE_TRUNC('year', CAST({col} AS TIMESTAMP)) AS 
TIMESTAMP)",
       }
   
       @classmethod
       def column_datatype_to_string(
           cls, sqla_column_type: TypeEngine, dialect: Dialect
       ) -> str:
           # Pinot driver infers TIMESTAMP column as LONG, so make the quick 
fix.
           # When the Pinot driver fix this bug, current method could be 
removed.
           if isinstance(sqla_column_type, types.TIMESTAMP):
               return sqla_column_type.compile().upper()
           else:
               return super().column_datatype_to_string(sqla_column_type, 
dialect)
   
       @staticmethod
       def alias_in_select_mutator(label: str) -> str:
           return f"{label}__"
   
       @classmethod
       def get_timezone_expressions(
           cls,
           col: ColumnClause,
           timezone: typing.Optional[str],
       ) -> ColumnClause:
           if BF_EUROPE_BERLIN_TIMEZONE_COLUMN_SUFFIX in col.name:
               return col
           tpl = f"""
   CAST(
       FROMDATETIME(
           DATETIMECONVERT(
               {col},
               '1:MILLISECONDS:EPOCH',
               '1:MILLISECONDS:SIMPLE_DATE_FORMAT:yyyy-MM-dd HH:mm:ss.SSS 
tz({timezone})',
               '1:MILLISECONDS'
           ),
           'yyyy-MM-dd HH:mm:ss.SSS'
       ) AS TIMESTAMP
   )""".strip()
           return literal_column(tpl)
   ```



-- 
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