🐷
Snowflake ロード履歴が見たい!!
ロード履歴が見たい!!安心してください。見れますよ。
今回はロード履歴について見ていきます。
LOAD HISTORYについて
ドキュメントより抜粋
このInformation Schemaビューにより、 COPY INTO <テーブル> コマンドを使用して、
テーブルにロードされた過去14日間以内のデータの履歴を取得できるようになります。
ビューには、ロードされたファイルごとに1行が表示されます。
動作確認
information_schema.load_historyの実行
まずは履歴が見たい対象のDBを指定します。
そのあと、information_schemaスキーマのload_historyをSELECTします。
USE COPY_DB;
SELECT * FROM information_schema.load_history
実行結果
SCHEMA_NAME | FILE_NAME | TABLE_NAME | LAST_LOAD_TIME | STATUS | ROW_COUNT | ROW_PARSED | FIRST_ERROR_MESSAGE | FIRST_ERROR_LINE_NUMBER | FIRST_ERROR_CHARACTER_POSITION | FIRST_ERROR_COL_NAME | ERROR_COUNT | ERROR_LIMIT |
---|---|---|---|---|---|---|---|---|---|---|---|---|
PUBLIC | s3://snowflakebucket-copyoption/size/Orders2.csv | ORDERS | 26:41.2 | LOADED | 1500 | 1500 | 0 | 1 | ||||
PUBLIC | s3://snowflakebucket-copyoption/size/Orders.csv | ORDERS | 26:41.2 | LOADED | 1500 | 1500 | 0 | 1 | ||||
PUBLIC | s3://snowflakebucket-copyoption/size/Orders.csv | ORDERS | 36:57.3 | LOADED | 1500 | 1500 | 0 | 1 | ||||
PUBLIC | s3://snowflakebucket-copyoption/size/Orders2.csv | ORDERS | 36:57.3 | LOADED | 1500 | 1500 | 0 | 1 |
すべてのDBで履歴を確認したい
上記の方法だと1つのDBの履歴しか確認できません。
これだと一々DBを切り替えないといけなく手間がかかります。
でも一気にすべてのDBで確認する方法があります。
SELECT * FROM snowflake.account_usage.load_history
実行結果
結構履歴行があったので省略しています。
TABLE_ID | TABLE_NAME | SCHEMA_ID | SCHEMA_NAME | CATALOG_ID | CATALOG_NAME | FILE_NAME | LAST_LOAD_TIME | STATUS | ROW_COUNT | ROW_PARSED | FIRST_ERROR_MESSAGE | FIRST_ERROR_LINE_NUMBER | FIRST_ERROR_CHARACTER_POSITION | FIRST_ERROR_COL_NAME | ERROR_COUNT | ERROR_LIMIT |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
38916 | ORDERS | 13 | PUBLIC | 12 | COPY_DB | s3://snowflakebucket-copyoption/returnfailed/OrderDetails_error2 - Copy.csv | 56:40.9 | PARTIALLY_LOADED | 283 | 285 | Numeric value '7-' is not recognized | 2 | 17 | ORDERS""[""QUANTITY"":4] | 2 | 285 |
38916 | ORDERS | 13 | PUBLIC | 12 | COPY_DB | s3://snowflakebucket-copyoption/returnfailed/OrderDetails_error.csv | 56:40.9 | PARTIALLY_LOADED | 1498 | 1500 | Numeric value 'one thousand' is not recognized | 2 | 14 | ORDERS""[""PROFIT"":3] | 2 | 1500 |
38916 | ORDERS | 13 | PUBLIC | 12 | COPY_DB | s3://snowflakebucket-copyoption/returnfailed/Orders.csv | 56:40.9 | LOADED | 1500 | 1500 | 1500 | |||||
38916 | ORDERS | 13 | PUBLIC | 12 | COPY_DB | s3://snowflakebucket-copyoption/returnfailed/Orders2.csv | 56:40.9 | LOADED | 1500 | 1500 | 1500 | |||||
38916 | ORDERS | 13 | PUBLIC | 12 | COPY_DB | s3://snowflakebucket-copyoption/returnfailed/OrderDetails_error2 - Copy.csv | 54:07.5 | PARTIALLY_LOADED | 283 | 285 | Numeric value '7-' is not recognized | 2 | 17 | ORDERS""[""QUANTITY"":4] | 2 | 285 |
38916 | ORDERS | 13 | PUBLIC | 12 | COPY_DB | s3://snowflakebucket-copyoption/returnfailed/Orders.csv | 54:07.5 | LOADED | 1500 | 1500 | 1500 | |||||
38916 | ORDERS | 13 | PUBLIC | 12 | COPY_DB | s3://snowflakebucket-copyoption/returnfailed/OrderDetails_error.csv | 54:07.5 | PARTIALLY_LOADED | 1498 | 1500 | Numeric value 'one thousand' is not recognized | 2 | 14 | ORDERS""[""PROFIT"":3] | 2 | 1500 |
38916 | ORDERS | 13 | PUBLIC | 12 | COPY_DB | s3://snowflakebucket-copyoption/returnfailed/Orders2.csv | 54:07.5 | LOADED | 1500 | 1500 | 1500 | |||||
16390 | CUSTOMERS | 2 | PUBLIC | 4 | OUR_FIRST_DB | s3://data-snowflake-fundamentals/time-travel/customers.csv | 37:40.5 | LOADED | 1000 | 1000 | 1000 | |||||
18436 | CUSTOMERS | 2 | PUBLIC | 4 | OUR_FIRST_DB | s3://data-snowflake-fundamentals/time-travel/customers.csv | 30:54.2 | LOADED | 1000 | 1000 | 1000 | |||||
21508 | ORDERS | 11 | PUBLIC | 10 | DATA_S | s3://bucketsnowflakes3/OrderDetails.csv | 23:19.2 | LOADED | 1500 | 1500 | 1500 | |||||
28674 | ORDERS_EX | 2 | PUBLIC | 4 | OUR_FIRST_DB | s3://bucketsnowflakes3/OrderDetails.csv | 58:12.6 | LOADED | 1500 | 1500 | 1500 | |||||
29700 | ORDERS_EX | 2 | PUBLIC | 4 | OUR_FIRST_DB | s3://bucketsnowflakes4/OrderDetails_error.csv | 50:57.1 | PARTIALLY_LOADED | 1498 | 1500 | Numeric value 'one thousand' is not recognized | 2 | 14 | ORDERS_EX""[""PROFIT"":3] | 2 | 1500 |
24578 | ORDERS | 2 | PUBLIC | 4 | OUR_FIRST_DB | s3://bucketsnowflakes3/OrderDetails.csv | 08:59.9 | LOADED | 1500 | 1500 | 1500 | |||||
32770 | ORDERS_EX | 2 | PUBLIC | 4 | OUR_FIRST_DB | s3://bucketsnowflakes3/OrderDetails.csv | 19:37.2 | LOADED | 1500 | 1500 | 1500 | |||||
24578 | ORDERS | 2 | PUBLIC | 4 | OUR_FIRST_DB | s3://bucketsnowflakes3/OrderDetails.csv | 11:29.8 | LOADED | 1500 | 1500 | 1500 | |||||
30722 | ORDERS_EX | 2 | PUBLIC | 4 | OUR_FIRST_DB | s3://bucketsnowflakes3/sampledata.csv | 41:59.5 | LOADED | 8 | 8 | 8 | |||||
27650 | ORDERS_EX | 2 | PUBLIC | 4 | OUR_FIRST_DB | s3://bucketsnowflakes3/OrderDetails.csv | 55:01.6 | LOADED | 1500 | 1500 | 1500 |
条件で履歴を絞りたい!
ケース1
where句でスキーマ名とテーブル名を指定してみる
SELECT * FROM snowflake.account_usage.load_history
where schema_name='PUBLIC' and
table_name='ORDERS'
ケース2
さらにerror_countが0以上を抽出する
SELECT * FROM snowflake.account_usage.load_history
where schema_name='PUBLIC' and
table_name='ORDERS' and
error_count > 0
ケース3
現在の時刻から1日前までの履歴を抽出する
で合ってると思います・・・
SELECT * FROM snowflake.account_usage.load_history
WHERE DATE(LAST_LOAD_TIME) <= DATEADD(days,-1,CURRENT_DATE)
以上、ロード履歴の動作確認でした。
Discussion