Skip to content

Conversation

@ovr
Copy link
Member

@ovr ovr commented Jul 3, 2025

This PR allows filters to be pushed down with DATE_PART('year') by pushing it as inDateRange. Now, such queries will be accelerated with pre-aggregations.

image
ovr=> explain select count(*), date_part('YEAR', created) as year from orders where date_part('YEAR', created) = '2022' group by year;
   plan_type   |                                                                                               plan                                                                                                
---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 logical_plan  | Projection: #COUNT(UInt8(1)), #datepart(Utf8("year"),orders.created) AS year                                                                                                                     +
               |   Aggregate: groupBy=[[datepart(Utf8("year"), #orders.datepart(Utf8("year"),orders.created)) AS datepart(Utf8("year"),orders.created)]], aggr=[[SUM(#orders.COUNT(UInt8(1))) AS COUNT(UInt8(1))]]+
               |     CubeScan: request={                                                                                                                                                                          +
               |   "measures": [                                                                                                                                                                                  +
               |     "orders.count"                                                                                                                                                                               +
               |   ],                                                                                                                                                                                             +
               |   "dimensions": [],                                                                                                                                                                              +
               |   "segments": [],                                                                                                                                                                                +
               |   "timeDimensions": [                                                                                                                                                                            +
               |     {                                                                                                                                                                                            +
               |       "dimension": "orders.created",                                                                                                                                                             +
               |       "granularity": "year",                                                                                                                                                                     +
               |       "dateRange": [                                                                                                                                                                             +
               |         "2022-01-01",                                                                                                                                                                            +
               |         "2022-12-31"                                                                                                                                                                             +
               |       ]                                                                                                                                                                                          +
               |     }                                                                                                                                                                                            +
               |   ],                                                                                                                                                                                             +
               |   "order": []                                                                                                                                                                                    +
               | }
 physical_plan | ProjectionExec: expr=[COUNT(UInt8(1))@1 as COUNT(UInt8(1)), datepart(Utf8("year"),orders.created)@0 as year]                                                                                     +
               |   HashAggregateExec: mode=FinalPartitioned, gby=[datepart(Utf8("year"),orders.created)@0 as datepart(Utf8("year"),orders.created)], aggr=[COUNT(UInt8(1))]                                       +
               |     CoalesceBatchesExec: target_batch_size=4096                                                                                                                                                  +
               |       RepartitionExec: partitioning=Hash([Column { name: "datepart(Utf8(\"year\"),orders.created)", index: 0 }], 14)                                                                             +
               |         HashAggregateExec: mode=Partial, gby=[datepart(year, datepart(Utf8("year"),orders.created)@0) as datepart(Utf8("year"),orders.created)], aggr=[COUNT(UInt8(1))]                          +
               |           CubeScanExecutionPlan, Request:                                                                                                                                                        +
               | {"measures":["orders.count"],"dimensions":[],"segments":[],"timeDimensions":[{"dimension":"orders.created","granularity":"year","dateRange":["2022-01-01","2022-12-31"]}],"order":[]}            +
               | 
(2 rows)

@ovr ovr requested a review from a team as a code owner July 3, 2025 13:27
@codecov
Copy link

codecov bot commented Jul 3, 2025

Codecov Report

Attention: Patch coverage is 97.90576% with 4 lines in your changes missing coverage. Please review.

Project coverage is 84.25%. Comparing base (4f5e5dc) to head (82be8ff).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...besql/cubesql/src/compile/rewrite/rules/filters.rs 95.83% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9749      +/-   ##
==========================================
+ Coverage   84.22%   84.25%   +0.02%     
==========================================
  Files         231      231              
  Lines       85494    85650     +156     
==========================================
+ Hits        72009    72163     +154     
- Misses      13485    13487       +2     
Flag Coverage Δ
cubesql 84.25% <97.90%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ovr ovr added the api:sql Issues related to SQL API label Jul 3, 2025
@ovr ovr changed the title feat(cubesql): Support filter push down for date_part('year', ?col) =… feat(cubesql): Filter push down for date_part('year', ?col) = ?literal Jul 3, 2025
@ovr ovr merged commit f952cf7 into master Jul 3, 2025
94 of 95 checks passed
@ovr ovr deleted the CORE-1752-mdx-date-filter-not-working-with-pre-aggs branch July 3, 2025 17:42
Frank-TXS pushed a commit to Helge-TXS/cube that referenced this pull request Aug 5, 2025
cube-js#9749)

Allowing filters to be pushed down with DATE_PART('year') by pushing it as inDateRange. Now, such queries will be accelerated with pre-aggregations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api:sql Issues related to SQL API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants