snowflake cloud data platform - use LIST inside Procedure OR AWAIT a task - Stack Overflow

I have some code that loads many files from AWS DMS endpoint, so the set of files is not known. So I cu

I have some code that loads many files from AWS DMS endpoint, so the set of files is not known. So I currently using the LIST command to enumerate all the files.

The code works from Snowsight, or a TASK, start shown here:

create or replace task REFRESH_ALL_PARQUET_TABLES
schedule='USING CRON 10 17 * * * UTC'
as DECLARE
  id_0 varchar;
BEGIN

  list @STAGE_NAME;
  id_0 := last_query_id();
...

but if I put it in a procedure, I get an error about LIST.

CREATE procedure REFRESH_ALL_PARQUET_TABLES_SP()
RETURNS VARCHAR
LANGUAGE SQL
EXECUTE AS OWNER
AS 
DECLARE
  id_0 varchar;
BEGIN

  list @STAGE_NAME;
  id_0 := last_query_id();

  return id_0;
END;
call REFRESH_ALL_PARQUET_TABLES_SP();

Uncaught exception of type 'STATEMENT_ERROR' on line 5 at position 2 : Stored procedure execution error: Unsupported statement type 'LIST_FILES'.

queryid: 01bae284-3204-2ea2-0001-ef8e01ec33f2

the Snowflake Scripting works:

DECLARE
  id_0 varchar;
BEGIN

  list @STAGE_NAME;
  id_0 := last_query_id();

  return id_0;
END;

anyways, I would like to know how to run LIST from a procedure, OR have a procedure AWAIT for a TASK, because I am doing my orchestration from a Task, that calls a procedure, that runs SQL from a table. And if I have to execute the task

execute task REFRESH_ALL_PARQUET_TABLES

I want to have the chain await it also. This is done so decencies occur in the correct order, AND because not all steps run on each time period, I was avoid task chains.

I have some code that loads many files from AWS DMS endpoint, so the set of files is not known. So I currently using the LIST command to enumerate all the files.

The code works from Snowsight, or a TASK, start shown here:

create or replace task REFRESH_ALL_PARQUET_TABLES
schedule='USING CRON 10 17 * * * UTC'
as DECLARE
  id_0 varchar;
BEGIN

  list @STAGE_NAME;
  id_0 := last_query_id();
...

but if I put it in a procedure, I get an error about LIST.

CREATE procedure REFRESH_ALL_PARQUET_TABLES_SP()
RETURNS VARCHAR
LANGUAGE SQL
EXECUTE AS OWNER
AS 
DECLARE
  id_0 varchar;
BEGIN

  list @STAGE_NAME;
  id_0 := last_query_id();

  return id_0;
END;
call REFRESH_ALL_PARQUET_TABLES_SP();

Uncaught exception of type 'STATEMENT_ERROR' on line 5 at position 2 : Stored procedure execution error: Unsupported statement type 'LIST_FILES'.

queryid: 01bae284-3204-2ea2-0001-ef8e01ec33f2

the Snowflake Scripting works:

DECLARE
  id_0 varchar;
BEGIN

  list @STAGE_NAME;
  id_0 := last_query_id();

  return id_0;
END;

anyways, I would like to know how to run LIST from a procedure, OR have a procedure AWAIT for a TASK, because I am doing my orchestration from a Task, that calls a procedure, that runs SQL from a table. And if I have to execute the task

execute task REFRESH_ALL_PARQUET_TABLES

I want to have the chain await it also. This is done so decencies occur in the correct order, AND because not all steps run on each time period, I was avoid task chains.

Share Improve this question asked Mar 9 at 4:28 Simeon PilgrimSimeon Pilgrim 26.2k3 gold badges36 silver badges50 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The error message indicates that this type of operation is not supported, though it works inside an anonymous block. IMO worth reporting to the support.

In the meantime you can consider using directory tables to list files inside a stage:

CREATE STAGE stage_name DIRECTORY = (ENABLE = TRUE);

CREATE OR REPLACE PROCEDURE REFRESH_ALL_PARQUET_TABLES_SP()
RETURNS VARCHAR
LANGUAGE SQL
EXECUTE AS OWNER
AS 
DECLARE
  id_0 varchar;
BEGIN
  ALTER STAGE stage_name REFRESH;
  SELECT * FROM DIRECTORY(@stage_name);
  id_0 := LAST_QUERY_ID();

  RETURN id_0;
END;


CALL REFRESH_ALL_PARQUET_TABLES_SP();
-- <query_id_here>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744878102a4598670.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信