use latte::*; pub const KEYSPACE = latte::param!("keyspace", "latte"); pub const TABLE = latte::param!("table", "sai_orig"); // Total number of rows in the table: pub const ROW_COUNT = latte::param!("rows", 100000); // Limit on the number of rows to fetch in a single query: pub const READ_SIZE = latte::param!("read_size", 10); // Helper constants for identifying prepared statements: pub const READ = "read"; pub const WRITE = "write"; pub async fn schema(ctx) { ctx.execute(` CREATE KEYSPACE IF NOT EXISTS ${KEYSPACE} WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1 }`).await?; ctx.execute(` DROP TABLE IF EXISTS ${KEYSPACE}.${TABLE}`).await?; ctx.execute(` CREATE TABLE ${KEYSPACE}.${TABLE} ( id uuid, time timestamp, value int, lc int, tag text, PRIMARY KEY (id) )`).await?; ctx.execute(`CREATE CUSTOM INDEX IF NOT EXISTS ON ${KEYSPACE}.${TABLE}(time) USING 'StorageAttachedIndex'`).await?; ctx.execute(`CREATE CUSTOM INDEX IF NOT EXISTS ON ${KEYSPACE}.${TABLE}(value) USING 'StorageAttachedIndex'`).await?; ctx.execute(`CREATE CUSTOM INDEX IF NOT EXISTS ON ${KEYSPACE}.${TABLE}(lc) USING 'StorageAttachedIndex'`).await?; ctx.execute(`CREATE CUSTOM INDEX IF NOT EXISTS ON ${KEYSPACE}.${TABLE}(tag) USING 'StorageAttachedIndex'`).await?; Ok(()) } pub async fn erase(ctx) { ctx.execute(`TRUNCATE TABLE ${KEYSPACE}.${TABLE}`).await?; Ok(()) } pub async fn prepare_write(ctx) { ctx.load_cycle_count = ROW_COUNT; ctx.prepare(WRITE, `INSERT INTO ${KEYSPACE}.${TABLE}(id, time, value, lc, tag) VALUES (?, ?, ?, ?, ?)`).await?; ctx.data.tags = fs::read_resource_lines("variable_words.txt")?; Ok(()) } pub async fn write_row(ctx, i) { let id = uuid(i); let time = i * 1000; let value = normal(i, 125.0, 25.0).clamp(0.0, 200.0).to_i32(); let lc = normal(i, 2.2, 2.5).clamp(0.0, 5.0).to_i32(); let tag = hash_select(i, ctx.data.tags); ctx.execute_prepared(WRITE, [id, time, value, lc, tag]).await?; Ok(()) }