You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "yihua (via GitHub)" <gi...@apache.org> on 2026/10/17 19:01:35 UTC

[PR] perf(datafusion): read string and binary columns as view types [hudi-rs]

yihua opened a new pull request, #832:
URL: https://github.com/apache/hudi-rs/pull/832

   ## Description
   
   The DataFusion table provider now declares top-level string and binary columns as `Utf8View` / `BinaryView`, following `datafusion.execution.parquet.schema_force_view_types` (on by default, forwarded from the session by the table factory or passed as a table option), so the copy-on-write parquet scan decodes strings straight into view arrays. The merge-on-read scan casts its string and binary columns to the declared view types and leaves every other column as the reader produced it. DataFusion consumers now get view arrays for these columns unless they set the option to `false`; the Python binding keeps `Utf8` by default, since it cannot see a Python session's own setting.
   
   TPC-H with DataFusion, local, median of 3 alternating rounds, before -> after:
   - SF1 copy-on-write: total 4354 -> 4090 ms (-6%); Q19 212 -> 155 ms, Q10 265 -> 238 ms, Q12 280 -> 252 ms, Q13 145 -> 129 ms.
   - SF0.01 merge-on-read: total 723 -> 734 ms, unchanged within noise.
   
   ## How are the changes test-covered
   
   - [ ] N/A
   - [x] Automated tests (unit and/or integration tests)
   - [ ] Manual tests
     - [ ] Details are described below
   
   Tests cover the schema following the option by default, when off, case-insensitively, through `SET` plus `CREATE EXTERNAL TABLE`, and rejecting an invalid value; merge-on-read reads (file group reader versions 1 and 2) returning the declared view types with the same values as `Utf8`; the batch cast touching only view-typed columns, keeping the batch's nullability, and refusing a misaligned batch; and the Python default. The shared test helpers accept both string representations, so existing tests run unchanged.
   


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(datafusion): read string and binary columns as view types [hudi-rs]

Posted by "yihua (via GitHub) via commits" <co...@hudi.apache.org>.
yihua commented on code in PR #832:
URL: https://github.com/apache/hudi-rs/pull/832#discussion_r4774586597


##########
crates/datafusion/src/lib.rs:
##########
@@ -1676,4 +1730,189 @@ mod tests {
         assert_scan_filter(&filters, "region", "=", &["us"]);
         assert_scan_filter(&filters, "txn_id", "=", &["TXN-001"]);
     }
+
+    /// Strings are view types by default and stay `Utf8` when the option or the
+    /// session turns view types off.
+    #[tokio::test]
+    async fn string_columns_follow_the_sessions_view_type_setting() {
+        let path = V6Nonpartitioned.path_to_cow();
+        let by_default = HudiDataSource::new(&path).await.unwrap();
+        assert_eq!(
+            by_default
+                .schema()
+                .field_with_name("name")
+                .unwrap()
+                .data_type(),
+            &DataType::Utf8View
+        );
+        assert_eq!(
+            by_default
+                .schema()
+                .field_with_name("_hoodie_record_key")
+                .unwrap()
+                .data_type(),
+            &DataType::Utf8View
+        );
+
+        let off = HudiDataSource::new_with_options(&path, [(SCHEMA_FORCE_VIEW_TYPES, "false")])
+            .await
+            .unwrap();
+        assert_eq!(
+            off.schema().field_with_name("name").unwrap().data_type(),
+            &DataType::Utf8
+        );
+        let upper = HudiDataSource::new_with_options(&path, [(SCHEMA_FORCE_VIEW_TYPES, "TRUE")])
+            .await
+            .unwrap();
+        assert_eq!(
+            upper.schema().field_with_name("name").unwrap().data_type(),
+            &DataType::Utf8View
+        );
+        let invalid =
+            HudiDataSource::new_with_options(&path, [(SCHEMA_FORCE_VIEW_TYPES, "maybe")]).await;
+        assert!(invalid.is_err());
+
+        for (setting, expected) in [("true", DataType::Utf8View), ("false", DataType::Utf8)] {
+            let factory: Arc<dyn TableProviderFactory> = Arc::new(HudiTableFactory::new());
+            let state = datafusion::execution::session_state::SessionStateBuilder::new()
+                .with_default_features()
+                .with_table_factories(HashMap::from([("HUDI".to_string(), factory)]))
+                .build();
+            let ctx = SessionContext::new_with_state(state);
+            ctx.sql(&format!("SET {SCHEMA_FORCE_VIEW_TYPES} = {setting}"))
+                .await
+                .unwrap();
+            ctx.sql(&format!(
+                "CREATE EXTERNAL TABLE t STORED AS HUDI LOCATION '{path}'"
+            ))
+            .await
+            .unwrap();
+            let df = ctx.sql("SELECT name FROM t").await.unwrap();
+            assert_eq!(
+                df.schema().field(0).data_type(),
+                &expected,
+                "session setting {setting}"
+            );
+        }
+    }
+
+    /// The merge-on-read scan goes through `HudiScanExec`, whose batches come
+    /// from the reader in storage types; they must arrive in the declared view
+    /// types with the same values the `Utf8` configuration returns.
+    #[tokio::test]
+    async fn merge_on_read_scan_returns_the_declared_view_types() {
+        use hudi_test::SampleTable::V6SimplekeygenNonhivestyle;
+        async fn names(view: bool) -> (DataType, Vec<String>) {
+            let path = V6SimplekeygenNonhivestyle.path_to_mor_parquet();
+            let ctx = SessionContext::new();
+            let ds = HudiDataSource::new_with_options(
+                &path,
+                [(SCHEMA_FORCE_VIEW_TYPES, if view { "true" } else { "false" })],
+            )
+            .await
+            .unwrap();
+            ctx.register_table("t", Arc::new(ds)).unwrap();
+            let batches = ctx
+                .sql("SELECT name FROM t ORDER BY id")
+                .await
+                .unwrap()
+                .collect()
+                .await
+                .unwrap();
+            let data_type = batches[0].schema().field(0).data_type().clone();
+            let values = batches
+                .iter()
+                .flat_map(|b| {
+                    hudi_test::util::get_str_column(b, "name")
+                        .into_iter()
+                        .map(str::to_string)
+                        .collect::<Vec<_>>()
+                })
+                .collect();
+            (data_type, values)
+        }
+        let (view_type, view_values) = names(true).await;
+        let (utf8_type, utf8_values) = names(false).await;
+        assert_eq!(view_type, DataType::Utf8View);
+        assert_eq!(utf8_type, DataType::Utf8);
+        assert!(!view_values.is_empty());
+        assert_eq!(view_values, utf8_values);

Review Comment:
   Done, `view_types_return_the_same_rows_as_utf8` compares the rendered `SELECT *` and `WHERE region = 'us'` output with the option on and off, on `V9TxnsSimpleMeta` copy-on-write and merge-on-read (Avro logs).



##########
crates/datafusion/src/lib.rs:
##########
@@ -23,6 +23,14 @@
 //! [`HudiTableFactory`] serves `CREATE EXTERNAL TABLE ... STORED AS HUDI`. Both read through
 //! `hudi-core` and accept the same table options.
 //!
+//! Top-level string and binary columns are declared as `Utf8View` and `BinaryView`, following
+//! [`SCHEMA_FORCE_VIEW_TYPES`] (on by default, as in DataFusion). Setting it to `false` keeps the
+//! table's own string and binary types, which code that downcasts to `StringArray` or compares
+//! against `Table::get_schema_with_meta_fields()` needs. A table created through
+//! [`HudiTableFactory`] takes it from the session or the `OPTIONS` clause; a provider built
+//! directly takes it only as an option to [`HudiDataSource::new_with_options`], since it cannot
+//! see the session it is registered with.

Review Comment:
   Done, the README's DataFusion section now has a short note on the default, how to set the option back to `false` for the factory and for a directly built provider, and that a directly built provider does not see a session `SET`.



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(datafusion): read string and binary columns as view types [hudi-rs]

Posted by "yihua (via GitHub) via commits" <co...@hudi.apache.org>.
yihua merged PR #832:
URL: https://github.com/apache/hudi-rs/pull/832


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(datafusion): read string and binary columns as view types [hudi-rs]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #832:
URL: https://github.com/apache/hudi-rs/pull/832#issuecomment-6239532401

   ## [Codecov](https://app.codecov.io/gh/apache/hudi-rs/pull/832?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `84.21053%` with `12 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 79.74%. Comparing base ([`ce1f6a3`](https://app.codecov.io/gh/apache/hudi-rs/commit/ce1f6a3e2b6adb34dc078eac7631316cd62c4a87?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`88cc867`](https://app.codecov.io/gh/apache/hudi-rs/commit/88cc867974f568ca24a3cb7025f6d673dfd0e816?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/hudi-rs/pull/832?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [crates/datafusion/src/hudi\_exec.rs](https://app.codecov.io/gh/apache/hudi-rs/pull/832?src=pr&el=tree&filepath=crates%2Fdatafusion%2Fsrc%2Fhudi_exec.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y3JhdGVzL2RhdGFmdXNpb24vc3JjL2h1ZGlfZXhlYy5ycw==) | 76.92% | [9 Missing :warning: ](https://app.codecov.io/gh/apache/hudi-rs/pull/832?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [crates/test/src/util.rs](https://app.codecov.io/gh/apache/hudi-rs/pull/832?src=pr&el=tree&filepath=crates%2Ftest%2Fsrc%2Futil.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y3JhdGVzL3Rlc3Qvc3JjL3V0aWwucnM=) | 77.77% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/hudi-rs/pull/832?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [crates/datafusion/src/lib.rs](https://app.codecov.io/gh/apache/hudi-rs/pull/832?src=pr&el=tree&filepath=crates%2Fdatafusion%2Fsrc%2Flib.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y3JhdGVzL2RhdGFmdXNpb24vc3JjL2xpYi5ycw==) | 94.11% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/hudi-rs/pull/832?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@           Coverage Diff           @@
   ##             main     #832   +/-   ##
   =======================================
     Coverage   79.73%   79.74%           
   =======================================
     Files         127      127           
     Lines       12533    12587   +54     
   =======================================
   + Hits         9993    10037   +44     
   - Misses       2540     2550   +10     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/hudi-rs/pull/832?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(datafusion): read string and binary columns as view types [hudi-rs]

Posted by "yihua (via GitHub) via commits" <co...@hudi.apache.org>.
yihua commented on PR #832:
URL: https://github.com/apache/hudi-rs/pull/832#issuecomment-6716968300

   Pushed a minor revision in the latest commit, after merging main: one shared `view_type` rule for the declared schema and the merge-on-read cast, the option key shared with the Python binding, width-mismatched batches rejected, and crate docs that state the default change and how each construction path opts out. LGTM.


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(datafusion): read string and binary columns as view types [hudi-rs]

Posted by "linliu-code (via GitHub) via commits" <co...@hudi.apache.org>.
linliu-code commented on code in PR #832:
URL: https://github.com/apache/hudi-rs/pull/832#discussion_r4774234272


##########
crates/datafusion/src/lib.rs:
##########
@@ -1676,4 +1730,189 @@ mod tests {
         assert_scan_filter(&filters, "region", "=", &["us"]);
         assert_scan_filter(&filters, "txn_id", "=", &["TXN-001"]);
     }
+
+    /// Strings are view types by default and stay `Utf8` when the option or the
+    /// session turns view types off.
+    #[tokio::test]
+    async fn string_columns_follow_the_sessions_view_type_setting() {
+        let path = V6Nonpartitioned.path_to_cow();
+        let by_default = HudiDataSource::new(&path).await.unwrap();
+        assert_eq!(
+            by_default
+                .schema()
+                .field_with_name("name")
+                .unwrap()
+                .data_type(),
+            &DataType::Utf8View
+        );
+        assert_eq!(
+            by_default
+                .schema()
+                .field_with_name("_hoodie_record_key")
+                .unwrap()
+                .data_type(),
+            &DataType::Utf8View
+        );
+
+        let off = HudiDataSource::new_with_options(&path, [(SCHEMA_FORCE_VIEW_TYPES, "false")])
+            .await
+            .unwrap();
+        assert_eq!(
+            off.schema().field_with_name("name").unwrap().data_type(),
+            &DataType::Utf8
+        );
+        let upper = HudiDataSource::new_with_options(&path, [(SCHEMA_FORCE_VIEW_TYPES, "TRUE")])
+            .await
+            .unwrap();
+        assert_eq!(
+            upper.schema().field_with_name("name").unwrap().data_type(),
+            &DataType::Utf8View
+        );
+        let invalid =
+            HudiDataSource::new_with_options(&path, [(SCHEMA_FORCE_VIEW_TYPES, "maybe")]).await;
+        assert!(invalid.is_err());
+
+        for (setting, expected) in [("true", DataType::Utf8View), ("false", DataType::Utf8)] {
+            let factory: Arc<dyn TableProviderFactory> = Arc::new(HudiTableFactory::new());
+            let state = datafusion::execution::session_state::SessionStateBuilder::new()
+                .with_default_features()
+                .with_table_factories(HashMap::from([("HUDI".to_string(), factory)]))
+                .build();
+            let ctx = SessionContext::new_with_state(state);
+            ctx.sql(&format!("SET {SCHEMA_FORCE_VIEW_TYPES} = {setting}"))
+                .await
+                .unwrap();
+            ctx.sql(&format!(
+                "CREATE EXTERNAL TABLE t STORED AS HUDI LOCATION '{path}'"
+            ))
+            .await
+            .unwrap();
+            let df = ctx.sql("SELECT name FROM t").await.unwrap();
+            assert_eq!(
+                df.schema().field(0).data_type(),
+                &expected,
+                "session setting {setting}"
+            );
+        }
+    }
+
+    /// The merge-on-read scan goes through `HudiScanExec`, whose batches come
+    /// from the reader in storage types; they must arrive in the declared view
+    /// types with the same values the `Utf8` configuration returns.
+    #[tokio::test]
+    async fn merge_on_read_scan_returns_the_declared_view_types() {
+        use hudi_test::SampleTable::V6SimplekeygenNonhivestyle;
+        async fn names(view: bool) -> (DataType, Vec<String>) {
+            let path = V6SimplekeygenNonhivestyle.path_to_mor_parquet();
+            let ctx = SessionContext::new();
+            let ds = HudiDataSource::new_with_options(
+                &path,
+                [(SCHEMA_FORCE_VIEW_TYPES, if view { "true" } else { "false" })],
+            )
+            .await
+            .unwrap();
+            ctx.register_table("t", Arc::new(ds)).unwrap();
+            let batches = ctx
+                .sql("SELECT name FROM t ORDER BY id")
+                .await
+                .unwrap()
+                .collect()
+                .await
+                .unwrap();
+            let data_type = batches[0].schema().field(0).data_type().clone();
+            let values = batches
+                .iter()
+                .flat_map(|b| {
+                    hudi_test::util::get_str_column(b, "name")
+                        .into_iter()
+                        .map(str::to_string)
+                        .collect::<Vec<_>>()
+                })
+                .collect();
+            (data_type, values)
+        }
+        let (view_type, view_values) = names(true).await;
+        let (utf8_type, utf8_values) = names(false).await;
+        assert_eq!(view_type, DataType::Utf8View);
+        assert_eq!(utf8_type, DataType::Utf8);
+        assert!(!view_values.is_empty());
+        assert_eq!(view_values, utf8_values);

Review Comment:
   Non-blocking: this compares only `name`, so a value regression in another string/binary column, or on the partition-filter path, would pass. Partition equality filters are reported `Exact`, so no residual filter runs, and they now arrive as `ScalarValue::Utf8View` literals that `scalar_to_filter_value` renders through `Display`. If that rendering ever changed, rows would be silently dropped. Suggest comparing `pretty_format_batches` output of `SELECT * ... ORDER BY _hoodie_record_key` and `... WHERE region = 'us'` with the option on and off, for `V9TxnsSimpleMeta` copy-on-write and merge-on-read (Avro logs). I ran exactly that locally and it matches, so this only pins it.



##########
crates/datafusion/src/lib.rs:
##########
@@ -23,6 +23,14 @@
 //! [`HudiTableFactory`] serves `CREATE EXTERNAL TABLE ... STORED AS HUDI`. Both read through
 //! `hudi-core` and accept the same table options.
 //!
+//! Top-level string and binary columns are declared as `Utf8View` and `BinaryView`, following
+//! [`SCHEMA_FORCE_VIEW_TYPES`] (on by default, as in DataFusion). Setting it to `false` keeps the
+//! table's own string and binary types, which code that downcasts to `StringArray` or compares
+//! against `Table::get_schema_with_meta_fields()` needs. A table created through
+//! [`HudiTableFactory`] takes it from the session or the `OPTIONS` clause; a provider built
+//! directly takes it only as an option to [`HudiDataSource::new_with_options`], since it cannot
+//! see the session it is registered with.

Review Comment:
   Non-blocking: the crate docs are the only place the default change is described. Since this breaks code that downcasts to `StringArray`, a short migration note in the README / Python-Rust quick start DataFusion section (set `datafusion.execution.parquet.schema_force_view_types=false`, or use `str_values`-style handling of both arrays) would help users upgrading. The note could also say that a provider built directly ignores a session-level `SET`.



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org