codeant-ai-for-open-source[bot] commented on code in PR #41184:
URL: https://github.com/apache/superset/pull/41184#discussion_r3564126332
##########
superset/common/query_context_processor.py:
##########
@@ -252,9 +256,60 @@ def get_query_result(self, query_object: QueryObject) ->
QueryResult:
This method delegates to the datasource's get_query_result method,
which handles query execution, normalization, time offsets, and
post-processing.
+
+ When the query requests rollup ``grouping_sets`` but the engine does
not
+ support native ``GROUPING SETS``, fall back to one query per level and
+ concatenate the results with ``GROUPING()``-equivalent markers, so the
+ combined result matches the shape the native path produces (SIP.md,
+ phase 3b). Engines that support it run the single native query.
"""
+ if query_object.grouping_sets and not self._supports_grouping_sets():
+ return self._grouping_sets_fallback(query_object)
return self._qc_datasource.get_query_result(query_object)
+ def _supports_grouping_sets(self) -> bool:
+ engine_spec: BaseEngineSpec | None = getattr(
+ self._qc_datasource, "db_engine_spec", None
+ )
+ return bool(engine_spec and engine_spec.supports_grouping_sets)
+
+ def _grouping_sets_fallback(self, query_object: QueryObject) ->
QueryResult:
+ """
+ Emulate a GROUPING SETS query on engines without native support: run
one
+ query per rollup level and concatenate, tagging each level's rows with
+ the same per-column markers the native path emits.
+ """
+ levels: list[list[str]] = query_object.grouping_sets
+ # Use the same label derivation as the native path (physical column
name
+ # or adhoc column label) so both column kinds are represented and each
+ # label maps back to its own column, in the same order as the source
+ # list.
+ all_labels = [get_column_name(col) for col in query_object.columns]
Review Comment:
**Suggestion:** Add an explicit type annotation for this newly introduced
intermediate variable to keep the new logic fully type-hinted. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This is newly added Python code and `all_labels` is a clearly annotatable
local variable. It currently lacks an explicit type hint, so it matches the
custom rule requiring type hints on new or modified Python code.
</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=0ebd06c8475941e3aacbf0bdef87e9eb&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=0ebd06c8475941e3aacbf0bdef87e9eb&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:** superset/common/query_context_processor.py
**Line:** 287:287
**Comment:**
*Custom Rule: Add an explicit type annotation for this newly introduced
intermediate variable to keep the new logic fully type-hinted.
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%2F41184&comment_hash=a1409c98891d0fd30df8a915e2d468d8b32fd3c509650e09c3974b837bf72e79&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41184&comment_hash=a1409c98891d0fd30df8a915e2d468d8b32fd3c509650e09c3974b837bf72e79&reaction=dislike'>๐</a>
##########
superset/common/grouping_sets.py:
##########
@@ -0,0 +1,116 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+SQL building blocks for the pivot-table non-additive totals optimization
+(SIP.md, phase 3b). When a datasource engine reports
+``supports_grouping_sets``, the N per-rollup-level queries can be collapsed
into
+a single ``GROUPING SETS`` query: the database computes every level in one
scan,
+and each returned row is attributed to its level via ``GROUPING()`` markers.
+
+These are the engine-agnostic SQL primitives. Wiring them into the query
context
+(emitting one query and splitting the result back into per-level results) is
the
+remaining integration; see SIP.md.
+"""
+
+from __future__ import annotations
+
+from collections.abc import Sequence
+
+import pandas as pd
+from sqlalchemy import func, tuple_
+from sqlalchemy.sql.elements import ColumnElement
+
+# Suffix for the per-column GROUPING() marker columns added to a GROUPING SETS
+# query. Chosen to be unlikely to collide with a real metric/column label.
+GROUPING_MARKER_SUFFIX = "__superset_grouping"
Review Comment:
**Suggestion:** Add an explicit type annotation to this module-level
constant to comply with the required Python type hints rule. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This new module-level constant is a relevant variable that can be annotated,
but it is defined without a type hint. That matches the Python type-hints rule
violation.
</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=0d834547d92147acb201940ed0f75bf9&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=0d834547d92147acb201940ed0f75bf9&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:** superset/common/grouping_sets.py
**Line:** 38:40
**Comment:**
*Custom Rule: Add an explicit type annotation to this module-level
constant to comply with the required Python type hints rule.
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%2F41184&comment_hash=f97816643f9864c3ec0896351478c2b85c84adf03e77915009a8676963c59299&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41184&comment_hash=f97816643f9864c3ec0896351478c2b85c84adf03e77915009a8676963c59299&reaction=dislike'>๐</a>
##########
superset/db_engine_specs/hive.py:
##########
@@ -96,6 +96,11 @@ class HiveEngineSpec(PrestoEngineSpec):
supports_dynamic_schema = True
supports_cross_catalog_queries = False
+ # Explicitly opt out (overriding the inherited PrestoEngineSpec value):
+ # Hive/Spark's GROUPING SETS + GROUPING() marker semantics have not been
+ # verified against this query pattern, so fall back to one query per
+ # rollup level instead of assuming native support.
+ supports_grouping_sets = False
Review Comment:
**Suggestion:** Add an explicit type annotation to this newly introduced
class-level boolean setting. [custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
This is a newly added class-level boolean assignment in Python that can be
annotated as `supports_grouping_sets: bool = False`, so it matches the rule
about missing 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=ca28652cbd2e400fba8d1e9bbdb5001b&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=ca28652cbd2e400fba8d1e9bbdb5001b&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:** superset/db_engine_specs/hive.py
**Line:** 103:103
**Comment:**
*Custom Rule: Add an explicit type annotation to this newly introduced
class-level boolean setting.
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%2F41184&comment_hash=0955dc89e0fed2ffe3b63f9193b15e7a72614acb6000c66d862f6b3601021b0b&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41184&comment_hash=0955dc89e0fed2ffe3b63f9193b15e7a72614acb6000c66d862f6b3601021b0b&reaction=dislike'>๐</a>
##########
superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/buildQuery.test.ts:
##########
@@ -56,9 +55,41 @@ const formData: PivotTableQueryFormData = {
currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' },
};
-test('should build groupby with series in form data', () => {
+test('additive metrics use the fast-path: a single full-detail query', () => {
+ const { queries } = buildQuery({
+ ...formData,
+ metrics: [
+ {
+ expressionType: 'SIMPLE',
+ aggregate: 'SUM',
+ column: { column_name: 'num' },
+ label: 'sum_num',
+ },
+ ] as any,
+ });
Review Comment:
**Suggestion:** Replace the `any` cast on the `metrics` value with the
correct concrete metric array type expected by `PivotTableQueryFormData`.
[custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
The changed TypeScript test code introduces an `any` cast for the `metrics`
value. This directly violates the no-any-types rule, which requires a concrete
type instead of `any`.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 16)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=298b6f437a494df782f4109ed1b94118&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=298b6f437a494df782f4109ed1b94118&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:**
superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/buildQuery.test.ts
**Line:** 58:69
**Comment:**
*Custom Rule: Replace the `any` cast on the `metrics` value with the
correct concrete metric array type expected by `PivotTableQueryFormData`.
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%2F41184&comment_hash=fe07a5c9946e7962bf62533545649419734ab43a1317a58912ac765d6d754632&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41184&comment_hash=fe07a5c9946e7962bf62533545649419734ab43a1317a58912ac765d6d754632&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]