Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependant variable not working #182

Open
barsdeveloper opened this issue Dec 12, 2023 · 1 comment
Open

Dependant variable not working #182

barsdeveloper opened this issue Dec 12, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@barsdeveloper
Copy link

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).

@unflag
Copy link
Collaborator

unflag commented Dec 24, 2023

Hi, @barsdeveloper !
Thank you for your report. It is true that dependant variables are not supported by the datasource yet.
I believe that in your case there is no other way than to use separated variables.

@unflag unflag added the enhancement New feature or request label Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants