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

fix: when taking struct fields they should be merged into the output in the correct order #3277

Merged
merged 4 commits into from
Dec 20, 2024

Conversation

westonpace
Copy link
Contributor

In various situations we need to fetch some fields from a struct and then later add more fields for the struct. For example, maybe we have a struct<big_string: string, filter: i32>. We might query with a filter on filter and then use late materialization to take big_string. When we do this we were previously creating struct<filter: i32, big_string: string> which would cause issues since that isn't the correct data type.

In creating this fix I added a new Projection concept and I would like to slowly replace a lot of the places where we use schemas as projections to use Projection instead. Not necessarily for performance but more for convenience.

@github-actions github-actions bot added bug Something isn't working python labels Dec 19, 2024
Comment on lines 262 to 268
def test_struct_field_order(tmp_path):
data = pa.table({"struct": [{"x": i, "y": i} for i in range(10)]})
dataset = lance.write_dataset(data, tmp_path)
result = dataset.to_table(filter="struct.y > 5")

expected = pa.table({"struct": [{"x": i, "y": i} for i in range(6, 10)]})
assert result == expected
Copy link
Contributor

Choose a reason for hiding this comment

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

TBH, I'm not 100% clear what this is testing. Just that we can filter on struct columns?

Copy link
Contributor Author

@westonpace westonpace Dec 19, 2024

Choose a reason for hiding this comment

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

Yes, well, more specifically that we can filter on struct columns and the resulting data has the correct order. I can add a comment. This was the original test failure that I was working downards to fix. Previously it was returning pa.table({"struct": [{"y": i, "x": i} for i in range(6, 10)]}) which failed the assert.

.dataset
.empty_projection()
.union_schema(&self.projection_plan.physical_schema)
.subtract_predicate(|field| !self.is_early_field(field));
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this subtract_predicate operator!

@codecov-commenter
Copy link

codecov-commenter commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 83.26241% with 118 lines in your changes missing coverage. Please review.

Project coverage is 79.07%. Comparing base (2b29487) to head (fb2df4d).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
rust/lance-core/src/datatypes/schema.rs 67.27% 48 Missing and 6 partials ⚠️
rust/lance-core/src/datatypes/field.rs 72.81% 25 Missing and 3 partials ⚠️
rust/lance-arrow/src/lib.rs 91.59% 10 Missing ⚠️
rust/lance/src/io/exec/take.rs 95.37% 2 Missing and 6 partials ⚠️
rust/lance/src/io/exec/optimizer.rs 89.65% 5 Missing and 1 partial ⚠️
rust/lance/src/dataset/scanner.rs 89.47% 0 Missing and 4 partials ⚠️
rust/lance/src/dataset/write/merge_insert.rs 82.60% 0 Missing and 4 partials ⚠️
rust/lance/src/datafusion/logical_plan.rs 80.00% 0 Missing and 1 partial ⚠️
rust/lance/src/dataset.rs 90.90% 0 Missing and 1 partial ⚠️
rust/lance/src/dataset/fragment.rs 80.00% 0 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3277      +/-   ##
==========================================
+ Coverage   78.80%   79.07%   +0.26%     
==========================================
  Files         246      246              
  Lines       86637    87471     +834     
  Branches    86637    87471     +834     
==========================================
+ Hits        68278    69167     +889     
+ Misses      15529    15438      -91     
- Partials     2830     2866      +36     
Flag Coverage Δ
unittests 79.07% <83.26%> (+0.26%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@westonpace westonpace merged commit 805438f into lancedb:main Dec 20, 2024
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants