Search code examples
testingcassandracqlnosqlbench

How do I handle UUID query parameters when generating NoSQLBench tests?


I am using NoSQLBench version 5 to generate queries against a table in a Cassandra database (DataStax DSE 6.8). The query goes by the primary key, a UUID column.

A simple example:

create table test.tab01 ( id uuid, nm text, primary key (id) );

The query expects a UUID parameter:

select nm from test.tab01 where id = ?;

In previous NoSQLBench versions, I would export the id's from the table to a CSV file and use the function ModuloCSVLineToUUID() to bind the query parameter, as shown in the yaml script below. The parameters would be taken from the 'ids.csv' file.

Test script test01.yaml:

# 
scenarios:
  default: run driver=stdout cycles=10
  teste: run driver=cql hosts=srvdse01 localdc=Cassandra cycles=1000

bindings:
  item : ModuloCSVLineToUUID('ids.csv','id')

statements:
 - cmd1: |
          select nm from test.tab01 where id = {item};

However, running the above script with NoSQLBench version 5 I get the error shown below. I've been looking for an alternative way of doing this. How should UUID query parameters be handled in nb5?

$ /opt/nb/nb5 test01 teste
2074 ERROR \[scenarios:001\] SCENARIO     Error in scenario, shutting down. (javax.script.ScriptException: java.lang.RuntimeException: There were no functions found for ModuloCSVLineToUUID('ids.csv','id'))
2086 WARN  \[main\] NBCLI        executions: 1 scenarios, 0 normal, 1 errored
2087 ERROR \[main\] ERRORHANDLER Error from driver or included library: javax.script.ScriptException: java.lang.RuntimeException: There were no functions found for ModuloCSVLineToUUID('ids.csv','id')
java.lang.RuntimeException: javax.script.ScriptException: java.lang.RuntimeException: There were no functions found for ModuloCSVLineToUUID('ids.csv','id')
at io.nosqlbench.engine.core.lifecycle.scenario.Scenario.executeScenarioScripts(Scenario.java:335)
at io.nosqlbench.engine.core.lifecycle.scenario.Scenario.runScenario(Scenario.java:269)
at io.nosqlbench.engine.core.lifecycle.scenario.Scenario.call(Scenario.java:406)
at io.nosqlbench.engine.core.lifecycle.scenario.Scenario.call(Scenario.java:63)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: javax.script.ScriptException: java.lang.RuntimeException: There were no functions found for ModuloCSVLineToUUID('ids.csv','id')

Solution

  • This was a highly specialized function which was deprecated in nb5 in lieu of composed forms. However, the String -> ToUUID() -> UUID function is missing, so it will be in the next point release. Then, you'll be able to use ModuloCSVLineToString(...); ToUUID().

    Here is a binding function which provides some timeuuid values:

    bindings:
     # advance by 1 second of millis per cycle,
     #  and then lift the minimum value to 2023 time base
     #  and then convert to the closest timeuuid
     one_per_sec: Mul(1000L); StartingEpochMillis('2023-01-01 00:00:00'); ToFinestTimeUUID();
    

    Given that the specific type in your CQL schema will determine which UUIDs are allowed to be assigned, this may or may not work. If timeuuids are not appropriate for your schema, you can use ToUUID() or ToHashedUUID() in the meantime.