QuakeWang commented on code in PR #157: URL: https://github.com/apache/paimon-rust/pull/157#discussion_r3005794811
########## docs/src/contributing.md: ########## @@ -0,0 +1,62 @@ +<!-- +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. +--> + +# Contributing + +Apache Paimon Rust welcomes contributions from everyone. See the full [Contributing Guide](https://github.com/apache/paimon-rust/blob/main/CONTRIBUTING.md) for detailed instructions. + +## Quick Start + +1. Fork the [repository](https://github.com/apache/paimon-rust) +2. Clone your fork: `git clone https://github.com/<your-username>/paimon-rust.git` +3. Create a feature branch: `git checkout -b feature/my-feature` +4. Make your changes and add tests +5. Run checks locally before submitting +6. Open a Pull Request + +## Development Setup + +```bash +# Ensure you have the correct Rust toolchain +rustup show + +# Build the project +cargo build + +# Run all tests +cargo test + +# Format code +cargo fmt + +# Lint +cargo clippy Review Comment: The project CI runs `cargo clippy --all-targets --workspace -- -D warnings`. Running `cargo clippy` locally without `-D warnings` may pass while CI fails, creating a confusing contributor experience. Please align this with the actual CI command. ########## docs/README.md: ########## @@ -0,0 +1,55 @@ +<!-- +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. +--> + +# Documentation + +This directory contains the source files for the Apache Paimon Rust documentation site, built with [MkDocs](https://www.mkdocs.org/) and the [Material for MkDocs](https://squidfun.github.io/mkdocs-material/) theme. Review Comment: ```suggestion This directory contains the source files for the Apache Paimon Rust documentation site, built with [MkDocs](https://www.mkdocs.org/) and the [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) theme. ``` ########## docs/src/getting-started.md: ########## @@ -0,0 +1,178 @@ +<!-- +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. +--> + +# Getting Started + +## Installation + +Add `paimon` to your `Cargo.toml`: + +```toml +[dependencies] +paimon = "0.0.0" +tokio = { version = "1", features = ["full"] } +``` + +By default, the `storage-fs` (local filesystem) and `storage-memory` (in-memory) backends are enabled. To use additional storage backends, enable the corresponding feature flags: + +```toml +[dependencies] +paimon = { version = "0.0.0", features = ["storage-s3"] } +``` + +Available storage features: + +| Feature | Backend | +|------------------|------------------| +| `storage-fs` | Local filesystem | +| `storage-memory` | In-memory | +| `storage-s3` | Amazon S3 | +| `storage-oss` | Alibaba Cloud OSS| +| `storage-all` | All of the above | + +## Catalog Management + +`FileSystemCatalog` manages databases and tables stored on a local (or remote) filesystem. + +### Create a Catalog + +```rust +use paimon::FileSystemCatalog; + +let catalog = FileSystemCatalog::new("/tmp/paimon-warehouse")?; +``` + +### Manage Databases + +```rust +use paimon::Catalog; // import the trait +use std::collections::HashMap; + +// Create a database +catalog.create_database("my_db", false, HashMap::new()).await?; + +// List databases +let databases = catalog.list_databases().await?; + +// Drop a database (cascade = true to drop all tables inside) +catalog.drop_database("my_db", false, true).await?; +``` + +### Manage Tables + +```rust +use paimon::catalog::Identifier; +use paimon::spec::{DataType, IntType, VarCharType, Schema}; + +// Define a schema +let schema = Schema::builder() + .column("id", DataType::Int(IntType::new())) + .column("name", DataType::VarChar(VarCharType::string_type())) + .build()?; + +// Create a table +let identifier = Identifier::new("my_db", "my_table"); +catalog.create_table(&identifier, schema, false).await?; + +// List tables in a database +let tables = catalog.list_tables("my_db").await?; + +// Get a table handle +let table = catalog.get_table(&identifier).await?; +``` + +## Reading a Table + +Paimon Rust uses a scan-then-read pattern: first scan the table to produce splits, then read data from those splits as Arrow `RecordBatch` streams. + +```rust +use futures::StreamExt; + +// Get a table from the catalog +let table = catalog.get_table(&Identifier::new("my_db", "my_table")).await?; + +// Create a read builder +let read_builder = table.new_read_builder(); + +// Step 1: Scan — produces a Plan containing DataSplits +let scan = read_builder.new_scan(); +let plan = scan.plan().await?; + +// Step 2: Read — consumes splits and returns Arrow RecordBatches +let reader = read_builder.new_read()?; +let mut stream = reader.to_arrow(plan.splits())?; + +while let Some(batch) = stream.next().await { + let batch = batch?; + println!("Got batch with {} rows", batch.num_rows()); +} +``` + +## DataFusion Integration + +Query Paimon tables using SQL with [Apache DataFusion](https://datafusion.apache.org/). Add the integration crate: + +```toml +[dependencies] +paimon = "0.0.0" +paimon-datafusion = "0.0.0" +datafusion = "46" Review Comment: ```suggestion datafusion = "52" ``` The DataFusion version here is out of date. The integration crate currently depends on 52.3.0 — using "46" will cause API incompatibility at compile time. Please update to datafusion = "52". ########## docs/src/getting-started.md: ########## @@ -0,0 +1,178 @@ +<!-- +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. +--> + +# Getting Started + +## Installation + +Add `paimon` to your `Cargo.toml`: + +```toml +[dependencies] +paimon = "0.0.0" +tokio = { version = "1", features = ["full"] } +``` + +By default, the `storage-fs` (local filesystem) and `storage-memory` (in-memory) backends are enabled. To use additional storage backends, enable the corresponding feature flags: + +```toml +[dependencies] +paimon = { version = "0.0.0", features = ["storage-s3"] } +``` + +Available storage features: + +| Feature | Backend | +|------------------|------------------| +| `storage-fs` | Local filesystem | +| `storage-memory` | In-memory | +| `storage-s3` | Amazon S3 | +| `storage-oss` | Alibaba Cloud OSS| +| `storage-all` | All of the above | + +## Catalog Management + +`FileSystemCatalog` manages databases and tables stored on a local (or remote) filesystem. + +### Create a Catalog + +```rust +use paimon::FileSystemCatalog; + +let catalog = FileSystemCatalog::new("/tmp/paimon-warehouse")?; +``` + +### Manage Databases + +```rust +use paimon::Catalog; // import the trait +use std::collections::HashMap; + +// Create a database +catalog.create_database("my_db", false, HashMap::new()).await?; + +// List databases +let databases = catalog.list_databases().await?; + +// Drop a database (cascade = true to drop all tables inside) +catalog.drop_database("my_db", false, true).await?; +``` + +### Manage Tables + +```rust +use paimon::catalog::Identifier; +use paimon::spec::{DataType, IntType, VarCharType, Schema}; + +// Define a schema +let schema = Schema::builder() + .column("id", DataType::Int(IntType::new())) + .column("name", DataType::VarChar(VarCharType::string_type())) + .build()?; + +// Create a table +let identifier = Identifier::new("my_db", "my_table"); +catalog.create_table(&identifier, schema, false).await?; + +// List tables in a database +let tables = catalog.list_tables("my_db").await?; + +// Get a table handle +let table = catalog.get_table(&identifier).await?; +``` + +## Reading a Table + +Paimon Rust uses a scan-then-read pattern: first scan the table to produce splits, then read data from those splits as Arrow `RecordBatch` streams. + +```rust +use futures::StreamExt; + +// Get a table from the catalog +let table = catalog.get_table(&Identifier::new("my_db", "my_table")).await?; + +// Create a read builder +let read_builder = table.new_read_builder(); + +// Step 1: Scan — produces a Plan containing DataSplits +let scan = read_builder.new_scan(); Review Comment: This example will not compile. `new_scan()` borrows `read_builder` immutably and the returned `TableScan<'a>` keeps that borrow alive as long as `scan` is in scope. Calling `read_builder.new_read()` on line 119 while `scan` still holds the borrow will be rejected by the borrow checker. Split the two phases into separate scopes: ```rust // Scan phase — borrow ends when this block exits let plan = { let scan = read_builder.new_scan(); scan.plan().await? }; // Read phase let reader = read_builder.new_read()?; let mut stream = reader.to_arrow(plan.splits())?; ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
