-
Notifications
You must be signed in to change notification settings - Fork 72
Extend attempt_predicate_pushdown to accept additional filters as arguments #1138
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
Closed
Closed
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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import pandas as pd | ||
| import pytest | ||
| from dask import dataframe as dd | ||
| from dask.utils_test import hlg_layer | ||
|
|
||
| from dask_sql.physical.utils.filter import attempt_predicate_pushdown | ||
| from dask_sql.utils import Pluggable, is_frame | ||
|
|
||
|
|
||
|
|
@@ -52,3 +54,96 @@ def test_overwrite(): | |
|
|
||
| assert PluginTest1.get_plugin("some_key") == "value_2" | ||
| assert PluginTest1().get_plugin("some_key") == "value_2" | ||
|
|
||
|
|
||
| def test_predicate_pushdown(parquet_ddf): | ||
|
Contributor
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. This test seems unnecessarily intimidating to me :) Perhaps this should be broken into several different tests? |
||
| filtered_df = parquet_ddf[parquet_ddf["a"] > 1] | ||
| pushdown_df = attempt_predicate_pushdown(filtered_df) | ||
| got_filters = hlg_layer(pushdown_df.dask, "read-parquet").creation_info["kwargs"][ | ||
| "filters" | ||
| ] | ||
| got_filters = frozenset(frozenset(v) for v in got_filters) | ||
| expected_filters = [[("a", ">", 1)]] | ||
| expected_filters = frozenset(frozenset(v) for v in expected_filters) | ||
| assert got_filters == expected_filters | ||
|
|
||
| filtered_df = parquet_ddf[ | ||
| (parquet_ddf["a"] > 1) & (parquet_ddf["b"] < 2) | (parquet_ddf["a"] == -1) | ||
| ] | ||
|
|
||
| pushdown_df = attempt_predicate_pushdown(filtered_df) | ||
| got_filters = hlg_layer(pushdown_df.dask, "read-parquet").creation_info["kwargs"][ | ||
| "filters" | ||
| ] | ||
| got_filters = frozenset(frozenset(v) for v in got_filters) | ||
| expected_filters = [[("a", ">", 1), ("b", "<", 2)], [("a", "==", -1)]] | ||
| expected_filters = frozenset(frozenset(v) for v in expected_filters) | ||
| assert got_filters == expected_filters | ||
|
|
||
| disjunctive_filters = [("c", "in", ("A", "B", "C"))] | ||
| pushdown_df = attempt_predicate_pushdown( | ||
| filtered_df, disjunctive_filters=disjunctive_filters | ||
| ) | ||
| got_filters = hlg_layer(pushdown_df.dask, "read-parquet").creation_info["kwargs"][ | ||
| "filters" | ||
| ] | ||
| got_filters = frozenset(frozenset(v) for v in got_filters) | ||
| expected_filters = [ | ||
| [("b", "<", 2), ("a", ">", 1)], | ||
| [("a", "==", -1)], | ||
| [("c", "in", ("A", "B", "C"))], | ||
| ] | ||
| expected_filters = frozenset(frozenset(v) for v in expected_filters) | ||
| assert got_filters == expected_filters | ||
|
|
||
| disjunctive_filters = [("c", "in", ("A", "B", "C")), ("b", "in", (5, 6, 7))] | ||
| pushdown_df = attempt_predicate_pushdown( | ||
| filtered_df, disjunctive_filters=disjunctive_filters | ||
| ) | ||
| got_filters = hlg_layer(pushdown_df.dask, "read-parquet").creation_info["kwargs"][ | ||
| "filters" | ||
| ] | ||
| got_filters = frozenset(frozenset(v) for v in got_filters) | ||
| expected_filters = [ | ||
| [("b", "<", 2), ("a", ">", 1)], | ||
| [("a", "==", -1)], | ||
| [("c", "in", ("A", "B", "C"))], | ||
| [("b", "in", (5, 6, 7))], | ||
| ] | ||
| expected_filters = frozenset(frozenset(v) for v in expected_filters) | ||
| assert got_filters == expected_filters | ||
|
|
||
| conjunctive_filters = [("c", "in", ("A", "B", "C"))] | ||
| pushdown_df = attempt_predicate_pushdown( | ||
| filtered_df, conjunctive_filters=conjunctive_filters | ||
| ) | ||
| got_filters = hlg_layer(pushdown_df.dask, "read-parquet").creation_info["kwargs"][ | ||
| "filters" | ||
| ] | ||
| got_filters = frozenset(frozenset(v) for v in got_filters) | ||
| expected_filters = [ | ||
| [("b", "<", 2), ("a", ">", 1), ("c", "in", ("A", "B", "C"))], | ||
| [("a", "==", -1), ("c", "in", ("A", "B", "C"))], | ||
| ] | ||
| expected_filters = frozenset(frozenset(v) for v in expected_filters) | ||
| assert got_filters == expected_filters | ||
|
|
||
| conjunctive_filters = [("c", "in", ("A", "B", "C")), ("a", "<=", 100)] | ||
| disjunctive_filters = [("b", "in", (5, 6, 7)), ("a", ">=", 100)] | ||
| pushdown_df = attempt_predicate_pushdown( | ||
| filtered_df, | ||
| conjunctive_filters=conjunctive_filters, | ||
| disjunctive_filters=disjunctive_filters, | ||
| ) | ||
| got_filters = hlg_layer(pushdown_df.dask, "read-parquet").creation_info["kwargs"][ | ||
| "filters" | ||
| ] | ||
| got_filters = frozenset(frozenset(v) for v in got_filters) | ||
| expected_filters = [ | ||
| [("b", "<", 2), ("a", ">", 1), ("c", "in", ("A", "B", "C")), ("a", "<=", 100)], | ||
| [("a", "==", -1), ("c", "in", ("A", "B", "C")), ("a", "<=", 100)], | ||
| [("b", "in", (5, 6, 7)), ("c", "in", ("A", "B", "C")), ("a", "<=", 100)], | ||
| [("a", ">=", 100), ("c", "in", ("A", "B", "C")), ("a", "<=", 100)], | ||
| ] | ||
| expected_filters = frozenset(frozenset(v) for v in expected_filters) | ||
| assert got_filters == expected_filters | ||
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.
I think this makes sense, and I think I (mostly) like the approach. However, it does seem possible that you will eventually want to do things that are currently prohibited. Some examples:
Not sure if any of these cases are important or meaningful at all. Either way, I'm pretty sure you could support (1) and (3) later if needed.
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.
Thanks for the comments. You're right that all three cases aren't really support with the current addition and it only helps for passing additional filters that get applied to everything.
Ideally I'd like to consolidate the
conjunctiveanddisjunctiveargs into a single arg in dnf form which allows some flexibility with the additional filters but doesn't allow good interactivity with existing ones.While we're unable to return a full dnf for a dataframe rather than having some existing filters coming via the hlg and some passed in additionally, I can't think of a nice way for both to interact cleanly without some good tracking around how we represent that information.