Skip to content

docs: add clickhouse-ext-arrow usage example#434

Open
nanookclaw wants to merge 2 commits into
ClickHouse:mainfrom
nanookclaw:fix/arrow-usage-example
Open

docs: add clickhouse-ext-arrow usage example#434
nanookclaw wants to merge 2 commits into
ClickHouse:mainfrom
nanookclaw:fix/arrow-usage-example

Conversation

@nanookclaw
Copy link
Copy Markdown

Summary

Adds a runnable examples/arrow.rs showing how to use clickhouse-ext-arrow for both Arrow reads and writes. The example follows the existing tests/it/arrow.rs coverage, but keeps the flow small enough for users to copy: create a table, insert one RecordBatch, stream query results with fetch_arrow(), and collect a merged batch.

The PR also links the example from examples/README.md and adds a short usage pointer in ext-arrow/README.md with the exact cargo run command.

Closes #433.

Verification

  • cargo fmt --check
  • cargo check --package clickhouse --example arrow
  • cargo clippy --package clickhouse --example arrow -- -D warnings
  • git diff --check

Signed-off-by: Nanook <nanookclaw@users.noreply.github.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 26, 2026

CLA assistant check
All committers have signed the CLA.

Comment thread examples/arrow.rs Outdated
async fn ddl(client: &Client) -> Result<()> {
client
.query(&format!(
"CREATE OR REPLACE TABLE {TABLE_NAME}(bar Int32, baz String) \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know we might have used this pattern in a few other examples, but IMO extracting the table name to a constant only serves to obfuscate the code here.

Moreover it's bad form to use format!() (we use it in tests mostly for legacy reasons). ClickHouse supports identifiers as bind parameters which are properly escaped. I don't want to teach the users that format!() is necessary, because it isn't.

Comment thread examples/arrow.rs Outdated
Comment on lines +49 to +50
// For a multi-batch insert, call `insert.write(&batch).await?` repeatedly,
// then `insert.end().await?` to flush and finish the request.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of explaining this, why not show it? It's not much more code.

Comment thread examples/README.md Outdated
- [data_types_derive_containers.rs](data_types_derive_containers.rs) - deriving container-like (Array, Tuple, Map, Nested, Geo) ClickHouse data types in a struct.
- [data_types_variant.rs](data_types_variant.rs) - working with the [Variant data type](https://clickhouse.com/docs/en/sql-reference/data-types/variant).
- [data_types_new_json.rs](data_types_new_json.rs) - working with the [new JSON data type](https://clickhouse.com/docs/en/sql-reference/data-types/newjson) as a String.
- [arrow.rs](arrow.rs) - reading and writing [Apache Arrow](https://arrow.apache.org/) `RecordBatch`es via the [`clickhouse-ext-arrow`](../ext-arrow) crate.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's debatable where this should go, but I would move it to Special cases because this section is talking mainly about ClickHouse data types.

@nanookclaw
Copy link
Copy Markdown
Author

Updated the Arrow example for the review comments in bd22cac:

  • removed the TABLE_NAME constant and format!()-built identifier SQL
  • switched the DDL/SELECT statements to {table:Identifier} server-side parameters
  • changed the insert example to write two RecordBatches before end()
  • moved examples/arrow.rs under Special cases in examples/README.md

Validation:

  • git diff --check
  • cargo fmt --all --check
  • cargo check --package clickhouse --example arrow

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.

Create clickhouse-ext-arrow Usage Example

3 participants