Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/paimon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
10 changes: 6 additions & 4 deletions crates/paimon/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
}
75 changes: 75 additions & 0 deletions crates/paimon/src/table/read_builder.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
8 changes: 4 additions & 4 deletions crates/paimon/src/table/table_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down
Loading