Skip to content

feat: rust examples for creating and querying Paimon tables - #648

Open
ganesh-skumar wants to merge 7 commits into
apache:mainfrom
ganesh-skumar:df-example
Open

feat: rust examples for creating and querying Paimon tables#648
ganesh-skumar wants to merge 7 commits into
apache:mainfrom
ganesh-skumar:df-example

Conversation

@ganesh-skumar

Copy link
Copy Markdown

Purpose

Add Rust examples demonstrating how to create a Paimon table with sample data and query it using DataFusion.

Brief change log

  • Add create_table.rs example to create a Paimon table and insert sample data.
  • Add datafusion_query.rs example demonstrating the DataFusion DataFrame API.
  • Add paimon-datafusion as a workspace dependency for the examples.

@ganesh-skumar

Copy link
Copy Markdown
Author

Hi, While checking the CI failure, the rust examples require adding paimon-datafusion and datafusion dependencies to paimon crate because they're located under crates/paimon/examples. As a result, the generated DEPENDENCIES.rust.tsv files also need to be updated.

I was wondering whether it would be more appropriate to place these examples in a separate example crate to avoid introducing these additional dependencies into the core paimon crate.

Or is updating the generated DEPENDENCIES.rust.tsv files the expected approach in this case?

Thanks!

Comment thread crates/paimon/examples/create_table.rs Outdated

// Create new database
catalog
.create_database("my_db", false, HashMap::new())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make this setup example safely rerunnable? With ignore_if_exists = false, a second invocation would fail. Perhaps the example can drop/recreate its sample objects everytime the example is run for a clean start.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, updated to ignore db if exists and creates fresh table.

Comment thread Cargo.toml Outdated
datafusion = "54.0.0"
datafusion-ffi = "54.0.0"
paimon = { version = "0.4.0", path = "crates/paimon" }
paimon-datafusion = { path = "crates/integrations/datafusion" }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to place datafusion_query.rs under the paimon-datafusion crate?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, created integrations/datafusion/examples/datafusion_query.rs

Comment thread crates/paimon/examples/create_table.rs Outdated

pub async fn create_catelog() -> Result<Arc<dyn Catalog>, Box<dyn Error>> {
let mut options = Options::new();
options.set(CatalogOptions::WAREHOUSE, "/path-to/testdata");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the path be provided as a cli argument, sharable by both examples. Since the user's would need to edit this code to wire up their real warehouse file otherwise.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to pass path via cli

@leaves12138 leaves12138 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran both examples end to end, including rerunning the setup and querying the resulting table. The functional flow works, but there is one destructive default behavior that should be addressed.


// if exists, drop and create fresh table and data
if table_exists {
catalog.drop_table(&identifier, false).await?;

@leaves12138 leaves12138 Aug 12, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid dropping an existing table by default? The warehouse is supplied as an arbitrary CLI path, so a user who points this example at an existing warehouse containing my_db.users would permanently delete that table and all of its data. Please fail when the table already exists, require an explicit destructive flag such as --overwrite, or use a clearly isolated example namespace/warehouse.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, added table recreation based on flag.

Comment thread crates/paimon/examples/create_table.rs Outdated
Ok(())
}

pub async fn create_catelog(warehouse: String) -> Result<Arc<dyn Catalog>, Box<dyn Error>> {

@leaves12138 leaves12138 Aug 12, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please rename create_catelog to create_catalog. The same typo also appears in datafusion_query.rs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

)
})?;

let overwrite = args.any(|arg| arg == "--overwrite");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make --overwrite order-independent, or document the required order? The first argument is always treated as the warehouse, so --overwrite <warehouse-path> fails; only <warehouse-path> --overwrite works. At minimum, please update the usage string to <warehouse-path> [--overwrite].

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated the usage doc with the correct argument order. I also tried making it order-independent, but it made the code a bit messy for a beginner-friendly create_table example.

@QuakeWang QuakeWang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@ArnavBalyan ArnavBalyan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @QuakeWang and thanks for the PR @ganesh-skumar!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants