web-dev-qa-db-ja.com

1つのテーブルのBigQueryストレージサイズを取得する方法

Google Big Query Storageのテーブルごとのコストを計算したいのですが、各テーブルのストレージのサイズを個別に表示する方法がわかりません。

16
selva kumar

またはGUIから、メタデータ内部テーブル__TABLES__を使用できます。たとえば、GB単位のサイズが得られます。

select 
  sum(size_bytes)/pow(10,9) as size
from
  <your_dataset>.__TABLES__
where 
  table_id = '<your_table>'
34
Quentin

これを行うにはいくつかの方法がありますが、ストリーミング挿入をアクティブに受信しているテーブルでは、バイト単位のテーブルプロパティのサイズを使用できないことに注意してください。

A. [〜#〜] bq [〜#〜] コマンドラインツール、および [〜#〜] jq [〜#〜] を使用して解析するLinuxライブラリJSON。

_bq --format=json show publicdata:samples.gsod | jq '.numBytes | tonumber'
_

このアウトパス:

_17290009238
_

B. REST apiを使用して Tables:get を呼び出す

_GET https://www.googleapis.com/bigquery/v2/projects/projectId/datasets/datasetId/tables/tableId
_

これにより、完全なJSONが返され、解析してnumBytesを取得できます。

_{
    "kind": "bigquery#table",
    "description": "This dataset contains weather information collected by NOAA, such a…",
    "creationTime": "1335916040125",
    "tableReference": {
        "projectId": "publicdata",
        "tableId": "gsod",
        "datasetId": "samples"
    },
    "numRows": "114420316",
    "numBytes": "17290009238",
    "etag": "\"Gn3Hpo5WaKnpFuT457VBDNMgZBw/MTQxMzkzNzk4Nzg0Ng\"",
    "location": "US",
    "lastModifiedTime": "1413937987846",
    "type": "TABLE",
    "id": "publicdata:samples.gsod",
    "selfLink": "https://www.googleapis.com/bigquery/v2/projects/publicdata/datasets…",
    "schema": {
        "fields": [
            {
                "description": "The World Meteorological Organization (WMO) / DATSAV3 station numbe…",
                "type": "INTEGER",
                "name": "station_number",
                "mode": "REQUIRED"
            },
            {
                "description": "The Weather-Bureau-Army-Navy (WBAN) station number where the data w…",
                "type": "INTEGER",
                "name": "wban_number",
                "mode": "NULLABLE"
            },
            {
                "description": "The year the data was collected in",
                "type": "INTEGER",
                "name": "year",
                "mode": "REQUIRED"
            },
            {
                "description": "The month the data was collected in",
                "type": "INTEGER",
                "name": "month",
                "mode": "REQUIRED"
            },
            {
                "description": "The day the data was collected in.",
                "type": "INTEGER",
                "name": "day",
                "mode": "REQUIRED"
            },
            {
                "description": "The mean temperature of the day in degrees Fahrenheit, accurate to …",
                "type": "FLOAT",
                "name": "mean_temp",
                "mode": "NULLABLE"
            },
            {
                "description": "The number of observations used to calculate mean_temp.",
                "type": "INTEGER",
                "name": "num_mean_temp_samples",
                "mode": "NULLABLE"
            },
            {
                "description": "The mean dew point of the day in degrees Fahrenheit, accurate to on…",
                "type": "FLOAT",
                "name": "mean_dew_point",
                "mode": "NULLABLE"
            },
            {
                "description": "The number of observations used to calculate mean_dew_point.",
                "type": "INTEGER",
                "name": "num_mean_dew_point_samples",
                "mode": "NULLABLE"
            },
            {
                "description": "The mean sea level pressure of the day in millibars, accurate to on…",
                "type": "FLOAT",
                "name": "mean_sealevel_pressure",
                "mode": "NULLABLE"
            },
            {
                "description": "The number of observations used to calculate mean_sealevel_pressure…",
                "type": "INTEGER",
                "name": "num_mean_sealevel_pressure_samples",
                "mode": "NULLABLE"
            },
            {
                "description": "The mean station pressure of the day in millibars, accurate to one …",
                "type": "FLOAT",
                "name": "mean_station_pressure",
                "mode": "NULLABLE"
            },
            {
                "description": "The number of observations used to calculate mean_station_pressure.…",
                "type": "INTEGER",
                "name": "num_mean_station_pressure_samples",
                "mode": "NULLABLE"
            },
            {
                "description": "The mean visibility of the day in miles, accurate to one tenth of a…",
                "type": "FLOAT",
                "name": "mean_visibility",
                "mode": "NULLABLE"
            },
            {
                "description": "The number of observations used to calculate mean_visibility.",
                "type": "INTEGER",
                "name": "num_mean_visibility_samples",
                "mode": "NULLABLE"
            },
            {
                "description": "The mean wind speed of the day in knots, accurate to one tenth of a…",
                "type": "FLOAT",
                "name": "mean_wind_speed",
                "mode": "NULLABLE"
            },
            {
                "description": "The number of observations used to calculate mean_wind_speed.",
                "type": "INTEGER",
                "name": "num_mean_wind_speed_samples",
                "mode": "NULLABLE"
            },
            {
                "description": "The maximum sustained wind speed reported on the day in knots, accu…",
                "type": "FLOAT",
                "name": "max_sustained_wind_speed",
                "mode": "NULLABLE"
            },
            {
                "description": "The maximum wind gust speed reported on the day in knots, accurate …",
                "type": "FLOAT",
                "name": "max_gust_wind_speed",
                "mode": "NULLABLE"
            },
            {
                "description": "The maximum temperature of the day in degrees Fahrenheit, accurate …",
                "type": "FLOAT",
                "name": "max_temperature",
                "mode": "NULLABLE"
            },
            {
                "description": "Indicates the source of max_temperature.",
                "type": "BOOLEAN",
                "name": "max_temperature_explicit",
                "mode": "NULLABLE"
            },
            {
                "description": "The minimum temperature of the day in degrees Fahrenheit, accurate …",
                "type": "FLOAT",
                "name": "min_temperature",
                "mode": "NULLABLE"
            },
            {
                "description": "Indicates the source of min_temperature.",
                "type": "BOOLEAN",
                "name": "min_temperature_explicit",
                "mode": "NULLABLE"
            },
            {
                "description": "The total precipitation of the day in inches, accurate to one hundr…",
                "type": "FLOAT",
                "name": "total_precipitation",
                "mode": "NULLABLE"
            },
            {
                "description": "The snow depth of the day in inches, accurate to one tenth of an in…",
                "type": "FLOAT",
                "name": "snow_depth",
                "mode": "NULLABLE"
            },
            {
                "description": "Indicates if fog was reported on this day.",
                "type": "BOOLEAN",
                "name": "fog",
                "mode": "NULLABLE"
            },
            {
                "description": "Indicates if rain was reported on this day.",
                "type": "BOOLEAN",
                "name": "rain",
                "mode": "NULLABLE"
            },
            {
                "description": "Indicates if snow was reported on this day.",
                "type": "BOOLEAN",
                "name": "snow",
                "mode": "NULLABLE"
            },
            {
                "description": "Indicates if hail was reported on this day.",
                "type": "BOOLEAN",
                "name": "hail",
                "mode": "NULLABLE"
            },
            {
                "description": "Indicates if thunder was reported on this day.",
                "type": "BOOLEAN",
                "name": "thunder",
                "mode": "NULLABLE"
            },
            {
                "description": "Indicates if a tornado was reported on this day.",
                "type": "BOOLEAN",
                "name": "tornado",
                "mode": "NULLABLE"
            }
        ]
    }
}
_

C. ___TABLES___および___TABLES_SUMMARY___というメタテーブルがあります。

次のようなクエリを実行できます。

_SELECT size_bytes FROM <dataset>.__TABLES__ WHERE table_id='mytablename'
_

そのクエリの___TABLES___の部分は見慣れないものに見えるかもしれません。 ___TABLES_SUMMARY___は、データセット内のテーブルに関する情報を含むメタテーブルです。このメタテーブルは自分で使用できます。たとえば、クエリ_SELECT * FROM publicdata:samples.__TABLES_SUMMARY___は、_publicdata:samples_データセット内のテーブルに関するメタデータを返します。 _SELECT * FROM publicdata:samples.__TABLES___も実行できます

利用可能なフィールド:

___TABLES_SUMMARY___メタテーブルのフィールド(これらはすべて_TABLE_QUERY_クエリで使用できます)には次のものがあります。

  • _table_id_:テーブルの名前。
  • _creation_time_:テーブルが作成された時刻(1970年1月1日からのミリ秒単位)。これは、テーブルの_creation_time_フィールドと同じです。
  • type:ビュー(2)か通常のテーブル(1)か。

次のフィールドは___TABLES___のメンバーですが___TABLES_SUMMARY___のメンバーではないため、TABLE_QUERY()ではnotを使用できません。これらは、歴史的な関心と___TABLES___メタテーブルを部分的に文書化するためにここに保持されます。

  • _last_modified_time_:テーブルが更新された時間(UTC/1/1970 UTCからのミリ秒単位)(メタデータまたはテーブルコンテンツのいずれか)。 tabledata.insertAll()を使用してレコードをテーブルにストリーミングする場合、これは数分古くなる可能性があることに注意してください。
  • _row_count_:テーブルの行数。
  • _size_bytes_:テーブルの合計サイズ(バイト単位)。
11
Pentium10

あなたはコマンドラインツールでこれを行うことができます

bq show ds_name.table_name

「Total Bytes」など、テーブル全体の情報が表示されます。ここで参照 https://cloud.google.com/bigquery/bq-command-line-tool

6
user1692732

コマンドラインツールを使用するだけです。 Last-Modified、Schema、Total Rows、Total Bytesなどの列を持つテーブルが表示されます。

  1. シングルテーブル用

bq show dataset_name.table_name

  1. すべてのテーブル

bq show dataset_name.*

1
Aniket Ghole