-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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: IS NULL
filter operator for numeric columns
#13496
Conversation
const isString = | ||
firstValue !== undefined && Number.isNaN(Number(firstValue)); | ||
const quote = isString ? "'" : ''; | ||
const [prefix, suffix] = isMulti ? ['(', ')'] : ['', '']; | ||
const formattedComparators = comparatorArray.map( | ||
val => `${quote}${isString ? val.replace("'", "''") : val}${quote}`, | ||
val => | ||
`${quote}${isString ? String(val).replace("'", "''") : val}${quote}`, |
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.
utils.FilterOperator.NOT_IN.value, | ||
): | ||
cond = col_obj.get_sqla_col().in_(eq) | ||
if isinstance(eq, str) and NULL_STRING in eq: |
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.
NULL_STRING
is already parsed to None
in filter_values_handler
, so this is not needed.
if eq: | ||
cond = or_(is_null_cond, col_obj.get_sqla_col().in_(eq)) | ||
else: | ||
cond = is_null_cond |
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.
Do additional check to make the generated where clause cleaner for when there are NULL
in the IN
list.
Previously it may generate:
WHERE abc in (NULL, 123) OR abc IS NULL
Now it generates:
WHERE abc in (123, ) OR abc IS NOT NULL
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.
why NOT NULL in the last expression ?
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.
Oh, it was a typo... Thanks for noting.
Codecov Report
@@ Coverage Diff @@
## master #13496 +/- ##
==========================================
- Coverage 77.66% 77.51% -0.16%
==========================================
Files 902 902
Lines 45873 45873
Branches 5598 5596 -2
==========================================
- Hits 35628 35558 -70
- Misses 10111 10181 +70
Partials 134 134
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
values = values[0] | ||
else: | ||
values = None | ||
values = values[0] if values else None |
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.
if values could be dangerous, as [],0, None would return false, it would be nice to be a bit more specific in the check.
cond, | ||
col_obj.get_sqla_col() # pylint: disable=singleton-comparison | ||
== None, | ||
if is_list_target: |
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.
is it possible to add unit tests here?
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.
Done.
More granular logics could be handled by actual unit tests when we break down the query generator. I also added "revisit:add-tests" label to mark this as a followup item.
if eq: | ||
cond = or_(is_null_cond, col_obj.get_sqla_col().in_(eq)) | ||
else: | ||
cond = is_null_cond |
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.
why NOT NULL in the last expression ?
Thanks for the fix! |
SUMMARY
Fixes #13229 where filters for numeric columns could not use
IS NULL
andIS NOT NULL
operators in SIMPLE mode.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before
After
TEST PLAN
Manual testing
ADDITIONAL INFORMATION