codope commented on code in PR #1027:
URL: https://github.com/apache/hudi-rs/pull/1027#discussion_r4656857518
##########
crates/core/src/write/rewrite/mor.rs:
##########
@@ -357,7 +364,12 @@ pub(super) async fn mor_upsert_batches(
base_file: Some(String::new()),
log_files: Some(vec![log_name]),
num_writes: Some(moved.len() as i64),
- num_deletes: Some(moved.len() as i64),
+ num_deletes: Some(
+ moved_delete_counts
+ .get(&(partition_path.clone(), file_id.clone()))
+ .copied()
+ .unwrap_or(0) as i64,
+ ),
Review Comment:
This log is a delete block containing every moved key, so `numDeletes`
should stay `moved.len()`. With this change, a plain (non-marker) partition
move writes a delete block whose stat says `numDeletes: 0`, and Java's append
handle counts those as deletes. `WriteResult.num_deletes` counts marker deletes
and the stats count physical deletes, so they don't need to add up to the same
total. Could you restore `moved.len()` and add a test that a plain move keeps
`numDeletes = 1` on the old group?
##########
crates/core/src/write/rewrite/cow.rs:
##########
@@ -355,6 +355,7 @@ pub(super) enum GroupOp {
incoming: RecordBatch,
partial_columns: Option<Vec<String>>,
evict_keys: std::sync::Arc<HashSet<String>>,
+ evict_marker_keys: std::sync::Arc<HashSet<String>>,
Review Comment:
Please also add doc comments for new params `evict_marker_keys` and
`marker_keys`
##########
crates/core/src/write/rewrite/cow.rs:
##########
@@ -625,6 +636,9 @@ impl MergePlan {
let doomed = keys_only.contains(key)
|| exact.contains(&(key.clone(), partition.clone()));
if doomed {
+ if marker_keys.contains(key) {
+ marker_deletes += 1;
+ }
Review Comment:
For a group that only loses rows, a moved marker is still counted in
`numUpdateWrites` (stat upd=1, del=1, while WriteResult has u=0, d=1). That's
the "records it as an update" part of #924. Could you leave marker-removed rows
out of `num_update_writes` for the `DeleteKeys` evict-only case?
##########
crates/core/tests/table_write_tests.rs:
##########
@@ -3573,11 +3573,23 @@ async fn
test_upsert_hoodie_is_deleted_removes_row_and_index_entry() {
])])
.await
.unwrap();
- if table_type == TableTypeValue::CopyOnWrite {
- // `a`'s winning marker counts as a delete, as Java's merge handle
- // counts it.
- assert_eq!(result.num_deletes, 1);
- }
+ // `a` is deleted in place and `c` is deleted when it moves partitions.
+ assert_eq!(result.num_deletes, 2, "{table_type:?}");
+ let instant = table.timeline.completed_commits.last().unwrap().clone();
+ let json = table
+ .timeline
+ .get_instant_metadata_in_json(&instant)
+ .await
+ .unwrap();
+ let metadata: serde_json::Value = serde_json::from_str(&json).unwrap();
+ let stat_num_deletes = metadata["partitionToWriteStats"]
+ .as_object()
+ .unwrap()
+ .values()
+ .flat_map(|stats| stats.as_array().unwrap())
+ .map(|stat| stat["numDeletes"].as_i64().unwrap_or(0))
+ .sum::<i64>();
+ assert_eq!(stat_num_deletes, 2, "{table_type:?}");
Review Comment:
Summing `numDeletes` across stats would pass even if the delete landed on
the wrong file. Could you assert per stat (old group numDeletes/numUpdateWrites
on COW; tombstone log vs data log on MOR)?
##########
crates/core/src/write/rewrite/mor.rs:
##########
@@ -195,6 +196,9 @@ pub(super) async fn mor_upsert_batches(
};
if delete_markers[index] {
index_deletes.push(doomed.clone());
+ *moved_delete_counts
+ .entry((location.partition_path.clone(),
location.file_id.clone()))
+ .or_default() += 1;
Review Comment:
Line 212 below also increments `updates += 1`. Should we guard that
increment with `if !delete_markers[index]` to line it up with COW?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]