docs: add clickhouse-ext-arrow usage example#434
Conversation
Signed-off-by: Nanook <nanookclaw@users.noreply.github.com>
| async fn ddl(client: &Client) -> Result<()> { | ||
| client | ||
| .query(&format!( | ||
| "CREATE OR REPLACE TABLE {TABLE_NAME}(bar Int32, baz String) \ |
There was a problem hiding this comment.
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.
| // For a multi-batch insert, call `insert.write(&batch).await?` repeatedly, | ||
| // then `insert.end().await?` to flush and finish the request. |
There was a problem hiding this comment.
Instead of explaining this, why not show it? It's not much more code.
| - [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. |
There was a problem hiding this comment.
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.
|
Updated the Arrow example for the review comments in
Validation:
|
Summary
Adds a runnable
examples/arrow.rsshowing how to useclickhouse-ext-arrowfor both Arrow reads and writes. The example follows the existingtests/it/arrow.rscoverage, but keeps the flow small enough for users to copy: create a table, insert oneRecordBatch, stream query results withfetch_arrow(), and collect a merged batch.The PR also links the example from
examples/README.mdand adds a short usage pointer inext-arrow/README.mdwith the exactcargo runcommand.Closes #433.
Verification
cargo fmt --checkcargo check --package clickhouse --example arrowcargo clippy --package clickhouse --example arrow -- -D warningsgit diff --check