Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Transform a Bigquery table to list of json on dataform

Hello, 

I have a script  on definition/query.sqlx: 

with data as (SELECT  array_agg(struct(obj,val)) as x FROM   tableSELECT    to_json_string(x)  as json FROM data .
The result of this query is json list :[{"obj":"t1","val":"'ok'"},{"obj":"t2","val":"'ko'"}] for exemple , I would like to assign the result of the script to my function created on includes/functions.js,  : 
function tagValues(results, tagName) {
    if (!Array.isArray(results)) {
        console.error("Input is not an array");
        return {};
    }
    const tagValues = {};
    results.forEach(row => {
        tagValues[row.tag] = row.value;
    });
    return tagValues[tagName];
},  but when iwrite this query  select ${functions.tagValues(ref("query"), "t1") I have the error, select [object , object],  It is because the result of the query is not is a list of json but a table, is it possible to convert the result of the query list of json so that it can take on my function ? The result that I want  select 'ok' .  Thanks
0 0 174
0 REPLIES 0