简体   繁体   中英

Syntax error: Unclosed string literal at [10:5]

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!

For multi lines you need to use multi quotation marks ie ””” 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM