SELECT type, key
FROM (
SELECT * FROM
js(
(SELECT json, type FROM arboreal-vision-339901.take_home.virtual_kitchen_ubereats_hours
),
-- Input columns.
json, type,
-- Output schema.
"[{name: 'key', type:'string'}, -- error here
{name: 'type', type:'string'}]",
-- The function.
"function(r, emit) {
x=JSON.parse(r.json)
Object.keys(x).forEach(function(entry) {
emit({key:entry, type:r.type,});
});
}"
)
)
LIMIT 10
can't understand why there's an error with "[{name: 'key', type:'string'}
could anyone please help me solve this. thanks!
CodePudding user response:
For multi lines you need to use multi quotation marks i.e ”””
or ’’’
at the beginning and end of the string. For more information you can refer to the google cloud documentation .
You can try this below query:
SELECT type, key
FROM (
SELECT * FROM
js(
(SELECT json, type FROM arboreal-vision-339901.take_home.virtual_kitchen_ubereats_hours
),
-- Input columns.
json, type,
-- Output schema.
"""[{name: 'key', type:'string'}, -- error here
{name: 'type', type:'string'}]""",
-- The function.
"""function(r, emit) {
x=JSON.parse(r.json)
Object.keys(x).forEach(function(entry) {
emit({key:entry, type:r.type,});
});
}"""
)
)
LIMIT 10