Files
rs/tests/it/cursor_stats.rs
zeekay 86788566d1 datastore: rebrand the Rust client and speak the Datastore wire protocol
Cut from the upstream v0.13.3 release tag (not HEAD) so this is a pure
rename with no behaviour change. v0.13.3 is what our consumers already
resolve to: insights/rust's Cargo.lock pins clickhouse 0.13.3 and its
manifest already declares `datastore` at 0.13.x.

The load-bearing change is the HTTP auth header rename. The Datastore
server reads only X-Datastore-User / X-Datastore-Key; the upstream names
return `401 Code: 194 Authentication failed`. Every un-renamed HTTP
client is therefore unable to authenticate at all — this is a
correctness fix, not branding.

- crate `clickhouse` -> `datastore`, `clickhouse-derive` -> `datastore-derive`;
  versions preserved exactly (0.13.3 / 0.2.0).
- derive macro emits `datastore::Row` in lockstep, so downstream
  `#[derive(Row)]` keeps resolving.
- User-Agent reports `datastore-rs/{version}`.
- test-harness env vars CLICKHOUSE_* -> DATASTORE_*; compose uses
  ghcr.io/hanzoai/datastore with /etc/datastore-server config paths.
- doc links point at docs.hanzo.ai/datastore.
- `publish = false`: the `datastore` name on crates.io belongs to an
  unrelated crate, so consume this by git tag, never by version range.

CHANGELOG is truncated to a fork notice rather than find-replaced —
rewriting upstream release history would manufacture changes Datastore
never shipped. References to upstream issues keep their numbers.
2026-07-26 11:30:32 -07:00

52 lines
1.4 KiB
Rust

use datastore::{Client, Compression};
use crate::{create_simple_table, SimpleRow};
async fn check(client: Client, expected_ratio: f64) {
create_simple_table(&client, "test").await;
let mut insert = client.insert("test").unwrap();
for i in 0..1_000 {
insert.write(&SimpleRow::new(i, "foobar")).await.unwrap();
}
insert.end().await.unwrap();
let mut cursor = client
.query("SELECT * FROM test")
.fetch::<SimpleRow>()
.unwrap();
let mut received = cursor.received_bytes();
let mut decoded = cursor.decoded_bytes();
assert_eq!(received, 0);
assert_eq!(decoded, 0);
while cursor.next().await.unwrap().is_some() {
assert!(cursor.received_bytes() >= received);
assert!(cursor.decoded_bytes() >= decoded);
received = cursor.received_bytes();
decoded = cursor.decoded_bytes();
}
assert_eq!(decoded, 15000);
assert_eq!(cursor.received_bytes(), dbg!(received));
assert_eq!(cursor.decoded_bytes(), dbg!(decoded));
assert_eq!(
(decoded as f64 / received as f64 * 10.).round() / 10.,
expected_ratio
);
}
#[tokio::test]
async fn none() {
let client = prepare_database!().with_compression(Compression::None);
check(client, 1.0).await;
}
#[cfg(feature = "lz4")]
#[tokio::test]
async fn lz4() {
let client = prepare_database!().with_compression(Compression::Lz4);
check(client, 3.7).await;
}