Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Data] Avoid pickling LanceFragment when creating read tasks for Lance #45392

Merged
merged 3 commits into from
May 20, 2024

Conversation

c21
Copy link
Contributor

@c21 c21 commented May 16, 2024

Why are these changes needed?

Avoid pickling LanceFragment when creating read tasks for Lance, as this is expensive.

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: Cheng Su <scnju13@gmail.com>
@c21 c21 added the go Trigger full test run on premerge label May 16, 2024
Signed-off-by: Cheng Su <scnju13@gmail.com>
Comment on lines 47 to 51
num_rows = sum([f.count_rows() for f in fragments])
input_files = [
data_file.path() for f in fragments for data_file in f.data_files()
]

Choose a reason for hiding this comment

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

I think you can still keep these. We've established that count_rows is not the slow part. In fact, it's even faster than get_fragments().

Also, small nit: you don't need the [] inside of sum. If you omit them you get a generator expression which bypasses the need to allocate the whole list.

num_rows = sum(f.count_rows() for f in fragments)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, updated.

Comment on lines 80 to 84
for fragment_id in fragment_ids:
fragment = lance_ds.get_fragment(fragment_id)
batches = fragment.to_batches(columns=columns, filter=row_filter)
for batch in batches:
yield pyarrow.Table.from_batches([batch])

Choose a reason for hiding this comment

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

If you wanted something that did some IO prefetching, you could instead do:

Suggested change
for fragment_id in fragment_ids:
fragment = lance_ds.get_fragment(fragment_id)
batches = fragment.to_batches(columns=columns, filter=row_filter)
for batch in batches:
yield pyarrow.Table.from_batches([batch])
fragments = [lance_ds.get_fragment(id) for id in fragment_ids]
scanner = lance_ds.scanner(
columns,
filter=row_filter,
fragments=fragments,
)
for batch in scanner.to_reader():
yield pyarrow.Table.from_batches([batch])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, updated.

Signed-off-by: Cheng Su <scnju13@gmail.com>
@c21 c21 changed the title [Data] Avoid calling count_rows() when creating read tasks for Lance [Data] Avoid pickling LanceFragment when creating read tasks for Lance May 20, 2024
@c21 c21 merged commit e2028e0 into ray-project:master May 20, 2024
6 checks passed
@c21 c21 deleted the fix-lance branch May 20, 2024 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Trigger full test run on premerge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants