2

从任务运行过程时会记录以下错误消息,但当我手动运行它时工作正常:

存储过程 STAGE_SERVICEBUS_ORDER 中的执行错误:JSON 响应中缺少“查询代码”在 Statement.execute 第 4 行位置 60。

该过程如下所示:

CREATE OR REPLACE PROCEDURE "STAGE_SERVICEBUS_ORDER"(YEARMONTH VARCHAR)
RETURNS VARCHAR(16777216)
LANGUAGE JAVASCRIPT
EXECUTE AS OWNER
AS '
 snowflake.createStatement({ sqlText: `Truncate table DM.STG.SERVICEBUS_ORDER`}).execute();
 var copy_into_statement = `copy into DM.STG.SERVICEBUS_ORDER  (FILE_NAME,OBJECT)  from ( select metadata$filename, $1 from @SERVICEBUS_ORDER`+YEARMONTH+` )  file_format = (type = ''JSON'' strip_outer_array = false) force=true ON_ERROR = CONTINUE `;
 snowflake.createStatement({ sqlText: copy_into_statement}).execute();
return ''Done'';
';
4

1 回答 1

0

请尝试替换$1PARSE_JSON($1).

这是 Snowflake 文档中的一个示例,说明了在 COPY 语句中访问 JSON 文件元数据的解决方案:

-- Create a file format
CREATE OR REPLACE FILE FORMAT my_json_format
  TYPE = 'json';

-- Create an internal stage
CREATE OR REPLACE STAGE mystage2
  FILE_FORMAT = my_json_format;

-- Stage a data file
PUT file:///tmp/data1.json @mystage2;

-- Query the filename and row number metadata columns 
-- and the regular data columns in the staged file
SELECT METADATA$FILENAME, METADATA$FILE_ROW_NUMBER, parse_json($1) 
FROM @mystage2/data1.json.gz;

https://docs.snowflake.com/en/user-guide/querying-metadata.html#example-2-querying-the-metadata-columns-for-a-json-file

于 2020-04-03T13:02:15.553 回答