You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "rusackas (via GitHub)" <gi...@apache.org> on 2026/06/01 23:02:20 UTC
[PR] test(histogram): metric filters require aggregation in buildQuery (#30330) [superset]
rusackas opened a new pull request, #40617:
URL: https://github.com/apache/superset/pull/40617
### SUMMARY
This is a **test-only PR** opened as a TDD-style validation of issue #30330.
#30330 reports that the Histogram chart fails with a database error when a "filter by metric" (HAVING clause) is added. rusackas confirmed the bug is still live on master.
**Root cause:** `buildQuery.ts` unconditionally sets `metrics: undefined`. Any HAVING-clause `adhoc_filter` therefore produces SQL with a `HAVING` clause but no aggregated metric or `GROUP BY` — invalid SQL that Druid (and most databases) reject.
This PR adds a `buildQuery` test with three cases:
1. **`should build query with column and no metrics`** — baseline: histogram sends no metrics (passes today).
2. **`should include groupby columns in query columns`** — groupby passthrough (passes today).
3. **`Regression for #30330`** — asserts that when a HAVING `adhoc_filter` is present, `query.metrics` is defined and non-empty. **Fails today** (metrics is always `undefined`).
### How to interpret CI
- **CI red** → bug is live. Fix target: `buildQuery.ts` — detect HAVING `adhoc_filters` and preserve or synthesise a `COUNT(*)` metric so the HAVING clause has an aggregated value to filter on.
- **CI green** → bug fixed; merge closes #30330 and locks in the regression guard.
### TESTING INSTRUCTIONS
```bash
cd superset-frontend
npm run test -- plugins/plugin-chart-echarts/test/Histogram/buildQuery.test.ts --no-coverage
```
### ADDITIONAL INFORMATION
- [x] Has associated issue: closes #30330
- [ ] Required feature flags: N/A
- [ ] Changes UI: No
- [ ] Includes DB Migration: No
- [ ] Introduces new feature or API: No
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] test(histogram): metric filters require aggregation in buildQuery (#30330) [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #40617:
URL: https://github.com/apache/superset/pull/40617#issuecomment-4597180485
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] test(histogram): metric filters require aggregation in buildQuery (#30330) [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #40617:
URL: https://github.com/apache/superset/pull/40617#issuecomment-4597486314
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/40617?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 63.95%. Comparing base ([`1523d79`](https://app.codecov.io/gh/apache/superset/commit/1523d797ca69e3a70aa8b0ea470ba30a6ad5bb95?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`2efbdd4`](https://app.codecov.io/gh/apache/superset/commit/2efbdd4af8ffb38cc8314181648763710f2555b9?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 18 commits behind head on master.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #40617 +/- ##
=======================================
Coverage 63.94% 63.95%
=======================================
Files 2658 2658
Lines 143011 143015 +4
Branches 32866 32869 +3
=======================================
+ Hits 91453 91461 +8
+ Misses 49995 49991 -4
Partials 1563 1563
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/40617/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [javascript](https://app.codecov.io/gh/apache/superset/pull/40617/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `67.38% <100.00%> (+<0.01%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/40617?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] test(histogram): metric filters require aggregation in buildQuery (#30330) [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #40617:
URL: https://github.com/apache/superset/pull/40617#discussion_r3342894536
##########
superset-frontend/plugins/plugin-chart-echarts/src/Histogram/buildQuery.ts:
##########
@@ -21,13 +21,24 @@ import { histogramOperator } from '@superset-ui/chart-controls';
import { HistogramFormData } from './types';
export default function buildQuery(formData: HistogramFormData) {
- const { column, groupby = [] } = formData;
+ const { column, groupby = [], adhoc_filters } = formData;
Review Comment:
**MEDIUM — PR title and description say "test-only" but the diff includes production code**
The PR title uses the Conventional Commits `test` type (= tests only) and the description opens with "This is a **test-only PR**", but this file has +13/−2 lines of production logic — the actual fix. The description does go on to describe the fix approach, so intent is clear, but the title will mislead changelog tooling and reviewers scanning git log.
Suggested title: `fix(histogram): synthesise COUNT(*) metric when HAVING filter is present (#30330)`
Not a merge blocker — the code is correct — but worth fixing before merge.
##########
superset-frontend/plugins/plugin-chart-echarts/test/Histogram/buildQuery.test.ts:
##########
@@ -0,0 +1,81 @@
+/**
+ * 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.
+ */
+import buildQuery from '../../src/Histogram/buildQuery';
+import { HistogramFormData } from '../../src/Histogram/types';
+
+const baseFormData: HistogramFormData = {
+ datasource: '5__table',
+ granularity_sqla: 'ds',
+ column: 'price',
+ groupby: [],
+ bins: 10,
+ viz_type: 'histogram',
+ cumulative: false,
+ normalize: false,
+ sliceId: 1,
+ showLegend: false,
+ showValue: false,
+ xAxisFormat: '',
+ xAxisTitle: '',
+ yAxisFormat: '',
+ yAxisTitle: '',
+};
+
+test('should build query with column and no metrics', () => {
+ const queryContext = buildQuery(baseFormData);
+ const [query] = queryContext.queries;
+ expect(query.columns).toContain('price');
+ expect(query.metrics).toBeUndefined();
+});
+
+test('should include groupby columns in query columns', () => {
+ const queryContext = buildQuery({ ...baseFormData, groupby: ['category'] });
+ const [query] = queryContext.queries;
+ expect(query.columns).toEqual(['category', 'price']);
+});
+
+test('Regression for #30330: HAVING-clause metric filters require aggregation in the query', () => {
+ /**
+ * buildQuery unconditionally sets metrics: undefined, which means any
+ * HAVING-clause adhoc_filter produces SQL with a HAVING clause but no
+ * GROUP BY or aggregated metric — invalid SQL that most databases reject.
+ *
+ * The fix should preserve (or synthesise) a metric so the HAVING clause
+ * has an aggregated value to filter on. This test asserts that desired
+ * behaviour: when a HAVING adhoc_filter is present, query.metrics must
+ * not be undefined or empty.
+ */
+ const formDataWithHavingFilter: HistogramFormData = {
+ ...baseFormData,
+ adhoc_filters: [
+ {
+ clause: 'HAVING',
+ expressionType: 'SQL',
+ sqlExpression: 'COUNT(*) > 5',
+ },
+ ],
+ };
+ const queryContext = buildQuery(formDataWithHavingFilter);
+ const [query] = queryContext.queries;
+
+ // HAVING filters without aggregation produce invalid SQL.
+ // The query must include at least one metric when HAVING filters are present.
+ expect(query.metrics).toBeDefined();
+ expect((query.metrics as unknown[]).length).toBeGreaterThan(0);
Review Comment:
**NIT — `as unknown[]` cast loses type safety; prefer `.toHaveLength()`**
```ts
// before
expect((query.metrics as unknown[]).length).toBeGreaterThan(0);
// after
expect(query.metrics).toHaveLength(1);
```
`toHaveLength` works directly on arrays, produces a better failure message, and avoids the unsafe cast. If you also want to lock down the synthesised metric shape:
```ts
expect(query.metrics?.[0]).toMatchObject({ expressionType: 'SQL', label: 'COUNT(*)' });
```
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] test(histogram): metric filters require aggregation in buildQuery (#30330) [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #40617:
URL: https://github.com/apache/superset/pull/40617#issuecomment-4597446137
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 2efbdd4af8ffb38cc8314181648763710f2555b9 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6a1e1c01ece217000851a459 |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-40617--superset-docs-preview.netlify.app](https://deploy-preview-40617--superset-docs-preview.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br /><br /><br />_Use your smartphone camera to open QR code link._</details> |
|<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#Dcs7DsMgDADQu3gOil3ya2-QY1BwG6RQkHGGKMrdy_aWd0GRnIrCC6CDt7if35o1hD7WerCxaC2aLVbNX3HJJFaJ3nziriytBC57PtfQ0uSIySOx5wfNiLiM5IbxCfcf) |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-40617--superset-docs-preview.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] test(histogram): metric filters require aggregation in buildQuery (#30330) [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #40617:
URL: https://github.com/apache/superset/pull/40617#issuecomment-4598322086
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] test(histogram): metric filters require aggregation in buildQuery (#30330) [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #40617:
URL: https://github.com/apache/superset/pull/40617#discussion_r3342892294
##########
superset-frontend/plugins/plugin-chart-echarts/src/Histogram/buildQuery.ts:
##########
@@ -21,13 +21,24 @@ import { histogramOperator } from '@superset-ui/chart-controls';
import { HistogramFormData } from './types';
export default function buildQuery(formData: HistogramFormData) {
- const { column, groupby = [] } = formData;
+ const { column, groupby = [], adhoc_filters } = formData;
+ const hasHavingFilter = (adhoc_filters ?? []).some(
+ (filter: { clause?: string }) => filter.clause === 'HAVING',
Review Comment:
**MEDIUM — inline type `{ clause?: string }` should use `AdhocFilter`**
`HistogramFormData` extends `QueryFormData` which already types `adhoc_filters?: AdhocFilter[] | null` via `BaseFormData`. TypeScript can infer `filter: AdhocFilter` in the `.some()` callback without an explicit annotation. The inline annotation introduces two problems:
1. Makes `clause` optional (adds `?`) when `BaseAdhocFilter.clause` is the required union `'WHERE' | 'HAVING'`.
2. Widens the element type from the literal union to `string`, losing narrowing.
Fix — remove the annotation and let TypeScript infer, or use the proper type:
```ts
(filter: AdhocFilter) => filter.clause === 'HAVING',
```
`AdhocFilter` is already re-exported from `@superset-ui/core` — no new import needed.
##########
superset-frontend/plugins/plugin-chart-echarts/src/Histogram/buildQuery.ts:
##########
@@ -21,13 +21,24 @@ import { histogramOperator } from '@superset-ui/chart-controls';
import { HistogramFormData } from './types';
export default function buildQuery(formData: HistogramFormData) {
- const { column, groupby = [] } = formData;
+ const { column, groupby = [], adhoc_filters } = formData;
+ const hasHavingFilter = (adhoc_filters ?? []).some(
Review Comment:
**MEDIUM — `extra_form_data.adhoc_filters` HAVING filters not detected**
`adhoc_filters` here is `formData.adhoc_filters` only. HAVING filters injected by dashboard native filter boxes arrive via `extra_form_data.adhoc_filters`, which `buildQueryContext` merges into the built query — but those filters are invisible to this check. If a dashboard box injects a HAVING clause, `hasHavingFilter` stays `false`, `metrics` stays `undefined`, and the invalid-SQL path from #30330 fires.
This is a niche path (HAVING filters via dashboard boxes are uncommon), so not a hard blocker. Worth a follow-up issue or an inline comment scoping the fix to the direct-filter path.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] test(histogram): metric filters require aggregation in buildQuery (#30330) [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe merged PR #40617:
URL: https://github.com/apache/superset/pull/40617
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] test(histogram): metric filters require aggregation in buildQuery (#30330) [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #40617:
URL: https://github.com/apache/superset/pull/40617#discussion_r3342897310
##########
superset-frontend/plugins/plugin-chart-echarts/test/Histogram/buildQuery.test.ts:
##########
@@ -0,0 +1,81 @@
+/**
+ * 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.
+ */
+import buildQuery from '../../src/Histogram/buildQuery';
+import { HistogramFormData } from '../../src/Histogram/types';
+
+const baseFormData: HistogramFormData = {
+ datasource: '5__table',
+ granularity_sqla: 'ds',
+ column: 'price',
+ groupby: [],
+ bins: 10,
+ viz_type: 'histogram',
+ cumulative: false,
+ normalize: false,
+ sliceId: 1,
+ showLegend: false,
+ showValue: false,
+ xAxisFormat: '',
+ xAxisTitle: '',
+ yAxisFormat: '',
+ yAxisTitle: '',
+};
+
+test('should build query with column and no metrics', () => {
+ const queryContext = buildQuery(baseFormData);
+ const [query] = queryContext.queries;
+ expect(query.columns).toContain('price');
+ expect(query.metrics).toBeUndefined();
+});
+
+test('should include groupby columns in query columns', () => {
+ const queryContext = buildQuery({ ...baseFormData, groupby: ['category'] });
+ const [query] = queryContext.queries;
+ expect(query.columns).toEqual(['category', 'price']);
+});
+
+test('Regression for #30330: HAVING-clause metric filters require aggregation in the query', () => {
Review Comment:
**NIT — test name doesn't follow the `'should ...'` convention used by the other two tests**
Tests 1 and 2 use `'should ...'` names. Consider:
```ts
test('should include COUNT(*) metric when HAVING filter is present', () => {
```
Keep the `#30330` reference and the bug explanation in the block comment, where they add context without cluttering the Jest output.
##########
superset-frontend/plugins/plugin-chart-echarts/test/Histogram/buildQuery.test.ts:
##########
@@ -0,0 +1,81 @@
+/**
+ * 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.
+ */
+import buildQuery from '../../src/Histogram/buildQuery';
+import { HistogramFormData } from '../../src/Histogram/types';
+
+const baseFormData: HistogramFormData = {
+ datasource: '5__table',
+ granularity_sqla: 'ds',
+ column: 'price',
+ groupby: [],
+ bins: 10,
+ viz_type: 'histogram',
+ cumulative: false,
+ normalize: false,
+ sliceId: 1,
+ showLegend: false,
+ showValue: false,
+ xAxisFormat: '',
+ xAxisTitle: '',
+ yAxisFormat: '',
+ yAxisTitle: '',
+};
+
+test('should build query with column and no metrics', () => {
+ const queryContext = buildQuery(baseFormData);
+ const [query] = queryContext.queries;
+ expect(query.columns).toContain('price');
+ expect(query.metrics).toBeUndefined();
+});
+
+test('should include groupby columns in query columns', () => {
+ const queryContext = buildQuery({ ...baseFormData, groupby: ['category'] });
+ const [query] = queryContext.queries;
+ expect(query.columns).toEqual(['category', 'price']);
+});
Review Comment:
**NIT — missing complementary WHERE-only filter test**
There's no test confirming that a WHERE-only filter leaves `metrics` as `undefined`. This is the direct complement to the regression test and guards against a future refactor accidentally triggering on WHERE filters:
```ts
test('should not inject metrics for WHERE-only filters', () => {
const formData = {
...baseFormData,
adhoc_filters: [
{ clause: 'WHERE', expressionType: 'SQL', sqlExpression: 'price > 10' },
],
};
const [query] = buildQuery(formData as HistogramFormData).queries;
expect(query.metrics).toBeUndefined();
});
```
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] test(histogram): metric filters require aggregation in buildQuery (#30330) [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #40617:
URL: https://github.com/apache/superset/pull/40617#discussion_r3342890413
##########
superset-frontend/plugins/plugin-chart-echarts/src/Histogram/buildQuery.ts:
##########
@@ -21,13 +21,24 @@ import { histogramOperator } from '@superset-ui/chart-controls';
import { HistogramFormData } from './types';
export default function buildQuery(formData: HistogramFormData) {
- const { column, groupby = [] } = formData;
+ const { column, groupby = [], adhoc_filters } = formData;
+ const hasHavingFilter = (adhoc_filters ?? []).some(
+ (filter: { clause?: string }) => filter.clause === 'HAVING',
Review Comment:
**MEDIUM — inline type should use **
`HistogramFormData` extends `QueryFormData` which already types `adhoc_filters?: AdhocFilter[] | null` via `BaseFormData`. TypeScript can infer `filter: AdhocFilter` in the `.some()` callback without an explicit annotation. The inline annotation introduces two problems:
1. Makes `clause` optional (adds `?`) when `BaseAdhocFilter.clause` is the required union `'WHERE' | 'HAVING'`.
2. Widens the element type from the literal union to `string`, losing narrowing.
Fix — remove the annotation and let TypeScript infer, or use the proper type:
```ts
(filter: AdhocFilter) => filter.clause === 'HAVING',
```
`AdhocFilter` is already re-exported from `@superset-ui/core` — no new import needed.
##########
superset-frontend/plugins/plugin-chart-echarts/src/Histogram/buildQuery.ts:
##########
@@ -21,13 +21,24 @@ import { histogramOperator } from '@superset-ui/chart-controls';
import { HistogramFormData } from './types';
export default function buildQuery(formData: HistogramFormData) {
- const { column, groupby = [] } = formData;
+ const { column, groupby = [], adhoc_filters } = formData;
+ const hasHavingFilter = (adhoc_filters ?? []).some(
Review Comment:
**MEDIUM — `extra_form_data.adhoc_filters` HAVING filters not detected**
`adhoc_filters` here is `formData.adhoc_filters` only. HAVING filters injected by dashboard native filter boxes arrive via `extra_form_data.adhoc_filters`, which `buildQueryContext` merges into the built query — but those filters are invisible to this check. If a dashboard box injects a HAVING clause, `hasHavingFilter` stays `false`, `metrics` stays `undefined`, and the invalid-SQL path from #30330 fires.
This is a niche path (HAVING filters via dashboard boxes are uncommon), so not a hard blocker. Worth a follow-up issue or an inline comment scoping the fix to the direct-filter path.
##########
superset-frontend/plugins/plugin-chart-echarts/src/Histogram/buildQuery.ts:
##########
@@ -21,13 +21,24 @@ import { histogramOperator } from '@superset-ui/chart-controls';
import { HistogramFormData } from './types';
export default function buildQuery(formData: HistogramFormData) {
- const { column, groupby = [] } = formData;
+ const { column, groupby = [], adhoc_filters } = formData;
Review Comment:
**MEDIUM — PR title and description say test-only but the diff includes production code**
The PR title uses the Conventional Commits `test` type (= tests only) and the description opens with "This is a **test-only PR**", but this file has +13/−2 lines of production logic — the actual fix. The description does go on to describe the fix approach, so intent is clear, but the title will mislead the Conventional Commits changelog tooling and reviewers scanning git log.
Suggested title: `fix(histogram): synthesise COUNT(*) metric when HAVING filter is present (#30330)`
Not a merge blocker — the code is correct — but worth fixing before merge.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org