-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(schema-compiler): fix FILTER_PARAMS to populate set and notSet filters in cube's SQL query #8937
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
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. |
KSDaemon
left a comment
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 😄? |
|
Hi @sumeetgajjar, Sorry for the late answers. Yeah, everything looks right. I think the one missing piece is real integration tests. Please add some tests to |
|
Hi @KSDaemon - I've added the Postgres integration tests. |
|
Hi @sumeetgajjar Thank you for providing the tests! That's great! Merging! |
The presence of the following filters in a cube query:
set,notSet,eq NULLorNOT eq NULLrenders the corresponding FILTER_PARAMS as1 = 1irrespective of the cube or filter.This is because the
renderFilterParamsmethod skips invokingfilter.conditionSqlwhen converting afilterto its corresponding SQL due to an emptyfilterParamsarray.For
setandnotSet, the filter cannot have value(s).For
eq NULLorNOT eq NULLthenullvalue is filtered by:cube/packages/cubejs-schema-compiler/src/adapter/BaseFilter.ts
Line 115 in 349597a
This leads to an empty
filterParamsarray, 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
{ "or": [ { "member": "MyCube.creation_time", "operator": "afterDate", "values": [ "2024-10-31T21:00:00.000Z" ] }, { "member": "MyCube.creation_time", "operator": "notSet" } ] }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