From 37057f221a06b14c17a27184d2c66e9b83a94aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ko=C5=82aczkowski?= Date: Tue, 25 Jun 2024 07:46:21 +0200 Subject: [PATCH] Generating lists --- Cargo.lock | 8 +------- Cargo.toml | 4 ++-- src/context.rs | 20 +++++++++++++++++++- src/workload.rs | 2 ++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fafe35..7348958 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1020,7 +1020,7 @@ dependencies = [ [[package]] name = "latte-cli" -version = "0.26.0" +version = "0.27.0" dependencies = [ "anyhow", "base64 0.22.1", @@ -1913,8 +1913,6 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "scylla" version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9439d92eea9f86c07175c819c3a129ca28b02477b47df26db354a1f4ea7ee276" dependencies = [ "arc-swap", "async-trait", @@ -1946,8 +1944,6 @@ dependencies = [ [[package]] name = "scylla-cql" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64037fb9d9c59ae15137fff9a56c4d528908dfd38d09e75b5f8e56e3894966dd" dependencies = [ "async-trait", "byteorder", @@ -1963,8 +1959,6 @@ dependencies = [ [[package]] name = "scylla-macros" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e5fe1d389adebe6a1a27bce18b81a65ff18c25d58a795de490e18b0e7a27b9f" dependencies = [ "darling", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index b27e7ce..8484c3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "latte-cli" description = "A database benchmarking tool for Apache Cassandra" -version = "0.26.0" +version = "0.27.0" authors = ["Piotr Kołaczkowski "] edition = "2021" readme = "README.md" @@ -38,7 +38,7 @@ rand = "0.8" regex = "1.5" rune = "0.12" rust-embed = "8" -scylla = { version = "0.13", features = ["ssl"] } +scylla = { path = "../scylla-rust-driver/scylla", features = ["ssl"] } search_path = "0.1" serde = { version = "1.0.116", features = ["derive"] } serde_json = "1.0.57" diff --git a/src/context.rs b/src/context.rs index 2900681..1c56a08 100644 --- a/src/context.rs +++ b/src/context.rs @@ -20,7 +20,7 @@ use rune::ast; use rune::ast::Kind; use rune::macros::{quote, MacroContext, TokenStream}; use rune::parse::Parser; -use rune::runtime::{Object, Shared, TypeInfo, VmError}; +use rune::runtime::{Function, Object, Shared, TypeInfo, VmError}; use rune::{Any, Value}; use rust_embed::RustEmbed; use scylla::_macro_internal::ColumnType; @@ -616,6 +616,15 @@ mod bind { .try_collect()?; Ok(CqlValue::Set(elements)) } + (Value::Vec(v), ColumnType::Vector(elt, dim)) => { + let v = v.borrow_ref().unwrap(); + let elements = v + .as_ref() + .iter() + .map(|v| to_scylla_value(v, elt)) + .try_collect()?; + Ok(CqlValue::Vector(elements)) + } ( Value::Object(v), ColumnType::UserDefinedType { @@ -858,6 +867,15 @@ pub fn clamp_int(value: i64, min: i64, max: i64) -> i64 { value.clamp(min, max) } +pub fn list(seed: i64, len: usize, generator: Function) -> Result, VmError> { + let mut result = Vec::with_capacity(len); + for i in 0..len { + let value = generator.call((hash2(seed, i as i64),))?; + result.push(value); + } + Ok(result) +} + /// Generates random blob of data of given length. /// Parameter `seed` is used to seed the RNG. pub fn blob(seed: i64, len: usize) -> rune::runtime::Bytes { diff --git a/src/workload.rs b/src/workload.rs index a9cfc6f..bfa7375 100644 --- a/src/workload.rs +++ b/src/workload.rs @@ -129,6 +129,8 @@ impl Program { let mut latte_module = Module::with_crate("latte"); latte_module.function(&["blob"], context::blob).unwrap(); latte_module.function(&["text"], context::text).unwrap(); + latte_module.function(&["list"], context::list).unwrap(); + latte_module .function(&["now_timestamp"], context::now_timestamp) .unwrap();