8000 feat: Add filter pushdown to hybrid engine by TrevorBergeron · Pull Request #1871 · googleapis/python-bigquery-dataframes · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bigframes/session/polars_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
nodes.ProjectionNode,
nodes.SliceNode,
nodes.AggregateNode,
nodes.FilterNode,
)

_COMPATIBLE_SCALAR_OPS = (
Expand Down
67 changes: 67 additions & 0 deletions tests/system/small/engines/test_filtering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest

from bigframes.core import array_value, expression, nodes
import bigframes.operations as ops
from bigframes.session import polars_executor
from bigframes.testing.engine_utils import assert_equivalence_execution

pytest.importorskip("polars")

# Polars used as reference as its fast and local. Generally though, prefer gbq engine where they disagree.
REFERENCE_ENGINE = polars_executor.PolarsExecutor()


@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
def test_engines_filter_bool_col(
scalars_array_value: array_value.ArrayValue,
engine,
):
node = nodes.FilterNode(
scalars_array_value.node, predicate=expression.deref("bool_col")
)
assert_equivalence_execution(node, REFERENCE_ENGINE, engine)


@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
def test_engines_filter_expr_cond(
scalars_array_value: array_value.ArrayValue,
engine,
):
predicate = ops.gt_op.as_expr(
expression.deref("float64_col"), expression.deref("int64_col")
)
node = nodes.FilterNode(scalars_array_value.node, predicate=predicate)
assert_equivalence_execution(node, REFERENCE_ENGINE, engine)


@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
def test_engines_filter_true(
scalars_array_value: array_value.ArrayValue,
engine,
):
predicate = expression.const(True)
node = nodes.FilterNode(scalars_array_value.node, predicate=predicate)
assert_equivalence_execution(node, REFERENCE_ENGINE, engine)


@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
def test_engines_filter_false(
scalars_array_value: array_value.ArrayValue,
engine,
):
predicate = expression.const(False)
node = nodes.FilterNode(scalars_array_value.node, predicate=predicate)
assert_equivalence_execution(node, REFERENCE_ENGINE, engine)
3 changes: 1 addition & 2 deletions tests/system/small/test_polars_execution.py
57FA
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def test_polar_execution_sorted_filtered(session_w_polars, scalars_pandas_df_ind
.to_pandas()
)

# Filter and isnull not supported by polar engine yet, so falls back to bq execution
assert session_w_polars._metrics.execution_count == (execution_count_before + 1)
assert session_w_polars._metrics.execution_count == execution_count_before
assert_pandas_df_equal(bf_result, pd_result)


Expand Down
0