Skip to content

[data] fix lance count_rows not support filter - #53162

Closed
Jay-ju wants to merge 1 commit into
ray-project:masterfrom
Jay-ju:fix_lance_cnt_rows
Closed

Jay-ju wants to merge 1 commit into
ray-project:masterfrom
Jay-ju:fix_lance_cnt_rows

Conversation

@Jay-ju

@Jay-ju Jay-ju commented May 20, 2025

Copy link
Copy Markdown
Contributor

Why are these changes needed?

Related issue number

Checks

@Jay-ju
Jay-ju requested a review from a team as a code owner May 20, 2025 03:54
@Jay-ju
Jay-ju force-pushed the fix_lance_cnt_rows branch 3 times, most recently from 49644be to ebc48c8 Compare May 20, 2025 13:26

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why drop columns?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richardliaw This is related to lance-format/lance#3850. At the current stage, for lance's count_rows, it is required not to pass count_rows. However, this is something that needs to be modified by lance.

@Jay-ju
Jay-ju force-pushed the fix_lance_cnt_rows branch from ed1063c to 8faee0b Compare May 21, 2025 01:42
@richardliaw richardliaw added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels May 21, 2025
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jun 17, 2025
@richardliaw richardliaw added the community-contribution Contributed by the community label Jun 28, 2025
@github-actions github-actions Bot removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jun 28, 2025
jiaoew1991 pushed a commit to lance-format/lance-ray that referenced this pull request Jul 4, 2025
closes #15

We've identified that the count operation with filters returns incorrect
results in the current Lance connector implementation.

This issue has previously been addressed in our
ray-project/ray#53162 by @Jay-ju. We'll be
migrating the fix to this project to ensure:
1. Correct count results with various filter conditions
2. Proper handling of edge cases observed in our production workloads
@alexeykudinkin

Copy link
Copy Markdown
Contributor

@Jay-ju can you update PR description?

@gvspraveen gvspraveen added the @external-author-action-required Alternate tag for PRs where the author doesn't have labeling permission. label Jul 9, 2025
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jul 24, 2025
@github-actions

github-actions Bot commented Aug 7, 2025

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for your contribution!

@github-actions github-actions Bot closed this Aug 7, 2025
richardliaw pushed a commit that referenced this pull request Nov 17, 2026
## Description

Filtered Lance reads report fragment totals as exact output metadata.
For a 28-row table filtered to seven rows, `count()` can return 28 and
an 80/20 train/test split can produce 7/0 instead of 5/2.

Return unknown row-count metadata for filtered reads and retain fragment
counts for ordinary unfiltered reads. Scans with row-set-changing or
unrecognized active options also use unknown metadata. Read-task
planning does not perform a filtered count scan. Existing scanner
options, snapshot and fragment scope, and Ray task limits are preserved.

Ray computes filtered counts during execution; non-stratified splits
materialize when the count is unknown and reuse the result. Separate
actions on a non-deterministic filter may select different rows.
Count-only execution may read payload columns because the Lance reader
does not support automatic projection pushdown; users can explicitly
select columns when appropriate.

Regression coverage maps to the following changes:

- Four filtered-planning cases detect restoring fragment totals or
reintroducing a filtered planning scan.
- Six row-set option cases detect returning fragment totals for active
options; `limit=0` also detects treating zero as absent.
- A dictionary-valued search filter returns unknown planning metadata.
It fails with the original fragment totals and passes with the previous
pre-count implementation. This case does not execute Lance search.
- Public count/split checks for the direct filter and the
scanner-options filter fail with original fragment-total metadata. The
direct-filter case also checks an empty filtered result on the fixed
implementation.
- A pushed-filter count/split case includes a `take(1)` guard against an
extra planning scan. It passes against the original datasource but fails
when the previous planning scan is restored.
- A random-filter split checks output ratio, disjoint IDs and row counts
through the public API; it failed with the original fragment-total
metadata in the recorded control.
- The unfiltered fast-path test protects metadata counting without an
unnecessary data scan. It passes against the original datasource but
fails when unfiltered counts are made unknown. Feedback on retaining
these two targeted guards is welcome.

## Related issues

Fixes #67227.

#53162 addressed the same root cause but was closed without merging; no
active overlapping filtered-count fix was found. #66472 concerns
separate split-rounding and stratification issues.

## Additional information

Validation used the complete Ray Data Python source from this checkout
with the Ray 2.59.0 native wheel on Linux ARM64 / Python 3.12.14:

- `python -m pytest -v python/ray/data/tests/datasource/test_lance.py`:
45 passed with PyLance 4.0.0 / PyArrow 23.0.1, including 15 new
regression cases and one augmented existing version test. No tests were
skipped.
- Negative controls covered original fragment totals, the previous
filtered pre-count, zero-valued options treated as absent, and
unfiltered counts made unknown. Case-specific outcomes are summarized
above.
- The unchanged `limit=0` metadata and random-filter split cases
previously passed with PyLance 2.0.1 / PyArrow 23.0.1 and PyLance 12.0.0
/ PyArrow 23.0.1. These two-case results were reused after AST, fixture
and datasource fingerprint checks. The dictionary-filter case was
exercised on the primary baseline only.
- Ruff, import ordering, Black 22.10.0, configured Pydoclint and
whitespace checks passed.

These are Python-source tests with a released native runtime, not a
matching master native build. The runtime uses the existing fallback
that disables application-level lineage reconstruction; matching-runtime
CI is required before merge. No real S3 or media integration tests were
run for this test-only revision.

AI assistance: Codex was used for implementation, testing and
documentation.

---------

Signed-off-by: jiangxt2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues @external-author-action-required Alternate tag for PRs where the author doesn't have labeling permission. go add ONLY when ready to merge, run all tests stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants