mirror of
https://github.com/hanzo-ds/rs.git
synced 2026-10-30 20:49:56 +00:00
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.
109 lines
3.1 KiB
Rust
109 lines
3.1 KiB
Rust
#![cfg(feature = "time")]
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use time::Month::January;
|
|
|
|
use datastore::Row;
|
|
|
|
// See also: https://docs.hanzo.ai/datastore/sql-reference/data-types/variant
|
|
|
|
#[tokio::test]
|
|
async fn variant_data_type() {
|
|
let client = prepare_database!();
|
|
|
|
// NB: Inner Variant types are _always_ sorted alphabetically,
|
|
// and should be defined in _exactly_ the same order in the enum.
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
enum MyRowVariant {
|
|
Array(Vec<i16>),
|
|
Boolean(bool),
|
|
// attributes should work in this case, too
|
|
#[serde(with = "datastore::serde::time::date")]
|
|
Date(time::Date),
|
|
FixedString([u8; 6]),
|
|
Float32(f32),
|
|
Float64(f64),
|
|
Int128(i128),
|
|
Int16(i16),
|
|
Int32(i32),
|
|
Int64(i64),
|
|
Int8(i8),
|
|
String(String),
|
|
UInt128(u128),
|
|
UInt16(i16),
|
|
UInt32(u32),
|
|
UInt64(u64),
|
|
UInt8(i8),
|
|
}
|
|
|
|
#[derive(Debug, PartialEq, Row, Serialize, Deserialize)]
|
|
struct MyRow {
|
|
var: MyRowVariant,
|
|
}
|
|
|
|
// No matter the order of the definition on the Variant types, it will always be sorted as follows:
|
|
// Variant(Array(UInt16), Bool, FixedString(6), Float32, Float64, Int128, Int16, Int32, Int64, Int8, String, UInt128, UInt16, UInt32, UInt64, UInt8)
|
|
client
|
|
.query(
|
|
"
|
|
CREATE OR REPLACE TABLE test_var
|
|
(
|
|
`var` Variant(
|
|
Array(UInt16),
|
|
Bool,
|
|
Date,
|
|
FixedString(6),
|
|
Float32, Float64,
|
|
Int128, Int16, Int32, Int64, Int8,
|
|
String,
|
|
UInt128, UInt16, UInt32, UInt64, UInt8
|
|
)
|
|
)
|
|
ENGINE = MergeTree
|
|
ORDER BY ()",
|
|
)
|
|
.with_option("allow_experimental_variant_type", "1")
|
|
.with_option("allow_suspicious_variant_types", "1")
|
|
.execute()
|
|
.await
|
|
.unwrap();
|
|
|
|
let vars = [
|
|
MyRowVariant::Array(vec![1, 2]),
|
|
MyRowVariant::Boolean(true),
|
|
MyRowVariant::Date(time::Date::from_calendar_date(2021, January, 1).unwrap()),
|
|
MyRowVariant::FixedString(*b"foobar"),
|
|
MyRowVariant::Float32(100.5),
|
|
MyRowVariant::Float64(200.1),
|
|
MyRowVariant::Int8(2),
|
|
MyRowVariant::Int16(3),
|
|
MyRowVariant::Int32(4),
|
|
MyRowVariant::Int64(5),
|
|
MyRowVariant::Int128(6),
|
|
MyRowVariant::String("my_string".to_string()),
|
|
MyRowVariant::UInt8(7),
|
|
MyRowVariant::UInt16(8),
|
|
MyRowVariant::UInt32(9),
|
|
MyRowVariant::UInt64(10),
|
|
MyRowVariant::UInt128(11),
|
|
];
|
|
|
|
let rows = vars.map(|var| MyRow { var });
|
|
|
|
// Write to the table.
|
|
let mut insert = client.insert("test_var").unwrap();
|
|
for row in &rows {
|
|
insert.write(row).await.unwrap();
|
|
}
|
|
insert.end().await.unwrap();
|
|
|
|
// Read from the table.
|
|
let result_rows = client
|
|
.query("SELECT ?fields FROM test_var")
|
|
.fetch_all::<MyRow>()
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(result_rows, rows)
|
|
}
|