Skip to content

Commit

Permalink
fix: Project last column if count query (#16569)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored May 29, 2024
1 parent 4048c3a commit acfc767
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ pub(super) fn process_projection(
// the whole file while we only want the count
if exprs.len() == 1 && is_count(exprs[0].node(), expr_arena) {
let input_schema = lp_arena.get(input).schema(lp_arena);
// simply select the first column
let (first_name, _) = input_schema.try_get_at_index(0)?;
// simply select the last column
// NOTE: the first can be the inserted index column, so that might not work
let (first_name, _) = input_schema.try_get_at_index(input_schema.len() - 1)?;
let expr = expr_arena.add(AExpr::Column(ColumnName::from(first_name.as_str())));
if !acc_projections.is_empty() {
check_double_projection(
Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/unit/io/test_lazy_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def test_row_index(foods_parquet_path: Path) -> None:
assert df["foo"].to_list() == [10, 16, 21, 23, 24, 30, 35]


def test_row_index_len_16543(foods_parquet_path: Path) -> None:
q = pl.scan_parquet(foods_parquet_path).with_row_index()
assert q.select(pl.all()).select(pl.len()).collect().item() == 27


@pytest.mark.write_disk()
def test_categorical_parquet_statistics(tmp_path: Path) -> None:
tmp_path.mkdir(exist_ok=True)
Expand Down

0 comments on commit acfc767

Please sign in to comment.