Hello,
I have a script on definition/query.sqlx:
Solved! Go to Solution.
Here is a solution:
I have created a pyhton script that can execute the query and produce a string : q = '[{"obj":"t1","val":"'ok'"},{"obj":"t2","val":"'ko'"}]'
The q string value is stored in a json file in dataform project. This task can be automated using airflow (I use the operator DataformWriteFileOperator to create the json file), for exemple : includes/q_string.json
The path of the json file can be considered as a variable in the dataform.json file
I cant replicate your code but you are possibly looking for converting BQ table to JSON Data ? I would suggesting this Documentation how Google SQL is working with JSON:
Here is the code :
definition/query.sqlx :
Can you maybe describe what you are trying to achieve from a logical perspective without a lot of code. I see you have some SQL that returns some values and I see you have JavaScript that takes some input. The puzzle in my mind is what you are trying to achieve. Can you paint the high level picture of your design/logic. That will help (at least me) get a handle on the semantics and purpose of the code.
Yes of course. here is the data of my TABLE
OBJ | VAL |
t1 | 'ok' |
t2 | 'ko' |
What I am trying to acheive is to get the value from the column VAL knowing value from OBJ column and data from table after transforming data on the table to an array (list of json).
It is basically a function like this f (q, x) = y ==> f(q, t1) = 'ok' ; f(q, t2) = 'ko'
My inputs are : t1 , t2 value from OBJ column and the TABLE
The query will transform the data from the table to an array
q : [{"obj":"t1","val":"'ok'"},{"obj":"t2","val":"'ko'"}]
I have got the result of what I want to acheive by copy and paste the q result on my function. so what I did is : f([{"obj":"t1","val":"'ok'"},{"obj":"t2","val":"'ko'"}], "t1") = 'ok'
It is working fine.
But i don't want to copy and paste q value on the function, I would like to get the q value automatically from the result of the query as a variable on my function : f(q, "t1"), q is the variable which come from the result of the query .
It means that the result of the query will be call on the function, without any copy and paste.
Note that I am working on DATAFORM :
For exemple we can call a table as a variable. It would be the same for what I would like to acheive, call the result of the query as variable.
It is simple if I consider my table as a dataframe df: the result of the query will be this table
json |
q |
value of q is : [{"obj":"t1","val":"'ok'"},{"obj":"t2","val":"'ko'"}]
to get q value from my dataframe, I will run df.iloc[0]['json'] and the result is q and I can call it as a variable
So my function will be : f(df.iloc[0]['json'], "t1") = "ok"
Here is a solution:
I have created a pyhton script that can execute the query and produce a string : q = '[{"obj":"t1","val":"'ok'"},{"obj":"t2","val":"'ko'"}]'
The q string value is stored in a json file in dataform project. This task can be automated using airflow (I use the operator DataformWriteFileOperator to create the json file), for exemple : includes/q_string.json
The path of the json file can be considered as a variable in the dataform.json file