This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git
The following commit(s) were added to refs/heads/main by this push:
new fd0e21c feat: introduce read builder (#114)
fd0e21c is described below
commit fd0e21ce06e4c09a1add6c97279c935bf9410122
Author: yuxia Luo <[email protected]>
AuthorDate: Tue Mar 10 12:00:22 2026 +0800
feat: introduce read builder (#114)
---
crates/paimon/src/lib.rs | 4 +-
crates/paimon/src/table/mod.rs | 10 +++--
crates/paimon/src/table/read_builder.rs | 75 +++++++++++++++++++++++++++++++++
crates/paimon/src/table/table_scan.rs | 8 ++--
4 files changed, 88 insertions(+), 9 deletions(-)
diff --git a/crates/paimon/src/lib.rs b/crates/paimon/src/lib.rs
index 641427c..b3095a3 100644
--- a/crates/paimon/src/lib.rs
+++ b/crates/paimon/src/lib.rs
@@ -25,4 +25,6 @@ pub mod file_index;
pub mod io;
pub mod spec;
mod table;
-pub use table::{DataSplit, DataSplitBuilder, Plan, SnapshotManager, Table,
TableScan};
+pub use table::{
+ DataSplit, DataSplitBuilder, Plan, ReadBuilder, SnapshotManager, Table,
TableRead, TableScan,
+};
diff --git a/crates/paimon/src/table/mod.rs b/crates/paimon/src/table/mod.rs
index d4170a7..4011f52 100644
--- a/crates/paimon/src/table/mod.rs
+++ b/crates/paimon/src/table/mod.rs
@@ -17,10 +17,12 @@
//! Table API for Apache Paimon
+mod read_builder;
mod snapshot_manager;
mod source;
mod table_scan;
+pub use read_builder::{ReadBuilder, TableRead};
pub use snapshot_manager::SnapshotManager;
pub use source::{DataSplit, DataSplitBuilder, Plan};
pub use table_scan::TableScan;
@@ -75,10 +77,10 @@ impl Table {
&self.file_io
}
- /// Create a table scan for full table read (no incremental, no predicate).
+ /// Create a read builder for scan/read.
///
- /// Reference: [pypaimon
TableScan](https://github.com/apache/paimon/blob/release-1.3/paimon-python/pypaimon/read/table_scan.py).
- pub fn new_scan(&self) -> TableScan {
- TableScan::new(self.clone())
+ /// Reference: [pypaimon
FileStoreTable.new_read_builder](https://github.com/apache/paimon/blob/release-1.3/paimon-python/pypaimon/table/file_store_table.py).
+ pub fn new_read_builder(&self) -> ReadBuilder<'_> {
+ ReadBuilder::new(self)
}
}
diff --git a/crates/paimon/src/table/read_builder.rs
b/crates/paimon/src/table/read_builder.rs
new file mode 100644
index 0000000..14f56b1
--- /dev/null
+++ b/crates/paimon/src/table/read_builder.rs
@@ -0,0 +1,75 @@
+// 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.
+
+//! ReadBuilder and TableRead for table read API.
+//!
+//! Reference:
[pypaimon.read.read_builder.ReadBuilder](https://github.com/apache/paimon/blob/master/paimon-python/pypaimon/read/read_builder.py)
+//! and
[pypaimon.table.file_store_table.FileStoreTable.new_read_builder](https://github.com/apache/paimon/blob/master/paimon-python/pypaimon/table/file_store_table.py).
+
+use crate::spec::DataField;
+use crate::Result;
+
+use super::{Table, TableScan};
+
+/// Builder for table scan and table read (new_scan, new_read).
+///
+/// Reference:
[pypaimon.read.read_builder.ReadBuilder](https://github.com/apache/paimon/blob/master/paimon-python/pypaimon/read/read_builder.py)
+#[derive(Debug, Clone)]
+pub struct ReadBuilder<'a> {
+ table: &'a Table,
+}
+
+impl<'a> ReadBuilder<'a> {
+ pub(crate) fn new(table: &'a Table) -> Self {
+ Self { table }
+ }
+
+ /// Create a table scan. Call [TableScan::plan] to get splits.
+ pub fn new_scan(&self) -> TableScan<'a> {
+ TableScan::new(self.table)
+ }
+
+ /// Create a table read for consuming splits (e.g. from a scan plan).
+ pub fn new_read(&self) -> Result<TableRead<'a>> {
+ let read_type = self.table.schema.fields();
+ Ok(TableRead {
+ table: self.table,
+ read_type,
+ })
+ }
+}
+
+/// Table read: reads data from splits (e.g. produced by [TableScan::plan]).
+///
+/// Reference:
[pypaimon.read.table_read.TableRead](https://github.com/apache/paimon/blob/master/paimon-python/pypaimon/read/table_read.py)
+#[derive(Debug, Clone)]
+pub struct TableRead<'a> {
+ table: &'a Table,
+ read_type: &'a [DataField],
+}
+
+impl<'a> TableRead<'a> {
+ /// Schema (fields) that this read will produce.
+ pub fn read_type(&self) -> &[DataField] {
+ self.read_type
+ }
+
+ /// Table for this read.
+ pub fn table(&self) -> &Table {
+ self.table
+ }
+}
diff --git a/crates/paimon/src/table/table_scan.rs
b/crates/paimon/src/table/table_scan.rs
index 88d1778..931c3cd 100644
--- a/crates/paimon/src/table/table_scan.rs
+++ b/crates/paimon/src/table/table_scan.rs
@@ -107,12 +107,12 @@ fn merge_manifest_entries(entries: Vec<ManifestEntry>) ->
Vec<ManifestEntry> {
///
/// Reference:
[pypaimon.read.table_scan.TableScan](https://github.com/apache/paimon/blob/master/paimon-python/pypaimon/read/table_scan.py)
#[derive(Debug, Clone)]
-pub struct TableScan {
- table: Table,
+pub struct TableScan<'a> {
+ table: &'a Table,
}
-impl TableScan {
- pub fn new(table: Table) -> Self {
+impl<'a> TableScan<'a> {
+ pub fn new(table: &'a Table) -> Self {
Self { table }
}