codeant-ai-for-open-source[bot] commented on code in PR #44712:
URL: https://github.com/apache/superset/pull/44712#discussion_r4111706815
##########
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:
**Suggestion:** For bare four-digit year columns, `{col}` remains numeric,
so `DAYOFYEAR({col})` receives an integer and produces invalid or incorrect
Kylin SQL.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Type error`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9aa34ff992ef4ec280176d631c40aa7c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9aa34ff992ef4ec280176d631c40aa7c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/db_engine_specs/kylin.py
**Line:** 78:80
**Comment:**
*Type Error: For bare four-digit year columns, `{col}` remains numeric,
so `DAYOFYEAR({col})` receives an integer and produces invalid or incorrect
Kylin SQL.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44712&comment_hash=cfefcd094eccfd0f3e0a4b20007a8d8d691e77b1296448574144c2e15f8c55cb&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44712&comment_hash=cfefcd094eccfd0f3e0a4b20007a8d8d691e77b1296448574144c2e15f8c55cb&reaction=dislike'>๐</a>
--
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]