-
Notifications
You must be signed in to change notification settings - Fork 31
Description
Hello, I've been trying for a long time to make setup a variable whose query depends on another variable and couldn't. The only explanation I have is that there is a bug somewhere.
This is my table
CREATE TABLE IF NOT EXISTS ao_pricing.data (
model_instrument uuid,
maturity bigint,
as_of timestamp,
label ascii static,
pricer_data pricer_data_t,
fitter_data fitter_data_t,
PRIMARY KEY ((model_instrument, maturity), as_of)
) WITH CLUSTERING ORDER BY (as_of DESC);
Please notice I have a partition key which is composed of two keys: model_instrument and maturity. My temporal variable is: as_of.
Now I want to show in Grafana graphs that depend on the pair (model_instrument, maturity) which must be selectable through a dropdown and this would be my parameter for the queries.
There are multiple problems with this. First is that I don't know how to return a pair or tuple for variables. The ideal query to get all the parameter values would be:
SELECT DISTINCT model_instrument, maturity, label FROM ao_pricing.data;
It returns results like this:
cqlsh> SELECT DISTINCT model_instrument, maturity, label FROM ao_pricing.data;
model_instrument | maturity | label
--------------------------------------+---------------------+-----------------------------
e971637a-9454-11e1-a34e-15ebadefba03 | 1704472200000000000 | INGA 2024-01-05
ea14f940-9454-11e1-a34e-15ebadefba03 | 1704472200000000000 | RDSA 2024-01-05
e9a7721c-9454-11e1-a34e-15ebadefba03 | 1718983800000000000 | VOW 2024-06-21
e971637a-9454-11e1-a34e-15ebadefba03 | 1710520200000000000 | INGA 2024-03-15
e95fa338-9454-11e1-a34e-15ebadefba03 | 1718983800000000000 | BAS 2024-06-21
e95fa338-9454-11e1-a34e-15ebadefba03 | 1726846200000000000 | BAS 2024-09-20
Now if I define a variable, it expects to get two columns: one is the value and one is the text. My query would return 3, I can't make the value a pair or tuple. I came up with a work around leveraging the functions from ScyllaDB (let me know if you have a better solution for this):
CREATE OR REPLACE FUNCTION ao_pricing.pair_to_key(a ascii, b ascii)
RETURNS NULL ON NULL INPUT
RETURNS ascii
LANGUAGE LUA
AS 'return a.."|"..b;';
So I changed and now I have two variables, first query is be the following (products):
SELECT DISTINCT pair_to_key(pair_to_key(CAST(model_instrument AS ascii), CAST(maturity AS ascii)), label) FROM ao_pricing.data;
and second query is:
SELECT DISTINCT pair_to_key(pair_to_key(CAST(model_instrument AS ascii), CAST(maturity AS ascii)), label) FROM ao_pricing.data WHERE model_instrument = $products ALLOW FILTERING;
But this does not work, I always get an error: Error updating options: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data.
Do you have a solution: I can either keep the two variables separated OR I can keep one variable but in that case I need to extract the first part of the concatenation (and this seems to be impossible to do in Grafana).