Skip to main content

Snowflake の Load History と Copy History の違い

data

Snowflake におけるデータロードの追跡は、データの健全性とパフォーマンスを維持するために非常に重要です。Load History と Copy History は、過去のデータロードに関する貴重な情報を提供してくれる機能です。これらの機能を理解することで、トラブルシューティング、監査、パフォーマンス分析などを効率的に行うことができます。

Snowflake で Load History を使っても Copy History を使ってもテーブルにロードされた過去のデータの履歴を取得できますが。

何が違うでしょうか。いつどっちを使った方が良いでしょうか。

Load History と Copy History の7違いさ

違いさ1: ビュー vs テーブル関数

Load History はビューです。
Copy History と言うテーブル関数ビューもあります。

Load History の使う方の例:

USE DATABASE db_1;

SELECT table_name, last_load_time
  FROM information_schema.load_history
  WHERE schema_name=current_schema() AND
  table_name='TABLE_1';

Copy History ビュー:

select file_name, table_name, last_load_time
from snowflake.account_usage.copy_history
order by last_load_time desc
limit 10;

Copy History テーブル関数:

select *
from table(
    information_schema.copy_history(
       TABLE_NAME=>'TABLE_1',
       START_TIME=> DATEADD(hours, -1, CURRENT_TIMESTAMP())
      )
    )
;

違いさ2: アクセス権限

Copy History テーブル関数は普通の関数です。
Copy History ビューは Account Usage ビューを使用します。
Load History ビュー Information Schema ビューを使用します。

と言うは:
Load History ビューを使うに Copy History テーブル関数使うよりもっと権限が必要です。
Copy History ビューを使うには Load History ビューを使うよりもっと高く権限が必要です。

違いさ 3: Snowpipe を使用してロードされたデータの履歴

Load History ビューは、Snowpipe を使用してロードされたデータの履歴を返しません。
Copy History テーブル関数もビューも Snowpipe を使用してロードされたデータの履歴を返します。

違いさ 4: 返される行の上限

Load History ビューは, 10,000 行の上限を返します。
Copy History テーブル関数もビューもこの上限がないです。

違いさ 5: 過去履歴の上限

Load History ビューと Copy History テーブル関数はテーブルにロードされた過去 14 日間以内のデータの履歴を取得できるようになります。
Copy History ビューは過去 365 日(1 年)の Snowflake データロード履歴をクエリできます。

違いさ 6: レイテンシー

Copy History ビューは多くの場合、ビューの遅延は最大 120 分(2 時間)です。状態によって最大 2 日になることもあります。

違いさ 7: クエリーの結果

Copy history テーブル関数を使う時に、必ずテーブル名を指定しないといけないです。
と言うのは、Copy history テーブル関数は一つのテーブルだけにロードされた過去のデータの履歴を取得できます。

例:

select *
from table(
    information_schema.copy_history(
      TABLE_NAME=>'TABLE_1',
      START_TIME=> DATEADD(hours, -1, CURRENT_TIMESTAMP())
      )
    )
;

Load History ビューと Copy history ビューの場合ではテーブル名を指定するのはオプショナルでは。
例: database_a データベースに対して実行された 10 個の最新の COPY INTO コマンドのレコードを取得します。

USE DATABASE database_a;

SELECT table_name, last_load_time
  FROM information_schema.load_history
  ORDER BY last_load_time DESC
  LIMIT 10;

Comments

Popular posts from this blog

Introduction to SQLFluff: How to make your SQL code clean and error-free

Image by Jake Aldridge from Pixabay You know oftentimes, the cause of runtime or compile errors and hours of debugging agony is all due to simply a missing semicolon. Have you ever had such experience? If you had, you are not alone. There are two ways to avoid these unfortunate situations: either become a perfect developer who never makes mistakes, or use helpful tools such as linters that can catch these errors early on. I am nowhere near being a perfect developer who never makes a mistake. In fact, I'm probably the opposite of a perfect developer, so even if I wanted to, I wouldn’t be able to teach you how to become a perfect developer. But what I can teach you is using linters. A Wikipedia defines a linter as a "static code analysis tool used to flag programming errors, bugs, stylistic errors and suspicious constructs." If you're not convinced yet on using linters, consider this scenario: in a large project with multiple members, different people tend to ...

WinMerge のセットアップと使う方

WinMerge は、Windows 用のオープン ソースの差分およびマージ ツールです。WinMerge は、フォルダーとファイルの両方を比較し、違いを理解して扱いやすい視覚的なテキスト形式で表示します。この記事でWinMerge のセットアップと使う方を教えます。 source: https://winmerge.org WinMerge をダウンロード WinMerge のウェブサイト に行って、「WinMerge-2.16.44-x64-Setup.exe」ボタンを押し、WinMerge 2.16 をダウンロードしてください。 WinMerge をインストール ダウンロードされたソフトウェアをクリックし、ポップアップ画面で「Next」を押してください 「Languages」部分をスクロールダウンし、「Japanese menus and dialogs」を選択し、「Next」ボタンを押してください ターミナル等からも WinMerge をアクセス出来ようにする為に「Add WinMerge folder to your system path」オプションを選択し、希望によって他のオプション選択してください 「Enable Explorer context menu Integration」オプションを選択したら、フォルダ/ファイルを右キリックし、コンテクストメニューから WinMerge を開くようになります。 「Install」ボタンを押し、「Next」ボタンを押し、その後、「Finish」ボタンを押してください 言語を日本語にする もし WinMerge の言語が日本語じゃなくて、英語なら、「Edit」タブから「Options」を押してください。 ポップアップ画面で右側の下にある「Languages」と言うドロップダウンメニューから日本語を選択し、「OK」ボタンを押してください WinMerge を使う方 「ファイル」タッブから「開く」を押し 参照ボタンを押し、比較したいフォルダ・ファイルを指定 比較したいフォルダを指定する方法: ポップアップ画面から対象のフォルダーを選択し、「Open」を押してくだい 何も選択しないで、「Open」を押してくだい 右側下にある「比較」ボタンを押し ...

Git squash merge explained

There are many ways to integrate changes in git: regular / normal git merge, git squash merge, git rebase etc. This article explains git squash merge by comparing it to regular merge. Let’s use below example: In the repository with default main branch, after two commits, a new feature branch is created. Some work happened in feature branch. feature branch now has 2 commits that it shares with main branch, and three exclusive commits (exists only in feature branch). In the meantime, others worked on main branch and added two new commits (exists only in main branch). git log output of the main branch: c72d4a9 ( HEAD - > main ) fourth commit on main 2c3dd61 third commit on main 0c2eec3 second commit on main 9b968e8 first commit on main git log output of the feature branch: 786650f ( HEAD - > feature ) third commit on feature 21cbaf1 second commit on feature 677bc7f first commit on feature 0c2eec3 second commit on main 9b968e8 first commit on mai...