카테고리:

시스템 함수 (시스템 정보)

SYSTEM$SET_RETURN_VALUE

작업의 반환 값을 명시적으로 설정합니다.

작업의 DAG 에서 작업은 이 함수를 호출하여 반환 값을 설정할 수 있습니다. 이 작업을 선행 작업으로 식별하는 다른 작업(작업 정의에서 AFTER 키워드 사용)은 SYSTEM$GET_PREDECESSOR_RETURN_VALUE 를 사용해 선행 작업이 설정한 반환 값을 검색할 수 있습니다.

구문

SYSTEM$SET_RETURN_VALUE( '<string_expression>' )
Copy

인자

string_expression

반환 값으로 설정할 문자열입니다. 문자열 크기는 10kB 이하여야 합니다(UTF8로 인코딩 시).

반환 값을 설정하는 작업을 만듭니다. 선행 작업이 완료된 후 실행되는 두 번째 하위 작업을 만듭니다. 하위 작업은 (SYSTEM$GET_PREDECESSOR_RETURN_VALUE 호출을 통해) 선행 작업에서 설정한 반환 값을 검색하여 테이블 행에 삽입합니다.

-- create a table to store the return values.
create or replace table return_values (str varchar);

-- create a task that sets the return value for the task.
create task set_return_value
  warehouse=return_task_wh
  schedule='1 minute' as
  call system$set_return_value('The quick brown fox jumps over the lazy dog');

-- create a task that identifies the first task as the predecessor task and retrieves the return value set for that task.
create task get_return_value
  warehouse=return_task_wh
  after set_return_value
  as
    insert into return_values values(system$get_predecessor_return_value());


-- Note that if there are multiple predecessor tasks that are enabled, you must specify the name of the task to retrieve the return value for that task.
create task get_return_value_by_pred
  warehouse=return_task_wh
  after set_return_value
  as
    insert into return_values values(system$get_predecessor_return_value('SET_RETURN_VALUE'));

-- resume task (using ALTER TASK ... RESUME).
-- wait for task to run on schedule.

select distinct(str) from return_values;
+-----------------------------------------------+
|                      STR                      |
+-----------------------------------------------+
|  The quick brown fox jumps over the lazy dog  |
+-----------------------------------------------+

select distinct(RETURN_VALUE)
  from table(information_schema.task_history())
  where RETURN_VALUE is not NULL;

+-----------------------------------------------+
|                  RETURN_VALUE                 |
+-----------------------------------------------+
|  The quick brown fox jumps over the lazy dog  |
+-----------------------------------------------+
Copy

첫 번째 예와 유사하지만, 작업에 대한 반환 값을 설정하고 별도의 저장 프로시저를 호출하여 검색합니다.

-- create a table to store the return values.
create or replace table return_values_sp (str varchar);

-- create a stored procedure that sets the return value for the task.
create or replace procedure set_return_value_sp()
returns string
language javascript
execute as caller
as $$
  var stmt = snowflake.createStatement({sqlText:`call system$set_return_value('The quick brown fox jumps over the lazy dog');`});
  var res = stmt.execute();
$$;

-- create a stored procedure that inserts the return value for the predecessor task into the 'return_values_sp' table.
create or replace procedure get_return_value_sp()
returns string
language javascript
execute as caller
as $$
var stmt = snowflake.createStatement({sqlText:`insert into return_values_sp values(system$get_predecessor_return_value());`});
var res = stmt.execute();
$$;

-- create a task that calls the set_return_value stored procedure.
create task set_return_value_t
warehouse=warehouse1
schedule='1 minute'
as
  call set_return_value_sp();

-- create a task that calls the get_return_value stored procedure.
create task get_return_value_t
warehouse=warehouse1
after set_return_value_t
as
  call get_return_value_sp();

-- resume task.
-- wait for task to run on schedule.

select distinct(str) from return_values_sp;
+-----------------------------------------------+
|                      STR                      |
+-----------------------------------------------+
|  The quick brown fox jumps over the lazy dog  |
+-----------------------------------------------+

select distinct(RETURN_VALUE)
  from table(information_schema.task_history())
  where RETURN_VALUE is not NULL;

+-----------------------------------------------+
|                  RETURN_VALUE                 |
+-----------------------------------------------+
|  The quick brown fox jumps over the lazy dog  |
+-----------------------------------------------+
Copy