雪花过程由于任务执行而失败

时间:2020-04-03 05:10:52

标签: snowflake-cloud-data-platform snowflake-task

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

存储过程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'';
';

1 个答案:

答案 0 :(得分:0)

请尝试将$1替换为PARSE_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