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

feat: support merge by row_id, row_addr #3254

Merged
merged 3 commits into from
Dec 18, 2024

Conversation

chenkovsky
Copy link
Contributor

No description provided.

@github-actions github-actions bot added the enhancement New feature or request label Dec 16, 2024
@chenkovsky chenkovsky changed the title feat: merge by row_id, row_addr feat: support merge by row_id, row_addr Dec 16, 2024
Copy link
Contributor

@wjones127 wjones127 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @chenkovsky. I would like to see a few improvements to the unit tests, and then this is ready to go.

Comment on lines 3138 to 3139
let test_dir = tempdir().unwrap();
let test_uri = test_dir.path().to_str().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

If we aren't testing anything about the files, let's use an in-memory dataset instead.

Suggested change
let test_dir = tempdir().unwrap();
let test_uri = test_dir.path().to_str().unwrap();

Comment on lines 3149 to 3153
Dataset::write(data, test_uri, Some(write_params.clone()))
.await
.unwrap();

let mut dataset = Dataset::open(test_uri).await.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

If you re-use the dataset instance from write(), you can just use an in-memory dataset:

Suggested change
Dataset::write(data, test_uri, Some(write_params.clone()))
.await
.unwrap();
let mut dataset = Dataset::open(test_uri).await.unwrap();
let dataset = Dataset::write(data, "memory://", Some(write_params.clone()))
.await
.unwrap();

Comment on lines 3163 to 3168
let new_batch =
RecordBatch::try_new(new_schema.clone(), vec![row_ids.clone(), row_ids.clone()])
.unwrap();
let new_data = RecordBatchIterator::new(vec![Ok(new_batch)], new_schema.clone());
dataset.merge(new_data, ROW_ID, "rowid").await.unwrap();
dataset.validate().await.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like us to assert a few more things in this test:

  1. dataset has the expected final schema key, value, new_value.
  2. The values are what we expect. For this, you should avoid using the same values in each column. Otherwise, the test could pass even if there is a bug that uses the wrong column's values. Right now, you use row_ids.clone() for both rowid and new_value.
  3. This works even if you shuffle the data. I would recommend using take_record_batch() to reorder the new_batch so the row ids are out-of-order.

Comment on lines 3130 to 3131
// This test also tests "null filling" when merging (e.g. when keys do not match
// we need to insert nulls)
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the null filling? It seems like you are providing every row id, unless I am missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where is the null filling? It seems like you are providing every row id, unless I am missing something.

sorry, I copy and modify another test

Comment on lines 3171 to 3176
#[rstest]
#[tokio::test]
async fn test_merge_on_row_addr(
#[values(LanceFileVersion::Legacy, LanceFileVersion::Stable)]
data_storage_version: LanceFileVersion,
#[values(false, true)] use_stable_row_id: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments from the row id test apply here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.88%. Comparing base (83b8efd) to head (b216aa0).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3254      +/-   ##
==========================================
+ Coverage   78.47%   78.88%   +0.41%     
==========================================
  Files         245      246       +1     
  Lines       85088    86568    +1480     
  Branches    85088    86568    +1480     
==========================================
+ Hits        66772    68292    +1520     
+ Misses      15501    15450      -51     
- Partials     2815     2826      +11     
Flag Coverage Δ
unittests 78.88% <100.00%> (+0.41%) ⬆️

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.

Copy link
Contributor

@wjones127 wjones127 left a comment

Choose a reason for hiding this comment

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

Looks better. Have a few suggestions to clean up the tests. Then I think this is ready to be merged.

Comment on lines 3271 to 3278
let result = dataset
.scan()
.try_into_stream()
.await
.unwrap()
.try_collect::<Vec<_>>()
.await
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use .try_into_batch() to immediately collect the results in one batch. Will need to remove the for loop below too.

Suggested change
let result = dataset
.scan()
.try_into_stream()
.await
.unwrap()
.try_collect::<Vec<_>>()
.await
.unwrap();
let result = dataset
.scan()
.try_into_batch()
.await
.unwrap();

Comment on lines 3280 to 3285
let key = batch
.column_by_name("key")
.unwrap()
.as_any()
.downcast_ref::<arrow_array::Int32Array>()
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

For tests, you can use RecordBatch["<column>"] to access a column by name. Also, .as_primitive() is typically shorter. Both of these are mostly suitable for tests because they can panic.

Suggested change
let key = batch
.column_by_name("key")
.unwrap()
.as_any()
.downcast_ref::<arrow_array::Int32Array>()
.unwrap();
let key = batch["key"].as_primitive::<Int32Type>();

@wjones127 wjones127 merged commit 95f98b3 into lancedb:main Dec 18, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants