Closed8

snowflake タスク周り

yuucuyuucu

■ 用語メモ

  • ETL
    • Extract(抽出) Transform(変換) Load(書き出し)
    • さまざまなデータを利用しやすい形に変えて保管する工程
yuucuyuucu

バッチ処理的な、定期的なレポートの作成に役立ちそう

yuucuyuucu

タスクのリソースの種類

  • サーバーレス(snowflake管理)
    • ※プレビュー機能
    • 繰り返し使っているといい感じなサイズにしてくれるらしい
  • 仮装ウェアハウス(ユーザ管理)
yuucuyuucu

タスクのスケジュール周り

  • タスク作成時(CREATETASK を使用)または後(ALTER TASK を使用)でスケジュールが作れる
    • 特定の時間に1つだけ実行される(つまり、1つのタスクの実行時間が長いと、次のタスクはスキップされる)
yuucuyuucu

手動によるタスク実行

  • EXECUTE TASK
    • まだプレビュー機能
yuucuyuucu

create or replace database sample_db;

show databases;

create or replace table sample_table (
    id string,
    value string
);

show tables;

truncate sample_table;
insert into sample_table values (1, 10), (2, 10), (3, 10);
select * from sample_table;

// タスク作る (今回は適当にselectするだけ)
create or replace task sample_serverless_task
    schedule = '1 minute'
    as
        select * from sample_table;
    
// タスクの確認 (state=suspended)
show tasks;

// 手動実行
EXECUTE TASK sample_serverless_task;

// デフォルトのstateはsuspendedらしいので開始する
ALTER TASK sample_serverless_task RESUME;


// 1時間以内の直近10件のタスク履歴見るやつ
select *
  from table(information_schema.task_history(
    scheduled_time_range_start=>dateadd('hour',-1,current_timestamp()),
    result_limit => 10,
    task_name=>'sample_serverless_task'));
   
// 停止    
ALTER TASK sample_serverless_task SUSPEND;

yuucuyuucu

サマリーテーブルを作るようにちょっと変えてみる

create or replace table sample_summary_table (
    count int,
    insert_date date
);

show tables;

// タスク作る (rowの数と入れた時間を別テーブルに入れてみる)
create or replace task sample_serverless_task
    schedule = '1 minute'
    as
        insert into sample_summary_table
            select row_count, current_date() 
                from (
                    select count(1) as row_count from sample_table
                )
;
yuucuyuucu

途中でinsertしてみたりして、1分経つとサマリーテーブルいい感じにできてそう

このスクラップは2023/09/10にクローズされました