-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(schema-compiler): fix FILTER_PARAMS to populate set and notSet filters in cube's SQL query #8937
base: master
Are you sure you want to change the base?
fix(schema-compiler): fix FILTER_PARAMS to populate set and notSet filters in cube's SQL query #8937
Conversation
…lters in cube's SQL query
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 8 Skipped Deployments
|
Hi @KSDaemon, @RusovDmitriy, @paveltiunov - can you please review this PR? Thanks in advance. |
Hi @sumeetgajjar Thank you for contributing! I'll have a look! |
3 tests under This is primarily because the
Earlier (before this change) SQL was
cube(`visitors`, {
sql: `
select * from visitors WHERE ${FILTER_PARAMS.visitors.createdAt.filter('created_at')}
AND ${FILTER_PARAMS.ReferenceOriginalSql.createdAt.filter('created_at')}
`, This makes sense as the time dimension filter values |
Given each of the DATE_OPERATORS_Where methods (i.e. inDateRangeWhere, notInDateRangeWhere, etc) exactly knows its required parameters i.e.
One fix could be modifying each DATE_OPERATORS_Where method to return @KSDaemon - Does the above proposal sound good to you? |
… parameters are unavailable
Hi @KSDaemon - gentle ping, can you please take a look? This bug is directly impacting our production workflows and is leading to incorrect data being shown to the users. |
That makes sense. Seems to be good. I relaunched tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻 LGTM!
Thanks for the review @KSDaemon. A couple of questions,
|
Hi @KSDaemon, @paveltiunov, @igorlukanin - can you please help us merge this PR given it is already approved 😄? |
The presence of the following filters in a cube query:
set
,notSet
,eq NULL
orNOT eq NULL
renders the corresponding FILTER_PARAMS as1 = 1
irrespective of the cube or filter.This is because the
renderFilterParams
method skips invokingfilter.conditionSql
when converting afilter
to its corresponding SQL due to an emptyfilterParams
array.For
set
andnotSet
, the filter cannot have value(s).For
eq NULL
orNOT eq NULL
thenull
value is filtered by:cube/packages/cubejs-schema-compiler/src/adapter/BaseFilter.ts
Line 115 in 349597a
This leads to an empty
filterParams
array, thus, skipping the filter SQL, thereby returning1 = 1
.The issue becomes more serious when the query contains multiple filters on the same dimension.
Consider the following example:
Cube
Query
In the above case, the rendered query would be of the form:
The right branch of the OR predicate will always evaluate TRUE, thus, the majority of the SQL optimizers will remove the LEFT branch altogether to prevent unnecessary evaluations, thereby defeating the purpose of the FILTER_PARAMS filter pushdown.
This PR aims to fix the bug by restructuring the nested if-else block, thereby also improving the readability of the same.
Check List