-
Notifications
You must be signed in to change notification settings - Fork 245
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: execute_uncommitted
for merge insert
#3233
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,8 @@ use lance::dataset::{ | |
WriteParams, | ||
}; | ||
use lance::dataset::{ | ||
BatchInfo, BatchUDF, CommitBuilder, NewColumnTransform, UDFCheckpointStore, WriteDestination, | ||
BatchInfo, BatchUDF, CommitBuilder, MergeStats, NewColumnTransform, UDFCheckpointStore, | ||
WriteDestination, | ||
}; | ||
use lance::dataset::{ColumnAlteration, ProjectionRequest}; | ||
use lance::index::vector::utils::get_vector_type; | ||
|
@@ -199,20 +200,46 @@ impl MergeInsertBuilder { | |
.try_build() | ||
.map_err(|err| PyValueError::new_err(err.to_string()))?; | ||
|
||
let new_self = RT | ||
let (new_dataset, stats) = RT | ||
.spawn(Some(py), job.execute_reader(new_data))? | ||
.map_err(|err| PyIOError::new_err(err.to_string()))?; | ||
|
||
let dataset = self.dataset.bind(py); | ||
|
||
dataset.borrow_mut().ds = new_self.0; | ||
let merge_stats = new_self.1; | ||
let merge_dict = PyDict::new_bound(py); | ||
merge_dict.set_item("num_inserted_rows", merge_stats.num_inserted_rows)?; | ||
merge_dict.set_item("num_updated_rows", merge_stats.num_updated_rows)?; | ||
merge_dict.set_item("num_deleted_rows", merge_stats.num_deleted_rows)?; | ||
dataset.borrow_mut().ds = new_dataset; | ||
|
||
Ok(merge_dict.into()) | ||
Ok(Self::build_stats(&stats, py)?.into()) | ||
} | ||
|
||
pub fn execute_uncommitted<'a>( | ||
&mut self, | ||
new_data: &Bound<'a, PyAny>, | ||
) -> PyResult<(PyLance<Transaction>, Bound<'a, PyDict>)> { | ||
let py = new_data.py(); | ||
let new_data = convert_reader(new_data)?; | ||
|
||
let job = self | ||
.builder | ||
.try_build() | ||
.map_err(|err| PyValueError::new_err(err.to_string()))?; | ||
|
||
let (transaction, stats) = RT | ||
.spawn(Some(py), job.execute_uncommitted(new_data))? | ||
.map_err(|err| PyIOError::new_err(err.to_string()))?; | ||
|
||
let stats = Self::build_stats(&stats, py)?; | ||
Comment on lines
+218
to
+230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit: this could be encapsulated in a helper method to cut down on repetition as it is shared by the committed variant. This might also help avoid issues in the future where we change one but not the other and don't notice. |
||
|
||
Ok((PyLance(transaction), stats)) | ||
} | ||
} | ||
|
||
impl MergeInsertBuilder { | ||
fn build_stats<'a>(stats: &MergeStats, py: Python<'a>) -> PyResult<Bound<'a, PyDict>> { | ||
let dict = PyDict::new_bound(py); | ||
dict.set_item("num_inserted_rows", stats.num_inserted_rows)?; | ||
dict.set_item("num_updated_rows", stats.num_updated_rows)?; | ||
dict.set_item("num_deleted_rows", stats.num_deleted_rows)?; | ||
Ok(dict) | ||
} | ||
} | ||
|
||
|
@@ -1312,6 +1339,36 @@ impl Dataset { | |
enable_v2_manifest_paths: Option<bool>, | ||
detached: Option<bool>, | ||
max_retries: Option<u32>, | ||
) -> PyResult<Self> { | ||
let transaction = Transaction::new( | ||
read_version.unwrap_or_default(), | ||
operation.0, | ||
blobs_op.map(|op| op.0), | ||
None, | ||
); | ||
|
||
Self::commit_transaction( | ||
dest, | ||
PyLance(transaction), | ||
commit_lock, | ||
storage_options, | ||
enable_v2_manifest_paths, | ||
detached, | ||
max_retries, | ||
) | ||
} | ||
|
||
#[allow(clippy::too_many_arguments)] | ||
#[staticmethod] | ||
#[pyo3(signature = (dest, transaction, commit_lock = None, storage_options = None, enable_v2_manifest_paths = None, detached = None, max_retries = None))] | ||
fn commit_transaction( | ||
dest: &Bound<PyAny>, | ||
transaction: PyLance<Transaction>, | ||
commit_lock: Option<&Bound<'_, PyAny>>, | ||
storage_options: Option<HashMap<String, String>>, | ||
enable_v2_manifest_paths: Option<bool>, | ||
detached: Option<bool>, | ||
max_retries: Option<u32>, | ||
) -> PyResult<Self> { | ||
let object_store_params = | ||
storage_options | ||
|
@@ -1333,13 +1390,6 @@ impl Dataset { | |
WriteDestination::Uri(dest.extract()?) | ||
}; | ||
|
||
let transaction = Transaction::new( | ||
read_version.unwrap_or_default(), | ||
operation.0, | ||
blobs_op.map(|op| op.0), | ||
None, | ||
); | ||
|
||
let mut builder = CommitBuilder::new(dest) | ||
.enable_v2_manifest_paths(enable_v2_manifest_paths.unwrap_or(false)) | ||
.with_detached(detached.unwrap_or(false)) | ||
|
@@ -1354,7 +1404,10 @@ impl Dataset { | |
} | ||
|
||
let ds = RT | ||
.block_on(commit_lock.map(|cl| cl.py()), builder.execute(transaction))? | ||
.block_on( | ||
commit_lock.map(|cl| cl.py()), | ||
builder.execute(transaction.0), | ||
)? | ||
.map_err(|err| PyIOError::new_err(err.to_string()))?; | ||
|
||
let uri = ds.uri().to_string(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make a comment that this operation should not insert new rows? Or would that not be a bad thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it's used by merge-insert for upsert. So it's allowed to insert new rows.