Skip to content

Commit

Permalink
refactor(rust): Temporarily disable common subplan elim for new-strea…
Browse files Browse the repository at this point in the history
…ming (#20374)
  • Loading branch information
orlp authored Dec 20, 2024
1 parent 6965ac7 commit 5f791b4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
8 changes: 6 additions & 2 deletions crates/polars-lazy/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,15 @@ impl LazyFrame {
opt_state &= !OptFlags::COMM_SUBPLAN_ELIM;
}

// The new streaming engine can't deal with the way the common
// subexpression elimination adds length-incorrect with_columns.
#[cfg(feature = "cse")]
if new_streaming {
// The new streaming engine can't deal with the way the common
// subexpression elimination adds length-incorrect with_columns.
opt_state &= !OptFlags::COMM_SUBEXPR_ELIM;

// The new streaming engine can't yet deal with the cache nodes
// introduced by common subplan elimination.
opt_state &= !OptFlags::COMM_SUBPLAN_ELIM;
}

let lp_top = optimize(
Expand Down
8 changes: 6 additions & 2 deletions py-polars/tests/unit/operations/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,14 @@ def test_join() -> None:
}
)

joined = df_left.join(df_right, left_on="a", right_on="a").sort("a")
joined = df_left.join(
df_right, left_on="a", right_on="a", maintain_order="left_right"
).sort("a")
assert_series_equal(joined["b"], pl.Series("b", [1, 3, 2, 2]))

joined = df_left.join(df_right, left_on="a", right_on="a", how="left").sort("a")
joined = df_left.join(
df_right, left_on="a", right_on="a", how="left", maintain_order="left_right"
).sort("a")
assert joined["c_right"].is_null().sum() == 1
assert_series_equal(joined["b"], pl.Series("b", [1, 3, 2, 2, 4]))

Expand Down
29 changes: 19 additions & 10 deletions py-polars/tests/unit/sql/test_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,36 @@ def test_join_cross_11927() -> None:
def test_join_inner(foods_ipc_path: Path, join_clause: str) -> None:
foods1 = pl.scan_ipc(foods_ipc_path)
foods2 = foods1 # noqa: F841
schema = foods1.collect_schema()

sort_clause = ", ".join(f'{c} ASC, "{c}:foods2" DESC' for c in schema)
out = pl.sql(
f"""
SELECT *
FROM foods1
INNER JOIN foods2 {join_clause}
ORDER BY {sort_clause}
LIMIT 2
""",
eager=True,
)

assert out.to_dict(as_series=False) == {
"category": ["vegetables", "vegetables"],
"calories": [45, 20],
"fats_g": [0.5, 0.0],
"sugars_g": [2, 2],
"category:foods2": ["vegetables", "vegetables"],
"calories:foods2": [45, 45],
"fats_g:foods2": [0.5, 0.5],
"sugars_g:foods2": [2, 2],
}
assert_frame_equal(
out,
pl.DataFrame(
{
"category": ["fruit", "fruit"],
"calories": [30, 30],
"fats_g": [0.0, 0.0],
"sugars_g": [3, 5],
"category:foods2": ["fruit", "fruit"],
"calories:foods2": [130, 130],
"fats_g:foods2": [0.0, 0.0],
"sugars_g:foods2": [25, 25],
}
),
check_dtypes=False,
)


@pytest.mark.parametrize(
Expand Down
1 change: 1 addition & 0 deletions py-polars/tests/unit/test_cse.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ def test_cse_and_schema_update_projection_pd() -> None:


@pytest.mark.debug
@pytest.mark.may_fail_auto_streaming
def test_cse_predicate_self_join(capfd: Any, monkeypatch: Any) -> None:
monkeypatch.setenv("POLARS_VERBOSE", "1")
y = pl.LazyFrame({"a": [1], "b": [2], "y": [3]})
Expand Down

0 comments on commit 5f791b4

Please sign in to comment.