You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "Gwildor (via GitHub)" <gi...@apache.org> on 2025/12/16 15:48:59 UTC

[I] Filter box can't retrieve values when using BigQuery with required partition filter [superset]

Gwildor opened a new issue, #36676:
URL: https://github.com/apache/superset/issues/36676

   ### Bug description
   
   We use Google BigQuery, and have enabled the setting to require partition filters (on a date column) on our tables, as our tables have multiple years of data, with billions of rows. Generally, users only want to see the last few weeks or months, and scanning the full table is both costly and can actually cause Superset to freeze as the queries take too long to execute.
   
   Requiring the partition filter works, and we get a nice error screen when the user has not added this filter on this chart. We have set the default datetime column, and also enabled the `DEFAULT_TIME_FILTER` setting. This all works really well.
   
   Unfortunately though, filtering on text columns now doesn't give a nice UI with the available values in the filter box. This is because the query that Superset generates to retrieve those values does not use the date filter set by the user or the `DEFAULT_TIME_FILTER` setting, and thus BigQuery rejects it because it is missing the partition filter. Users can still manually enter the values they want to see, but this is hard if you don't know beforehand which values are available. Without the required partition filter, the queries to retrieve these values would often take way too long, and would cause Superset to become unstable.
   
   Likewise such filters break on dashboard filter sets. However, here you can configure the filter to be dependent on the other time filter (if configured), and this works pretty well. This is something we just need to explain to our users, although the error message if you don't do this could be nicer.
   
   I think that when creating charts, the filter box should adhere to the other filters that are already configured on the chart, so you can really narrow down on the values that you want to select. Especially if they are time filters. That would solve both the required partition filter, as well as the case that the query would timeout because a full scan of the table would take too long.
   
   ### Screenshots/recordings
   
   <img width="383" height="383" alt="Image" src="https://github.com/user-attachments/assets/4e63b4e6-efda-4006-882a-9f26f32f7c7d" />
   
   Generated query:
   
   ```sql
   SELECT DISTINCT `readable_brand_name` AS `column_values` 
   FROM (SELECT * FROM `clicks`
   ) AS `virtual_table`
    LIMIT 10000
   ```
   
   BigQuery error (UI doesn't show it, it just shows no values to select):
   
   > Cannot query over table 'clicks' without a filter over column(s) 'event_date_cet' that can be used for partition elimination
   
   On dashboards:
   
   <img width="261" height="219" alt="Image" src="https://github.com/user-attachments/assets/736b9a95-3bc5-4835-8dfa-79fdc436db80" />
   
   With the generic error:
   
   > Network error: Network error while attempting to fetch resource
   
   But this works really well if you make the filter dependent on the time filter:
   
   <img width="879" height="592" alt="Image" src="https://github.com/user-attachments/assets/9a4ec492-abd5-4ebe-b829-416bd8aa7ad1" />
   
   Generated query:
   
   ```sql
   SELECT `readable_brand_name` AS `readable_brand_name` 
   FROM (SELECT * FROM `clicks`
   ) AS `virtual_table` 
   WHERE `event_date_cet` >= CAST('2025-09-16' AS DATE) AND `event_date_cet` < CAST('2025-12-16' AS DATE) GROUP BY `readable_brand_name` ORDER BY `readable_brand_name` ASC
    LIMIT 1000
   ```
   
   Something like this would be nice for when creating a chart as well.
   
   ### Superset version
   
   5.0.0
   
   ### Python version
   
   3.11
   
   ### Node version
   
   16
   
   ### Browser
   
   Firefox
   
   ### Additional context
   
   _No response_
   
   ### Checklist
   
   - [x] I have searched Superset docs and Slack and didn't find a solution to my problem.
   - [x] I have searched the GitHub issue tracker and didn't find a similar bug report.
   - [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.


-- 
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.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: [I] Filter box can't retrieve values when using BigQuery with required partition filter [superset]

Posted by "Gwildor (via GitHub)" <gi...@apache.org>.
Gwildor commented on issue #36676:
URL: https://github.com/apache/superset/issues/36676#issuecomment-3661377904

   Interesting, I didn't know about the Autocomplete query predicate setting on datasets. I've set it to `event_date_cet >= date_add(current_date(), interval -3 month)` and the filter box works again, great! It produces this query now:
   
   ```sql
   SELECT DISTINCT `readable_brand_name` AS `column_values` 
   FROM (SELECT * FROM `clicks`
   ) AS `virtual_table` 
   WHERE event_date_cet >= date_add(current_date(), interval -3 month)
    LIMIT 10000
   ```
   
   On the dashboards it doesn't use this predicate, which is good, because there I prefer it to use the filter it is dependent on. If you don't have this dependency, it still gives that network error, so it doesn't use the dataset predicate.
   
   I think I will close this, as I don't have a real bug anymore. The user experience (and perhaps documentation, as I couldn't find this solution before) could be better, but that's not vital.


-- 
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: [I] Filter box can't retrieve values when using BigQuery with required partition filter [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #36676:
URL: https://github.com/apache/superset/issues/36676#issuecomment-3661245647

   <!-- Answer -->
   Superset's filter value queries for native filters (used in chart creation and dashboards) do not automatically apply time filters or partition filters, even if you have set a default datetime column or enabled `DEFAULT_TIME_FILTER`. The backend API that retrieves distinct values for filter controls simply selects from the table without including any time or partition predicates, unless you explicitly configure them in the dataset's `fetch_values_predicate` field. This is why BigQuery rejects these queries when a required partition filter is missing, and why you see no values in the filter box UI. This behavior is by design in the current codebase and matches your observations&nbsp;([source](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/models/helpers.py#L1288-L2117), [source](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/datasource/api.py#L39-L125)).
   
   The only way to ensure a partition filter is always present in these queries is to add a Jinja template in the dataset's `fetch_values_predicate` that enforces a filter on your partition column (for example, always filter to the last N days, or require a time range parameter). This will apply to all filter value queries for that dataset, including those triggered by the filter box UI.
   
   On dashboards, making a filter dependent on a time filter works because the UI passes the time filter to the backend, so the generated query includes the partition filter. However, in chart creation or when the filter is not dependent, this does not happen automatically.
   
   There are no recent changes or configuration options that alter this behavior, and no indication that default time filters or chart-level filters are applied to filter value queries by default. If you want to avoid full table scans and BigQuery errors, you must enforce the partition filter via the dataset configuration&nbsp;([source](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/models/helpers.py#L1288-L2117)).
   
   If you need help crafting a `fetch_values_predicate` template for your use case, let me know!
   
   
   <!-- Dosu Comment Footer -->
   *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
   
   ---
   <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/deaa46fa-4995-4c4f-bc99-10e015c72773?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/deaa46fa-4995-4c4f-bc99-10e015c72773?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/deaa46fa-4995-4c4f-bc99-10e015c72773?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/deaa46fa-4995-4c4f-bc99-10e015c72773?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/deaa46fa-4995-4c4f-bc99-10e015c72773?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/deaa46fa-4995-4c4f-bc99-10e015c72773?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/deaa46fa-4995-4c4f-bc99-10e015c72773?feedback_type=other)</sup>
   
   [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Superset%27s%20filter%20value%20queries%20for%20native%20filters%20%28used%20in%20chart%20creation%20and%20dashboards%29%20do%20not%20automatically%20apply%20time%20filters%20or%20partition%20filters%2C%20even%20if%20you%20have%20set%20a%20default%20datetime%20column%20or%20enabled%20%60DEFAULT_TIME_FILTER%60.%20The%20backend%20API%20that%20retrieves%20distinct%20values%20for%20filter%20controls%20simply%20selects%20from%20the%20table%20without%20including%20any%20time%20or%20partition%20predicates%2C%20unless%20you%20explicitly%20configure%20them%20in%20the%20dataset%27s%20%60fetch_values_predicate%60%20field.%20This%20is%20why%20BigQuery%20rejects%20these%20queries%20when%20a%20required%20partition%20filter%20is%20missing%2C%20and%20why%20you%20s
 ee%20no%20values%20in%20the%20filter%20box%20UI.%20This%20behavior%20is%20by%20design%20in%20the%20current%20codebase%20and%20matches%20your%20observations%26nbsp%3B%28%5Bsource%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/models/helpers.py%23L1288-L2117%29%2C%20%5Bsource%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/datasource/api.py%23L39-L125%29%29.%0A%0AThe%20only%20way%20to%20ensure%20a%20partition%20filter%20is%20always%20present%20in%20these%20queries%20is%20to%20add%20a%20Jinja%20template%20in%20the%20dataset%27s%20%60fetch_values_predicate%60%20that%20enforces%20a%20filter%20on%20your%20partition%20column%20%28for%20example%2C%20always%20filter%20to%20the%20last%20N%20days%2C%20or%20require%20a%20time%20range%20parameter%29.%20This%20will%20apply%20to%20all%20filter%20value%20queries%20for%20that%20dataset%2C%20including%20those%20triggered%20by%20the%20filter%20box%20UI.%
 0A%0AOn%20dashboards%2C%20making%20a%20filter%20dependent%20on%20a%20time%20filter%20works%20because%20the%20UI%20passes%20the%20time%20filter%20to%20the%20backend%2C%20so%20the%20generated%20query%20includes%20the%20partition%20filter.%20However%2C%20in%20chart%20creation%20or%20when%20the%20filter%20is%20not%20dependent%2C%20this%20does%20not%20happen%20automatically.%0A%0AThere%20are%20no%20recent%20changes%20or%20configuration%20options%20that%20alter%20this%20behavior%2C%20and%20no%20indication%20that%20default%20time%20filters%20or%20chart-level%20filters%20are%20applied%20to%20filter%20value%20queries%20by%20default.%20If%20you%20want%20to%20avoid%20full%20table%20scans%20and%20BigQuery%20errors%2C%20you%20must%20enforce%20the%20partition%20filter%20via%20the%20dataset%20configuration%26nbsp%3B%28%5Bsource%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/models/helpers.py%23L1288-L2117%29%29.%0A%0AIf%20you%20need%20help%20crafti
 ng%20a%20%60fetch_values_predicate%60%20template%20for%20your%20use%20case%2C%20let%20me%20know%21)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/36676)


-- 
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: [I] Filter box can't retrieve values when using BigQuery with required partition filter [superset]

Posted by "Gwildor (via GitHub)" <gi...@apache.org>.
Gwildor closed issue #36676: Filter box can't retrieve values when using BigQuery with required partition filter
URL: https://github.com/apache/superset/issues/36676


-- 
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