Skip to content

Commit 6ef38f3

Browse files
more tests, casting fix
1 parent 7ef116e commit 6ef38f3

6 files changed

Lines changed: 260 additions & 26 deletions

File tree

packages/bigframes/bigframes/core/compile/polars/compiler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import bigframes.operations.numeric_ops as num_ops
4040
import bigframes.operations.string_ops as string_ops
4141
from bigframes.core import agg_expressions, identifiers, nodes, ordering, window_spec
42-
from bigframes.core.compile.polars import lowering
4342

4443
polars_installed = True
4544
if TYPE_CHECKING:
@@ -652,6 +651,8 @@ def compile(self, plan: nodes.BigFrameNode) -> pl.LazyFrame:
652651
node = nodes.bottom_up(node, bigframes.core.rewrite.rewrite_slice)
653652
node = bigframes.core.rewrite.pull_out_window_order(node)
654653
node = bigframes.core.rewrite.schema_binding.bind_schema_to_tree(node)
654+
from bigframes.core.compile import lowering
655+
655656
node = lowering.lower_ops_to_polars(node)
656657
return self.compile_node(node)
657658

@@ -743,6 +744,8 @@ def compile_join(self, node: nodes.JoinNode):
743744
left_on = []
744745
right_on = []
745746
for left_ex, right_ex in node.conditions:
747+
from bigframes.core.compile import lowering
748+
746749
left_ex, right_ex = lowering._coerce_comparables(left_ex, right_ex)
747750
left_on.append(self.expr_compiler.compile_expression(left_ex))
748751
right_on.append(self.expr_compiler.compile_expression(right_ex))
@@ -762,6 +765,8 @@ def compile_isin(self, node: nodes.InNode):
762765
right = right.with_columns(pl.lit(True).alias(node.indicator_col.sql))
763766

764767
right_col = ex.ResolvedDerefOp.from_field(node.right_child.fields[0])
768+
from bigframes.core.compile import lowering
769+
765770
left_ex, right_ex = lowering._coerce_comparables(node.left_col, right_col)
766771

767772
left_pl_ex = self.expr_compiler.compile_expression(left_ex)

packages/bigframes/bigframes/core/compile/substrait/compiler.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import bigframes.operations.generic_ops as generic_ops
3131
import bigframes.operations.numeric_ops as numeric_ops
3232
import bigframes.operations.struct_ops as struct_ops
33-
from bigframes.core import bigframe_node, nodes
33+
from bigframes.core import bigframe_node, nodes, rewrite
3434
from bigframes.core.compile import lowering
3535

3636

@@ -54,6 +54,8 @@ def compile(self, plan: bigframe_node.BigFrameNode) -> Optional[bytes]:
5454
if not self.can_compile(plan):
5555
return None
5656

57+
# Need to bind types in before lowering
58+
plan = rewrite.bind_schema_to_tree(plan)
5759
plan = lowering.lower_ops_to_substrait(plan)
5860
pb_rel = self._compile_node(plan)
5961

@@ -674,7 +676,8 @@ def _compile_cast(
674676
type_dict = self._convert_type(target_dtype)
675677
json_format.ParseDict(type_dict, cast.type)
676678

677-
cast.failure_behavior = algebra_pb2.Expression.Cast.FAILURE_BEHAVIOR_RETURN_NULL
679+
# alternative: FAILURE_BEHAVIOR_RETURN_NULL not supported by acero
680+
cast.failure_behavior = algebra_pb2.Expression.Cast.FAILURE_BEHAVIOR_THROW_EXCEPTION
678681
return pb_expr
679682

680683
def _get_expression_dtype(

packages/bigframes/bigframes/core/rewrite/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
try_reduce_to_local_scan,
2626
try_reduce_to_table_scan,
2727
)
28+
from bigframes.core.rewrite.schema_binding import bind_schema_to_tree
2829
from bigframes.core.rewrite.select_pullup import defer_selection
2930
from bigframes.core.rewrite.slices import pull_out_limit, pull_up_limits, rewrite_slice
3031
from bigframes.core.rewrite.timedeltas import rewrite_timedelta_expressions
@@ -37,6 +38,7 @@
3738

3839
__all__ = [
3940
"as_sql_nodes",
41+
"bind_schema_to_tree",
4042
"extract_ctes",
4143
"legacy_join_as_projection",
4244
"try_row_join",

packages/bigframes/tests/system/small/engines/test_filtering.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@
2424
REFERENCE_ENGINE = polars_executor.PolarsExecutor()
2525

2626

27-
@pytest.mark.parametrize("engine", ["polars", "bq", "bq-sqlglot"], indirect=True)
27+
@pytest.mark.parametrize(
28+
"engine",
29+
[
30+
"polars",
31+
"bq",
32+
"bq-sqlglot",
33+
"substrait-datafusion",
34+
"substrait-acero",
35+
],
36+
indirect=True,
37+
)
2838
def test_engines_filter_bool_col(
2939
scalars_array_value: array_value.ArrayValue,
3040
engine,
@@ -35,7 +45,17 @@ def test_engines_filter_bool_col(
3545
assert_equivalence_execution(node, REFERENCE_ENGINE, engine)
3646

3747

38-
@pytest.mark.parametrize("engine", ["polars", "bq", "bq-sqlglot"], indirect=True)
48+
@pytest.mark.parametrize(
49+
"engine",
50+
[
51+
"polars",
52+
"bq",
53+
"bq-sqlglot",
54+
"substrait-datafusion",
55+
"substrait-acero",
56+
],
57+
indirect=True,
58+
)
3959
def test_engines_filter_expr_cond(
4060
scalars_array_value: array_value.ArrayValue,
4161
engine,
@@ -47,7 +67,17 @@ def test_engines_filter_expr_cond(
4767
assert_equivalence_execution(node, REFERENCE_ENGINE, engine)
4868

4969

50-
@pytest.mark.parametrize("engine", ["polars", "bq", "bq-sqlglot"], indirect=True)
70+
@pytest.mark.parametrize(
71+
"engine",
72+
[
73+
"polars",
74+
"bq",
75+
"bq-sqlglot",
76+
"substrait-datafusion",
77+
"substrait-acero",
78+
],
79+
indirect=True,
80+
)
5181
def test_engines_filter_true(
5282
scalars_array_value: array_value.ArrayValue,
5383
engine,
@@ -57,7 +87,17 @@ def test_engines_filter_true(
5787
assert_equivalence_execution(node, REFERENCE_ENGINE, engine)
5888

5989

60-
@pytest.mark.parametrize("engine", ["polars", "bq", "bq-sqlglot"], indirect=True)
90+
@pytest.mark.parametrize(
91+
"engine",
92+
[
93+
"polars",
94+
"bq",
95+
"bq-sqlglot",
96+
"substrait-datafusion",
97+
"substrait-acero",
98+
],
99+
indirect=True,
100+
)
61101
def test_engines_filter_false(
62102
scalars_array_value: array_value.ArrayValue,
63103
engine,

0 commit comments

Comments
 (0)