cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Double Quotes Parsing Error Expression

nosingh
New Contributor

I am getting the below error when I am using the expression to run using the filter. If I remove them and run it, it works fine. The double quotes are causing issues. Any help would be greatly appreciated? I have changed the filed names because of confidentiality issues. Thank You

ERROR:
Expression parsing failed near โ€“ amap,'" >> { << โ€˜, โ€˜{โ€™),โ€™ (Reason: Mismatched input โ€˜{โ€™ at line 9:60. Expecting one of: {, โ€˜||โ€™, โ€˜&&โ€™, โ€˜^โ€™, โ€˜==โ€™, โ€˜!=โ€™, โ€˜>โ€™, โ€˜<โ€™, โ€˜>=โ€™, โ€˜<=โ€™, โ€˜+โ€™, โ€˜-โ€™, โ€˜*โ€™, โ€˜/โ€™, โ€˜%โ€™, โ€˜?โ€™, โ€˜instanceofโ€™, โ€˜inโ€™, โ€˜matchesโ€™, โ€˜[โ€™, โ€˜(โ€™, โ€˜.โ€™, PropertyRef}; Resolution: Please check expression syntax)

SQL:
โ€œREPLACE INTO abc.stg_order
select DISTINCT 1 as orderno
, 1 as orderId , 1 as subOrderId, 1 as itemId,
case when pi.amap is null then
JSON_EXTRACT_STRING(REPLACE(REPLACE(REPLACE(pi.amap,'โ€{โ€˜, โ€˜{โ€™),โ€™}โ€œโ€˜,โ€™}โ€˜),โ€™\โ€โ€˜,โ€™โ€œโ€˜),โ€˜countryโ€™)
else
REPLACE(pi.amap::country, โ€˜"โ€™, โ€˜โ€™)
end as country
, case when pi.amap is null then JSON_EXTRACT_STRING(REPLACE(REPLACE(REPLACE(pi.att ,โ€™โ€{โ€˜, โ€˜{โ€™),โ€™}โ€œโ€˜, โ€˜}โ€™),โ€™\โ€โ€˜, โ€˜"โ€™) ,โ€˜ffโ€™)
else REPLACE(pi.amap::ff, โ€˜"โ€™, โ€˜โ€™)
end as ff
, case when pi.amap is null then JSON_EXTRACT_STRING(REPLACE(REPLACE(REPLACE(pi.att ,โ€™โ€œ{โ€˜, โ€˜{โ€™),โ€™}โ€โ€˜, โ€˜}โ€™),โ€™\โ€œ', 'โ€โ€˜) ,โ€˜frameโ€™)
else REPLACE(pi.amap::frame, โ€˜"โ€™, โ€˜โ€™)
end as frame
, case when pi.amap is null then JSON_EXTRACT_STRING(REPLACE(REPLACE(REPLACE(pi.att,โ€™โ€œ{โ€˜, โ€˜{โ€™),โ€™}โ€โ€˜, โ€˜}โ€™),โ€™\โ€œ', 'โ€โ€˜) ,โ€˜orientationโ€™)
else REPLACE(pi.amap::orientation, โ€˜"โ€™, โ€˜โ€™)
end as orientation
, case when pi.amap is null then JSON_EXTRACT_STRING(REPLACE(REPLACE(REPLACE(pi.att,โ€™" {โ€˜, โ€˜{โ€™),โ€™}โ€œโ€˜, โ€˜}โ€™),โ€™\โ€โ€˜, โ€˜"โ€™) ,โ€˜sideโ€™)
else REPLACE(pi.amap::side, โ€˜"โ€™, โ€˜โ€™)
end as side
, case when pi.amap is null then REPLACE(REPLACE(REPLACE(pi.att ,โ€™โ€œ{โ€˜, โ€˜{โ€™),โ€™}โ€โ€˜, โ€˜}โ€™),โ€™\โ€œโ€˜,โ€™โ€')
else pi.amap
end as amap
,ci.componentId
, pi.ingest_ts
from
abc.product pi
JOIN abc.component ci on
pi.Id = ci.Id
WHERE pi.ingest_ts > โ€˜โ€œ+_filter_1+โ€โ€™"

1 REPLY 1

del
Contributor III

Hi @nosingh,

2 tips:

  1. The community forum reformatting can be a pain, so when you post code, itโ€™s easiest to use the preformatted text icon image so that your code doesnโ€™t get reformatted and difficult to troubleshoot.
  2. To resolve the error in your current expression, you need to escape (with a backslash) both your double-quotes and the backslash character:
"REPLACE INTO abc.stg_order
select DISTINCT 1 as orderno
, 1 as orderId , 1 as subOrderId, 1 as itemId,
case when pi.amap is null then
JSON_EXTRACT_STRING(REPLACE(REPLACE(REPLACE(pi.amap,'\"{', '{'),'}\"','}'),'\\\"','\"'),'country')
else
REPLACE(pi.amap::country, '\"', '')
end as country
, case when pi.amap is null then JSON_EXTRACT_STRING(REPLACE(REPLACE(REPLACE(pi.att ,'\"{', '{'),'}\"', '}'),'\\\"', '\"') ,'ff')
else REPLACE(pi.amap::ff, '\"', '')
end as ff
, case when pi.amap is null then JSON_EXTRACT_STRING(REPLACE(REPLACE(REPLACE(pi.att ,'\"{', '{'),'}\"', '}'),'\\\"', '\"') ,'frame')
else REPLACE(pi.amap::frame, '\"', '')
end as frame
, case when pi.amap is null then JSON_EXTRACT_STRING(REPLACE(REPLACE(REPLACE(pi.att,'\"{', '{'),'}\"', '}'),'\\\"', '\"') ,'orientation')
else REPLACE(pi.amap::orientation, '\"', '')
end as orientation
, case when pi.amap is null then JSON_EXTRACT_STRING(REPLACE(REPLACE(REPLACE(pi.att,'\" {', '{'),'}\"', '}'),'\\\"', '\"') ,'side')
else REPLACE(pi.amap::side, '\"', '')
end as side
, case when pi.amap is null then REPLACE(REPLACE(REPLACE(pi.att ,'\"{', '{'),'}\"', '}'),'\\\"','\"')
else pi.amap
end as amap
,ci.componentId
, pi.ingest_ts
from
abc.product pi
JOIN abc.component ci on
pi.Id = ci.Id
WHERE pi.ingest_ts > '"+_filter_1+"'"