bito-code-review[bot] commented on code in PR #44712:
URL: https://github.com/apache/superset/pull/44712#discussion_r4111763649


##########
superset/db_engine_specs/kylin.py:
##########
@@ -46,18 +46,52 @@ class KylinEngineSpec(BaseEngineSpec):  # pylint: 
disable=abstract-method
         "default_port": 7070,
     }
 
+    # Kylin validates every query with Calcite; queries no cube can answer are
+    # pushed down as SQL text to Spark SQL. ``FLOOR(<ts> TO <unit>)`` cannot be
+    # parsed by Spark, so the grains only use CAST, TIMESTAMPADD and field
+    # functions, which both paths accept. Weeks start on Sunday (DAYOFWEEK is 1
+    # for Sunday on both paths).
     _time_grain_expressions = {
         None: "{col}",
-        TimeGrain.SECOND: "CAST(FLOOR(CAST({col} AS TIMESTAMP) TO SECOND) AS 
TIMESTAMP)",  # noqa: E501
-        TimeGrain.MINUTE: "CAST(FLOOR(CAST({col} AS TIMESTAMP) TO MINUTE) AS 
TIMESTAMP)",  # noqa: E501
-        TimeGrain.HOUR: "CAST(FLOOR(CAST({col} AS TIMESTAMP) TO HOUR) AS 
TIMESTAMP)",
-        TimeGrain.DAY: "CAST(FLOOR(CAST({col} AS TIMESTAMP) TO DAY) AS DATE)",
-        TimeGrain.WEEK: "CAST(FLOOR(CAST({col} AS TIMESTAMP) TO WEEK) AS 
DATE)",
-        TimeGrain.MONTH: "CAST(FLOOR(CAST({col} AS TIMESTAMP) TO MONTH) AS 
DATE)",
-        TimeGrain.QUARTER: "CAST(FLOOR(CAST({col} AS TIMESTAMP) TO QUARTER) AS 
DATE)",
-        TimeGrain.YEAR: "CAST(FLOOR(CAST({col} AS TIMESTAMP) TO YEAR) AS 
DATE)",
+        TimeGrain.SECOND: (
+            "TIMESTAMPADD(SECOND, HOUR({col}) * 3600 + MINUTE({col}) * 60"
+            " + SECOND({col}), CAST(CAST({col} AS DATE) AS TIMESTAMP))"
+        ),
+        TimeGrain.MINUTE: (
+            "TIMESTAMPADD(MINUTE, HOUR({col}) * 60 + MINUTE({col}),"
+            " CAST(CAST({col} AS DATE) AS TIMESTAMP))"
+        ),
+        TimeGrain.HOUR: (
+            "TIMESTAMPADD(HOUR, HOUR({col}), CAST(CAST({col} AS DATE) AS 
TIMESTAMP))"
+        ),
+        TimeGrain.DAY: "CAST({col} AS DATE)",
+        TimeGrain.WEEK: (
+            "TIMESTAMPADD(DAY, 1 - DAYOFWEEK({col}), CAST({col} AS DATE))"
+        ),
+        TimeGrain.MONTH: (
+            "TIMESTAMPADD(DAY, 1 - DAYOFMONTH({col}), CAST({col} AS DATE))"
+        ),
+        TimeGrain.QUARTER: (
+            "TIMESTAMPADD(MONTH, 3 * QUARTER({col}) - 3,"
+            " TIMESTAMPADD(DAY, 1 - DAYOFYEAR({col}), CAST({col} AS DATE)))"
+        ),
+        TimeGrain.YEAR: (
+            "TIMESTAMPADD(DAY, 1 - DAYOFYEAR({col}), CAST({col} AS DATE))"

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Grain result type drift</b></div>
   <div id="fix">
   
   The deleted grains explicitly cast to DATE (`CAST(FLOOR(...) AS DATE)`), but 
`TIMESTAMPADD` returns TIMESTAMP, so WEEK/MONTH/QUARTER/YEAR now yield 
TIMESTAMP while DAY still yields DATE. Values are identical (midnight), but the 
changed result type may affect Kylin cube matching and downstream type 
handling. Consider wrapping these four in `CAST(... AS DATE)` for parity.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #cd83de</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



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