Skip to content

Commit

Permalink
Generating lists
Browse files Browse the repository at this point in the history
  • Loading branch information
pkolaczk committed Jul 4, 2024
1 parent d3c6850 commit b35b596
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
8 changes: 1 addition & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <pkolaczk@gmail.com>"]
edition = "2021"
readme = "README.md"
Expand Down Expand Up @@ -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"
Expand Down
20 changes: 19 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -907,6 +916,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<Vec<Value>, 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 {
Expand Down
2 changes: 2 additions & 0 deletions src/workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b35b596

Please sign in to comment.