-
Notifications
You must be signed in to change notification settings - Fork 14k
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: Native filter dynamic numeric search #24418
Merged
john-bodley
merged 1 commit into
apache:master
from
john-bodley:john-bodley--filter-select-like
Jun 21, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1173,7 +1173,14 @@ def handle_single_value(value: Optional[FilterValue]) -> Optional[FilterValue]: | |
if isinstance(value, str): | ||
value = value.strip("\t\n") | ||
|
||
if target_generic_type == utils.GenericDataType.NUMERIC: | ||
if ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to turn a blind eye to the fact that this function is copy-and-pasted in multiple places. Furthermore it's rather scary there's zero unit tests for the |
||
target_generic_type == utils.GenericDataType.NUMERIC | ||
and operator | ||
not in { | ||
utils.FilterOperator.ILIKE, | ||
utils.FilterOperator.LIKE, | ||
} | ||
): | ||
# For backwards compatibility and edge cases | ||
# where a column data type might have changed | ||
return utils.cast_to_num(value) | ||
|
@@ -1744,10 +1751,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma | |
tbl_column=col_obj, template_processor=template_processor | ||
) | ||
col_type = col_obj.type if col_obj else None | ||
col_spec = db_engine_spec.get_column_spec( | ||
native_type=col_type, | ||
# db_extra=self.database.get_extra(), | ||
) | ||
col_spec = db_engine_spec.get_column_spec(native_type=col_type) | ||
is_list_target = op in ( | ||
utils.FilterOperator.IN.value, | ||
utils.FilterOperator.NOT_IN.value, | ||
|
@@ -1766,7 +1770,6 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma | |
target_native_type=col_type, | ||
is_list_target=is_list_target, | ||
db_engine_spec=db_engine_spec, | ||
# db_extra=self.database.get_extra(), | ||
) | ||
if ( | ||
col_advanced_data_type != "" | ||
|
@@ -1848,10 +1851,17 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma | |
where_clause_and.append(sqla_col >= eq) | ||
elif op == utils.FilterOperator.LESS_THAN_OR_EQUALS.value: | ||
where_clause_and.append(sqla_col <= eq) | ||
elif op == utils.FilterOperator.LIKE.value: | ||
where_clause_and.append(sqla_col.like(eq)) | ||
elif op == utils.FilterOperator.ILIKE.value: | ||
where_clause_and.append(sqla_col.ilike(eq)) | ||
elif op in { | ||
utils.FilterOperator.ILIKE, | ||
utils.FilterOperator.LIKE, | ||
}: | ||
if target_generic_type != GenericDataType.STRING: | ||
sqla_col = sa.cast(sqla_col, sa.String) | ||
|
||
if utils.FilterOperator.LIKE.value: | ||
where_clause_and.append(sqla_col.like(eq)) | ||
else: | ||
where_clause_and.append(sqla_col.ilike(eq)) | ||
elif ( | ||
op == utils.FilterOperator.TEMPORAL_RANGE.value | ||
and isinstance(eq, str) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
btw i think
LIKE
can be enough for since it matches only numbers, right?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.
nvm. I don't find any performance benefit of using LIKE over ILIKE.
I'm good with it