This is an automated email from the ASF dual-hosted git repository. yuxia pushed a commit to branch update-rust-doc in repository https://gitbox.apache.org/repos/asf/fluss-rust.git
commit 0a0cc8ce346dd98a9080d28cf89060eb8929e974 Author: luoyuxia <[email protected]> AuthorDate: Tue Mar 3 15:47:47 2026 +0800 chore: update rust docs --- crates/fluss/src/error.rs | 2 +- crates/fluss/src/lib.rs | 87 +++++++++++++++++++++++++++++++++ crates/fluss/src/record/kv/kv_record.rs | 2 +- crates/fluss/src/row/binary/mod.rs | 2 +- crates/fluss/src/row/encode/mod.rs | 6 +-- 5 files changed, 93 insertions(+), 6 deletions(-) diff --git a/crates/fluss/src/error.rs b/crates/fluss/src/error.rs index 59524a6..5cf0d4b 100644 --- a/crates/fluss/src/error.rs +++ b/crates/fluss/src/error.rs @@ -33,7 +33,7 @@ pub enum Error { )] UnexpectedError { message: String, - /// see https://github.com/shepmaster/snafu/issues/446 + /// see <https://github.com/shepmaster/snafu/issues/446> #[snafu(source(from(Box<dyn std::error::Error + Send + Sync + 'static>, Some)))] source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>, }, diff --git a/crates/fluss/src/lib.rs b/crates/fluss/src/lib.rs index 689c37c..cd060c8 100644 --- a/crates/fluss/src/lib.rs +++ b/crates/fluss/src/lib.rs @@ -15,6 +15,93 @@ // specific language governing permissions and limitations // under the License. +//! Apache Fluss (Incubating) Official Rust Client +//! +//! Official Rust client library for [Apache Fluss (Incubating)](https://fluss.apache.org/). +//! It supports **primary key (KV) tables** (upsert + lookup) and **log tables** (append + scan). +//! +//! # Examples +//! +//! ## Primary key table and log table +//! +//! Connect to a cluster, create a KV table (upsert and lookup), then a log table (append and scan): +//! +//! ```rust,no_run +//! use fluss::client::EARLIEST_OFFSET; +//! use fluss::client::FlussConnection; +//! use fluss::config::Config; +//! use fluss::error::Result; +//! use fluss::metadata::{DataTypes, Schema, TableDescriptor, TablePath}; +//! use fluss::row::{GenericRow, InternalRow}; +//! use std::time::Duration; +//! +//! #[tokio::main] +//! async fn main() -> Result<()> { +//! let mut config = Config::default(); +//! config.bootstrap_servers = "127.0.0.1:9123".to_string(); +//! let connection = FlussConnection::new(config).await?; +//! let admin = connection.get_admin().await?; +//! +//! // ---- Primary key (KV) table: upsert and lookup ---- +//! let kv_path = TablePath::new("fluss", "users"); +//! let mut kv_schema = Schema::builder() +//! .column("id", DataTypes::int()) +//! .column("name", DataTypes::string()) +//! .column("age", DataTypes::bigint()) +//! .primary_key(vec!["id"]); +//! let kv_descriptor = TableDescriptor::builder() +//! .schema(kv_schema.build()?) +//! .build()?; +//! admin.create_table(&kv_path, &kv_descriptor, false).await?; +//! +//! let kv_table = connection.get_table(&kv_path).await?; +//! let upsert_writer = kv_table.new_upsert()?.create_writer()?; +//! let mut row = GenericRow::new(3); +//! row.set_field(0, 1i32); +//! row.set_field(1, "Alice"); +//! row.set_field(2, 30i64); +//! upsert_writer.upsert(&row)?; +//! upsert_writer.flush().await?; +//! +//! let mut lookuper = kv_table.new_lookup()?.create_lookuper()?; +//! let mut key = GenericRow::new(1); +//! key.set_field(0, 1i32); +//! let result = lookuper.lookup(&key).await?; +//! if let Some(r) = result.get_single_row()? { +//! println!("KV lookup: id={}, name={}, age={}", +//! r.get_int(0)?, r.get_string(1)?, r.get_long(2)?); +//! } +//! +//! // ---- Log table: append and scan ---- +//! let log_path = TablePath::new("fluss", "events"); +//! let mut log_schema_builder = Schema::builder() +//! .column("ts", DataTypes::bigint()) +//! .column("message", DataTypes::string()); +//! let log_descriptor = TableDescriptor::builder() +//! .schema(log_schema_builder.build()?) +//! .build()?; +//! admin.create_table(&log_path, &log_descriptor, false).await?; +//! +//! let log_table = connection.get_table(&log_path).await?; +//! let append_writer = log_table.new_append()?.create_writer()?; +//! let mut event = GenericRow::new(2); +//! event.set_field(0, 1700000000i64); +//! event.set_field(1, "hello"); +//! append_writer.append(&event)?; +//! append_writer.flush().await?; +//! +//! let scanner = log_table.new_scan().create_log_scanner()?; +//! scanner.subscribe(0, EARLIEST_OFFSET).await?; +//! let scan_records = scanner.poll(Duration::from_secs(1)).await?; +//! for record in scan_records { +//! let r = record.row(); +//! println!("Log scan: ts={}, message={}", r.get_long(0)?, r.get_string(1)?); +//! } +//! +//! Ok(()) +//! } +//! ``` + pub mod client; pub mod metadata; pub mod record; diff --git a/crates/fluss/src/record/kv/kv_record.rs b/crates/fluss/src/record/kv/kv_record.rs index a9c45d6..ed67aa0 100644 --- a/crates/fluss/src/record/kv/kv_record.rs +++ b/crates/fluss/src/record/kv/kv_record.rs @@ -50,7 +50,7 @@ pub const LENGTH_LENGTH: usize = 4; /// use the `row()` method with a RowDecoder (typically obtained from the iterator). /// /// Reference implementation: -/// https://github.com/apache/fluss/blob/main/fluss-common/src/main/java/org/apache/fluss/record/KvRecord.java +/// <https://github.com/apache/fluss/blob/main/fluss-common/src/main/java/org/apache/fluss/record/KvRecord.java> #[derive(Debug, Clone)] pub struct KvRecord { key: Bytes, diff --git a/crates/fluss/src/row/binary/mod.rs b/crates/fluss/src/row/binary/mod.rs index c31cbd5..2a88ee1 100644 --- a/crates/fluss/src/row/binary/mod.rs +++ b/crates/fluss/src/row/binary/mod.rs @@ -19,7 +19,7 @@ mod binary_writer; pub use binary_writer::*; -/// The binary row format types, it indicates the generated [`BinaryRow`] type by the [`BinaryWriter`] +/// The binary row format types, it indicates the generated row type by the [`BinaryWriter`] #[allow(dead_code)] pub enum BinaryRowFormat { Compacted, diff --git a/crates/fluss/src/row/encode/mod.rs b/crates/fluss/src/row/encode/mod.rs index 1ce7aef..16a540e 100644 --- a/crates/fluss/src/row/encode/mod.rs +++ b/crates/fluss/src/row/encode/mod.rs @@ -64,12 +64,12 @@ impl KeyEncoderFactory { } } -/// An encoder to write [`BinaryRow`]. It's used to write row -/// multi-times one by one. When writing a new row: +/// An encoder to write binary row data. It's used to write rows +/// one by one. When writing a new row: /// /// 1. call method [`RowEncoder::start_new_row()`] to start the writing. /// 2. call method [`RowEncoder::encode_field()`] to write the row's field. -/// 3. call method [`RowEncoder::finishRow()`] to finish the writing and get the written row. +/// 3. call method [`RowEncoder::finish_row()`] to finish the writing and get the written row. #[allow(dead_code)] pub trait RowEncoder: Send + Sync { /// Start to write a new row.
