This is an automated email from the ASF dual-hosted git repository.

yihua pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hudi-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 0ff3d618 fix(cpp): reject reader options that are not key=value (#942)
0ff3d618 is described below

commit 0ff3d61884a5cbd6fce7c783a1045de9527eea7a
Author: Sagar Sumit <[email protected]>
AuthorDate: Sun Nov 8 10:31:09 2026 +0530

    fix(cpp): reject reader options that are not key=value (#942)
    
    new_file_group_reader_with_options dropped any option without '=', so a
    C++ caller who wrote "hoodie.read.use.read_optimized.mode" without a
    value, or mistyped the separator, got a reader that silently ignored the
    option. Return an error naming the malformed option instead.
    
    This is a behavior change for C++ callers that relied on the drop.
    
    ---------
    
    Signed-off-by: codope <[email protected]>
---
 cpp/src/lib.rs | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/cpp/src/lib.rs b/cpp/src/lib.rs
index fd8d54e4..189bc067 100644
--- a/cpp/src/lib.rs
+++ b/cpp/src/lib.rs
@@ -38,6 +38,7 @@ mod ffi {
     extern "Rust" {
         type HudiFileGroupReader;
         /// Opens a reader for the table at `base_uri` with `key=value` 
options.
+        /// An option without `=` is an error.
         ///
         /// Throws `rust::Error` on failure, including a panic inside the 
library.
         fn new_file_group_reader_with_options(
@@ -111,6 +112,20 @@ fn cxx_strs(values: &CxxVector<CxxString>) -> 
Result<Vec<&str>, String> {
     values.iter().map(cxx_str).collect()
 }
 
+/// Splits `key=value` options, erroring on a malformed one rather than
+/// dropping it: a typo that silently loses an option is hard to find from C++.
+fn key_values<'a>(
+    options: impl IntoIterator<Item = &'a str>,
+) -> Result<Vec<(&'a str, &'a str)>, String> {
+    options
+        .into_iter()
+        .map(|opt| {
+            opt.split_once('=')
+                .ok_or_else(|| format!("Option is not key=value: {opt}"))
+        })
+        .collect()
+}
+
 #[derive(Debug)]
 pub struct HudiFileGroupReader {
     inner: FileGroupReader,
@@ -124,10 +139,7 @@ pub fn new_file_group_reader_with_options(
     guard("new_file_group_reader_with_options", || {
         let base_uri = cxx_str(base_uri)?;
 
-        let opt_vec: Vec<(&str, &str)> = cxx_strs(options)?
-            .into_iter()
-            .filter_map(|opt| opt.split_once('='))
-            .collect();
+        let opt_vec = key_values(cxx_strs(options)?)?;
 
         let rt = tokio::runtime::Builder::new_current_thread()
             .enable_all()
@@ -278,6 +290,22 @@ mod tests {
         assert_eq!(err, "op panicked: non-string panic payload");
     }
 
+    /// An option without `=` is an error, and only the first `=` splits, so a
+    /// value may contain one. Asserted on the parser directly:
+    /// `CxxVector<CxxString>` cannot be filled from Rust, so the constructor
+    /// cannot be handed one.
+    #[test]
+    fn test_key_values_option_without_equals_is_error() {
+        assert_eq!(
+            key_values(["a=1", "b"]).unwrap_err(),
+            "Option is not key=value: b"
+        );
+        assert_eq!(
+            key_values(["a=1", "b=x=y"]).unwrap(),
+            [("a", "1"), ("b", "x=y")]
+        );
+    }
+
     #[test]
     fn test_new_file_group_reader_with_options_unreadable_table_is_error() {
         let_cxx_string!(base_uri = "/definitely/not/a/hudi/table");

Reply via email to