codeant-ai-for-open-source[bot] commented on code in PR #42095:
URL: https://github.com/apache/superset/pull/42095#discussion_r3591291688
##########
tests/integration_tests/query_context_tests.py:
##########
@@ -1220,6 +1220,40 @@ def test_date_adhoc_column(app_context,
physical_dataset):
assert df["count"][0] == 10
+@only_postgresql
+def test_date_trunc_metric_matches_quarter_grouping(app_context,
physical_dataset):
Review Comment:
**Suggestion:** Add explicit type hints to the new test function signature,
including parameter types and a `None` return type annotation. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
The added test function is new Python code and its parameters and return
type are unannotated, which violates the requirement to include type hints
where applicable.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 28)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ec00efa059d947669b954793ecae5d3c&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=ec00efa059d947669b954793ecae5d3c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/integration_tests/query_context_tests.py
**Line:** 1224:1224
**Comment:**
*Custom Rule: Add explicit type hints to the new test function
signature, including parameter types and a `None` return type annotation.
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%2F42095&comment_hash=835e671339ce230002786f2c2e2a1188d171cd6b44617ae2897d42e23f154dbe&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42095&comment_hash=835e671339ce230002786f2c2e2a1188d171cd6b44617ae2897d42e23f154dbe&reaction=dislike'>๐</a>
##########
tests/unit_tests/db_engine_specs/test_postgres.py:
##########
@@ -40,6 +40,64 @@
from tests.unit_tests.fixtures.common import dttm # noqa: F401
[email protected](
+ "unit",
+ [
+ "SECOND",
+ "MINUTE",
+ "HOUR",
+ "DAY",
+ "WEEK",
+ "MONTH",
+ "QUARTER",
+ "YEAR",
+ "quarter",
+ "QuArTeR",
+ ],
+)
+def test_normalize_custom_sql_metric_date_trunc_unit(unit: str) -> None:
+ """DATE_TRUNC unit casing matches PostgreSQL time-grain templates."""
+ expression = (
+ f"CASE WHEN DATE_TRUNC('{unit}', created_at) = '2024-01-01' "
+ "THEN COUNT(*) / 1000 END"
+ )
Review Comment:
**Suggestion:** Add an explicit type annotation for the local `expression`
variable in this new test. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This is a newly added local variable with an obvious string type, and it
lacks a type hint. That matches the Python type-hint rule for annotatable
variables.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 28)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9af0661de8724ab282b363cb46ccabb2&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=9af0661de8724ab282b363cb46ccabb2&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/db_engine_specs/test_postgres.py
**Line:** 60:63
**Comment:**
*Custom Rule: Add an explicit type annotation for the local
`expression` variable in this new test.
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%2F42095&comment_hash=ac58e5fa66c2fd0c5f5052546aff3ae70bac3de6a60668152fcb171d02c30466&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42095&comment_hash=ac58e5fa66c2fd0c5f5052546aff3ae70bac3de6a60668152fcb171d02c30466&reaction=dislike'>๐</a>
##########
tests/unit_tests/db_engine_specs/test_redshift.py:
##########
@@ -79,3 +81,31 @@ def test_normalize_table_name_for_upload(
assert normalized_table == expected_table
assert normalized_schema == expected_schema
+
+
+def test_normalize_custom_sql_metric_date_trunc_unit() -> None:
+ expression = "DATE_TRUNC('QUARTER', created_at)"
Review Comment:
**Suggestion:** Add an explicit type annotation for this local variable so
it complies with the type-hint requirement for annotatable variables.
[custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This is new Python code introducing a clearly typed local variable without
an annotation, which matches the rule requiring type hints on annotatable
variables.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 28)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=5f6d389bd6d9444f8f26029ecac04745&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=5f6d389bd6d9444f8f26029ecac04745&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/db_engine_specs/test_redshift.py
**Line:** 87:87
**Comment:**
*Custom Rule: Add an explicit type annotation for this local variable
so it complies with the type-hint requirement for annotatable variables.
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%2F42095&comment_hash=911d71941dc057062d81ac4fbe6a8fe3e16f6e80a04528bd7ad391a9bcf0dda1&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42095&comment_hash=911d71941dc057062d81ac4fbe6a8fe3e16f6e80a04528bd7ad391a9bcf0dda1&reaction=dislike'>๐</a>
##########
tests/unit_tests/db_engine_specs/test_postgres.py:
##########
@@ -40,6 +40,64 @@
from tests.unit_tests.fixtures.common import dttm # noqa: F401
[email protected](
+ "unit",
+ [
+ "SECOND",
+ "MINUTE",
+ "HOUR",
+ "DAY",
+ "WEEK",
+ "MONTH",
+ "QUARTER",
+ "YEAR",
+ "quarter",
+ "QuArTeR",
+ ],
+)
+def test_normalize_custom_sql_metric_date_trunc_unit(unit: str) -> None:
+ """DATE_TRUNC unit casing matches PostgreSQL time-grain templates."""
+ expression = (
+ f"CASE WHEN DATE_TRUNC('{unit}', created_at) = '2024-01-01' "
+ "THEN COUNT(*) / 1000 END"
+ )
+
+ assert spec.normalize_custom_sql_metric(expression) == (
+ f"CASE WHEN DATE_TRUNC('{unit.lower()}', created_at) = '2024-01-01' "
+ "THEN COUNT(*) / 1000 END"
+ )
+
+
[email protected](
+ "expression",
+ [
+ "'QUARTER'",
+ "OTHER_DATE_TRUNC('QUARTER', created_at)",
+ "custom.DATE_TRUNC('QUARTER', created_at)",
+ "DATE_TRUNC(grain, created_at)",
+ "DATE_TRUNC('FISCAL_QUARTER', created_at)",
+ 'DATE_TRUNC("QUARTER", created_at)',
+ "'DATE_TRUNC(''QUARTER'', created_at)'",
+ ],
+)
+def test_normalize_custom_sql_metric_does_not_rewrite_unrelated_sql(
+ expression: str,
+) -> None:
+ assert spec.normalize_custom_sql_metric(expression) == expression
+
+
+def test_normalize_custom_sql_metric_preserves_source_around_multiple_calls()
-> None:
+ expression = (
+ "/* lead */ CASE WHEN DATE_TRUNC('QUARTER', created_at) = start_date\n"
+ "THEN DATE_TRUNC('MONTH', created_at) END /* tail */"
+ )
Review Comment:
**Suggestion:** Add an explicit type annotation for the local `expression`
variable in this new test. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This newly introduced local variable is also plainly a string and is left
unannotated, which violates the rule requiring type hints for annotatable
Python variables.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 28)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f5c9ba406ec948ecb655282297822f52&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=f5c9ba406ec948ecb655282297822f52&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/db_engine_specs/test_postgres.py
**Line:** 90:93
**Comment:**
*Custom Rule: Add an explicit type annotation for the local
`expression` variable in this new test.
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%2F42095&comment_hash=d7d2ba6e8d344a39ec2641e2e4148f94aac8fb74ec31aad376c6024c61ba6a97&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42095&comment_hash=d7d2ba6e8d344a39ec2641e2e4148f94aac8fb74ec31aad376c6024c61ba6a97&reaction=dislike'>๐</a>
##########
tests/unit_tests/db_engine_specs/test_redshift.py:
##########
@@ -79,3 +81,31 @@ def test_normalize_table_name_for_upload(
assert normalized_table == expected_table
assert normalized_schema == expected_schema
+
+
+def test_normalize_custom_sql_metric_date_trunc_unit() -> None:
+ expression = "DATE_TRUNC('QUARTER', created_at)"
+
+ assert RedshiftEngineSpec.normalize_custom_sql_metric(expression) == (
+ "DATE_TRUNC('quarter', created_at)"
+ )
+
+
+def test_date_trunc_metric_matches_quarter_grouping_in_complete_query() ->
None:
+ metric = sa.literal_column(
+ RedshiftEngineSpec.normalize_custom_sql_metric(
+ "CASE WHEN DATE_TRUNC('QUARTER', created_at) = '2024-01-01' "
+ "THEN COUNT(*) END"
+ )
+ ).label("quarter_metric")
+ quarter = RedshiftEngineSpec.get_timestamp_expr(
+ col=sa.column("created_at"),
+ pdf=None,
+ time_grain="P3M",
+ )
+ query = sa.select(quarter,
metric).select_from(sa.table("orders")).group_by(quarter)
+
+ sql = str(query.compile(dialect=postgresql.dialect()))
Review Comment:
**Suggestion:** Add explicit type annotations for these newly introduced
local variables to satisfy the rule requiring type hints on annotatable
variables. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
These are newly added local variables in Python code and none of them have
type annotations, so the suggestion correctly identifies a violation of the
type-hint requirement.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 28)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=eb6ae56ddf3948bd9726492f51e08ea2&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=eb6ae56ddf3948bd9726492f51e08ea2&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/db_engine_specs/test_redshift.py
**Line:** 95:108
**Comment:**
*Custom Rule: Add explicit type annotations for these newly introduced
local variables to satisfy the rule requiring type hints on annotatable
variables.
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%2F42095&comment_hash=1f73b2b8298541958af3c9556f624178fc89f52412a59783999249917958131d&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42095&comment_hash=1f73b2b8298541958af3c9556f624178fc89f52412a59783999249917958131d&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]