codeant-ai-for-open-source[bot] commented on code in PR #40398:
URL: https://github.com/apache/superset/pull/40398#discussion_r3293881894


##########
tests/unit_tests/mcp_service/chart/test_chart_schemas.py:
##########
@@ -727,6 +727,68 @@ def test_saved_metric_duplicate_label_rejected(self) -> 
None:
             )
 
 
+class TestColumnRefSqlExpression:
+    """Test ColumnRef sql_expression support for calculated metrics."""
+
+    def test_sql_expression_defaults_to_none(self) -> None:
+        col = ColumnRef(name="revenue", aggregate="SUM")
+        assert col.sql_expression is None

Review Comment:
   **Suggestion:** Add a short docstring to this new test method to satisfy the 
rule requiring docstrings on newly added function definitions. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The rule requires docstrings on newly added function definitions. This new 
test method has no docstring in the final file, so the suggestion identifies a 
real rule violation.
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=5583e99e634c470d91178a2e11b10ae1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=5583e99e634c470d91178a2e11b10ae1&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/mcp_service/chart/test_chart_schemas.py
   **Line:** 733:735
   **Comment:**
        *Custom Rule: Add a short docstring to this new test method to satisfy 
the rule requiring docstrings on newly added function definitions.
   
   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%2F40398&comment_hash=4f265c6ae8f99eba188b56dee31afd33aaa204778800f009cda4ca6dcc11f28c&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40398&comment_hash=4f265c6ae8f99eba188b56dee31afd33aaa204778800f009cda4ca6dcc11f28c&reaction=dislike'>👎</a>



##########
tests/unit_tests/mcp_service/chart/test_chart_schemas.py:
##########
@@ -727,6 +727,68 @@ def test_saved_metric_duplicate_label_rejected(self) -> 
None:
             )
 
 
+class TestColumnRefSqlExpression:
+    """Test ColumnRef sql_expression support for calculated metrics."""
+
+    def test_sql_expression_defaults_to_none(self) -> None:
+        col = ColumnRef(name="revenue", aggregate="SUM")
+        assert col.sql_expression is None
+
+    def test_sql_expression_accepted(self) -> None:
+        col = ColumnRef(
+            name="profit_ratio",
+            sql_expression="SUM(profit) / NULLIF(SUM(sales), 0)",
+            label="Profit Ratio",
+        )
+        assert col.sql_expression == "SUM(profit) / NULLIF(SUM(sales), 0)"
+        assert col.label == "Profit Ratio"

Review Comment:
   **Suggestion:** Add a concise docstring describing the behavior being 
validated so the new method complies with the docstring requirement for newly 
introduced functions. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This newly added test method does not include a docstring, which violates 
the stated rule for newly introduced function definitions.
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9f9dc781221f4b979e5ef3e9787460d6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9f9dc781221f4b979e5ef3e9787460d6&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/mcp_service/chart/test_chart_schemas.py
   **Line:** 737:744
   **Comment:**
        *Custom Rule: Add a concise docstring describing the behavior being 
validated so the new method complies with the docstring requirement for newly 
introduced functions.
   
   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%2F40398&comment_hash=5c27065d6f77857fb0769dc7d3beb0429fb146fb324d7dc54d62e626a6d0f419&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40398&comment_hash=5c27065d6f77857fb0769dc7d3beb0429fb146fb324d7dc54d62e626a6d0f419&reaction=dislike'>👎</a>



##########
tests/unit_tests/mcp_service/chart/test_chart_schemas.py:
##########
@@ -727,6 +727,68 @@ def test_saved_metric_duplicate_label_rejected(self) -> 
None:
             )
 
 
+class TestColumnRefSqlExpression:
+    """Test ColumnRef sql_expression support for calculated metrics."""
+
+    def test_sql_expression_defaults_to_none(self) -> None:
+        col = ColumnRef(name="revenue", aggregate="SUM")
+        assert col.sql_expression is None
+
+    def test_sql_expression_accepted(self) -> None:
+        col = ColumnRef(
+            name="profit_ratio",
+            sql_expression="SUM(profit) / NULLIF(SUM(sales), 0)",
+            label="Profit Ratio",
+        )
+        assert col.sql_expression == "SUM(profit) / NULLIF(SUM(sales), 0)"
+        assert col.label == "Profit Ratio"
+
+    def test_sql_expression_clears_aggregate(self) -> None:
+        """sql_expression takes over from aggregate, matching saved_metric 
behavior."""
+        col = ColumnRef(
+            name="profit_ratio",
+            sql_expression="SUM(profit) / SUM(sales)",
+            aggregate="SUM",
+        )
+        assert col.sql_expression == "SUM(profit) / SUM(sales)"
+        assert col.aggregate is None
+
+    def test_sql_expression_marks_as_metric(self) -> None:
+        col = ColumnRef(name="ratio", sql_expression="SUM(a)/SUM(b)")
+        assert col.is_metric is True
+
+    def test_sql_expression_and_saved_metric_are_mutually_exclusive(self) -> 
None:
+        """A ColumnRef can't be both a saved-metric reference AND a SQL 
calc."""
+        with pytest.raises(ValidationError, match="mutually exclusive"):
+            ColumnRef(
+                name="profit_ratio",
+                sql_expression="SUM(profit)/SUM(sales)",
+                saved_metric=True,
+            )
+
+    def test_sql_expression_in_xy_config(self) -> None:
+        """SQL-expression metrics work as the y-axis of an xy chart."""
+        config = XYChartConfig(
+            chart_type="xy",
+            x=ColumnRef(name="order_date"),
+            y=[
+                ColumnRef(
+                    name="margin",
+                    sql_expression="SUM(profit) / NULLIF(SUM(sales), 0)",
+                    label="Margin",
+                )
+            ],
+        )
+        assert len(config.y) == 1
+        assert config.y[0].sql_expression == (
+            "SUM(profit) / NULLIF(SUM(sales), 0)"
+        )
+
+    def test_sql_expression_max_length_enforced(self) -> None:
+        with pytest.raises(ValidationError, match="at most 2000"):
+            ColumnRef(name="x", sql_expression="x" * 2001)

Review Comment:
   **Suggestion:** Add a brief docstring to this test method to comply with the 
requirement that newly added functions must be documented. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This new test method also lacks a docstring in the final file, so the 
suggestion correctly flags a real violation of the docstring rule.
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=b867b942f25b467d946bf8ab620b0e03&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=b867b942f25b467d946bf8ab620b0e03&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/mcp_service/chart/test_chart_schemas.py
   **Line:** 787:789
   **Comment:**
        *Custom Rule: Add a brief docstring to this test method to comply with 
the requirement that newly added functions must be documented.
   
   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%2F40398&comment_hash=4db7ad46a7211ea492e29eecfc1c0c6630acaa63502919abc3fb80c7697d05fb&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40398&comment_hash=4db7ad46a7211ea492e29eecfc1c0c6630acaa63502919abc3fb80c7697d05fb&reaction=dislike'>👎</a>



##########
tests/unit_tests/mcp_service/chart/test_chart_schemas.py:
##########
@@ -727,6 +727,68 @@ def test_saved_metric_duplicate_label_rejected(self) -> 
None:
             )
 
 
+class TestColumnRefSqlExpression:
+    """Test ColumnRef sql_expression support for calculated metrics."""
+
+    def test_sql_expression_defaults_to_none(self) -> None:
+        col = ColumnRef(name="revenue", aggregate="SUM")
+        assert col.sql_expression is None
+
+    def test_sql_expression_accepted(self) -> None:
+        col = ColumnRef(
+            name="profit_ratio",
+            sql_expression="SUM(profit) / NULLIF(SUM(sales), 0)",
+            label="Profit Ratio",
+        )
+        assert col.sql_expression == "SUM(profit) / NULLIF(SUM(sales), 0)"
+        assert col.label == "Profit Ratio"
+
+    def test_sql_expression_clears_aggregate(self) -> None:
+        """sql_expression takes over from aggregate, matching saved_metric 
behavior."""
+        col = ColumnRef(
+            name="profit_ratio",
+            sql_expression="SUM(profit) / SUM(sales)",
+            aggregate="SUM",
+        )
+        assert col.sql_expression == "SUM(profit) / SUM(sales)"
+        assert col.aggregate is None
+
+    def test_sql_expression_marks_as_metric(self) -> None:
+        col = ColumnRef(name="ratio", sql_expression="SUM(a)/SUM(b)")
+        assert col.is_metric is True

Review Comment:
   **Suggestion:** Add a method-level docstring here so this newly added 
function meets the rule that all new function definitions include docstrings. 
[custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The final file shows this added test method without a docstring. That is a 
direct match for the docstring requirement on new functions.
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f87a123efdcc45eb8b20bf4f5a2de667&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=f87a123efdcc45eb8b20bf4f5a2de667&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/mcp_service/chart/test_chart_schemas.py
   **Line:** 756:758
   **Comment:**
        *Custom Rule: Add a method-level docstring here so this newly added 
function meets the rule that all new function definitions include docstrings.
   
   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%2F40398&comment_hash=142804983d1158734ed3bd4492bbbbdd29a5b0fb117844a9ce7e338ff18bbd2c&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40398&comment_hash=142804983d1158734ed3bd4492bbbbdd29a5b0fb117844a9ce7e338ff18bbd2c&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]

Reply via email to