2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

BigQueryでスキーマの自動検出をする

Posted at

概要

データパイプライン用のファイルのストレージをGoogle Cloudに構築するケース。JSONファイルをサポートする必要があって、JSONファイルのスキーマが変更される可能性があり、集計実行用の ANSI SQL クエリを使用する場合は、スキーマの自動検出を行うとよい(らしい)。

仕組み

サンプルを抽出し、そこから推定を行っている。

自動検出を有効にすると、BigQuery はデータソース内でランダムにファイルを選択します。ファイルの最大 100 行をスキャンして代表的なサンプルとして使用し、推定プロセスを開始します。BigQuery は、各フィールドを検証し、そのサンプル内の値に基づいてそのフィールドにデータ型を割り当てようとします。

設定

新旧UIで設定項目が異なる。

GCP Console: [スキーマ] セクションの [自動検出] で、[スキーマと入力パラメータ] オプションをオンにします。
従来の BigQuery ウェブ UI: [Schema] セクションで、[Automatically detect] オプションをオンにします。

懸念

ファイルをランダムに選択するのと、ファイルの最大100行のスキャンなので、実際に業務で利用する場合はこれに頼らず、明示的に指定するか、スキーマのデータが確実にそのデータ型の場合のみ自動検出を使ったほうがよさそう。

参考

スキーマの自動検出の使用
https://cloud.google.com/bigquery/docs/schema-detect?hl=ja

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?