linliu-code commented on code in PR #663: URL: https://github.com/apache/hudi-rs/pull/663#discussion_r3779929501
########## crates/core/src/file_group/reader_v2/update_processor.rs: ########## @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +//! Ported from the merge-on-read reader. Nothing consumes it yet, so its +//! items are unreachable from the crate's call graph until the reader wires in. +#![allow(dead_code)] + +//! Mirrors `org.apache.hudi.common.table.read.UpdateProcessor`. Review Comment: Fixed. Merged into one `//!` block, with the Java-mirror description first and the porting note plus `#![allow(dead_code)]` after it, so nothing is overwritten in rustdoc. ########## crates/core/src/file_group/reader_v2/input_split.rs: ########## @@ -0,0 +1,258 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +//! Ported from the merge-on-read reader. Nothing consumes it yet, so its +//! items are unreachable from the crate's call graph until the reader wires in. +#![allow(dead_code)] + +//! Mirrors `org.apache.hudi.common.table.read.InputSplit`. +//! +//! Describes the data to be read from a file group: an optional base file, +//! a list of log files, and the partition path context. + +use crate::file_group::log_file::LogFile; +use std::str::FromStr; + +/// Describes the input data for a file group read. +/// +/// Carries the base file (if any), the list of log files to scan, +/// the partition path, and the byte range to read from the base file. +#[derive(Debug, Clone)] +pub struct InputSplit { + /// Path to the base file (relative to table root), if present. + pub base_file_path: Option<String>, + + /// Commit time of the base file, if present. + pub base_file_commit_time: Option<String>, + + /// Relative paths to log files to scan. + pub log_file_paths: Vec<String>, + + /// Partition path for this file group (e.g. "year=2024/month=01"). + pub partition_path: String, + + /// Byte offset to start reading from in the base file. + pub start: i64, + + /// Number of bytes to read from the base file. + pub length: i64, +} + +/// CDC log-file suffix. Mirrors Java's `HoodieCDCUtils.CDC_LOGFILE_SUFFIX` (".cdc"). +/// CDC log files carry change-data-capture blocks and must be excluded from a +/// normal snapshot read — gold drops them in `InputSplit`'s constructor +/// (`InputSplit.java:57`). +const CDC_LOGFILE_SUFFIX: &str = ".cdc"; + +impl InputSplit { + pub fn new( + base_file_path: Option<String>, + base_file_commit_time: Option<String>, + log_file_paths: Vec<String>, + partition_path: String, + ) -> Self { + // Filter out CDC log files, then sort ascending by + // deltaCommitTime → logVersion → writeToken. This mirrors Java's + // InputSplit constructor (InputSplit.java:56-58), which sorts via + // HoodieLogFile.getLogFileComparator() and filters file names ending in + // HoodieCDCUtils.CDC_LOGFILE_SUFFIX. The C++ side may send log files in + // descending order (from FileSlice's reverse TreeSet), so we re-sort. + let log_file_paths = Self::filter_cdc_log_files(log_file_paths); + let log_file_paths = Self::sort_log_file_paths(log_file_paths); + Self { + base_file_path, + base_file_commit_time, + log_file_paths, + partition_path, + start: 0, + length: -1, + } + } + + /// Drop CDC log files from the scan list. + /// + /// Mirrors Java's `InputSplit` constructor filter + /// (`InputSplit.java:57`): `!logFile.getFileName().endsWith(CDC_LOGFILE_SUFFIX)`. + /// The match is on the file-name portion (after the last `/`), matching gold's + /// `getFileName()` semantics. + fn filter_cdc_log_files(paths: Vec<String>) -> Vec<String> { + paths + .into_iter() + .filter(|p| { + let name = p.rsplit('/').next().unwrap_or(p); + !name.ends_with(CDC_LOGFILE_SUFFIX) + }) + .collect() + } + + /// Sort log file paths ascending by deltaCommitTime → logVersion → writeToken. + /// + /// Mirrors Java's `InputSplit` constructor which sorts via + /// `HoodieLogFile.getLogFileComparator()`. + fn sort_log_file_paths(mut paths: Vec<String>) -> Vec<String> { + if paths.len() <= 1 { + return paths; + } + paths.sort_by(|a, b| { + let name_a = a.rsplit('/').next().unwrap_or(a); + let name_b = b.rsplit('/').next().unwrap_or(b); + match (LogFile::from_str(name_a), LogFile::from_str(name_b)) { + (Ok(lf_a), Ok(lf_b)) => lf_a.cmp(&lf_b), + _ => a.cmp(b), // fallback to lexicographic if parsing fails + } + }); + paths + } Review Comment: Fixed. Renamed to `is_base_only` and corrected the doc to "Returns true when there are no log files to merge, so the split reduces to its base file. A base-file-only split is exactly this case." The single call site in `engine.rs` is updated. -- 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]
