Appearance
カタログの検索
cdm catalog サブコマンドのうち、カタログ情報を検索・一覧するコマンドです。
cdm catalog <subcommand> [options]| サブコマンド | 用途 |
|---|---|
catalog search-tables | カタログに登録されたテーブルを検索 |
catalog list-schemas | カタログに登録されたスキーマ一覧を取得 |
catalog tag list | カタログ用のタグ一覧を取得 |
カタログへの書き込みコマンドについては、アノテーションの管理とタグの管理 を参照してください。
テーブルの検索
cdm catalog search-tables [options]
-q, --query <text> 検索キーワード(省略可。複数語はクオートで囲む)
-c, --connection-id <id> 検索対象のコネクション ID(複数指定可)
-f, --format <fmt> 出力形式: text | json(既定: text)
--compact テーブルごとのカラムを省略し、1行に要約して一覧(text のみ)
-d, --database <id> データベース ID で絞り込み(複数指定可)
-s, --schema <id> スキーマ ID で絞り込み(複数指定可)
--schema-uri <uri> スキーマ URI で絞り込み(複数指定可)
--starred スター付きテーブルのみに絞り込み
--type <type> テーブル種別で絞り込み(複数指定可・[下記](#catalog-search-tables-type))
--tag <name> タグ名で絞り込み(複数指定可)
--tag-id <id> タグIDで絞り込み(複数指定可)
--limit <n> 取得件数(1–100、省略時 20)
--offset <n> スキップ件数(省略時 0)
--sort <order> 並び順([下記](#catalog-search-tables-sort)のいずれか)
--profile <name> 利用する profile を指定カタログに登録されたテーブルを検索します。
- コネクション ID は
cdm connection listで確認できます - カタログに登録されているテーブルのみが検索対象になります
- コネクションからアクセス可能なテーブルであっても、カタログに登録されていないテーブルは検索対象になりません
- タグ名やタグIDは
cdm catalog tag listで確認できます- 複数指定した場合はAND条件で絞り込みます
--tagで指定したタグ名が、テーブル用(type:table)とカラム用(type:column)のどちらにも該当する場合、タグ名ではどちらを指すか特定できないためエラーとなります。その場合は--tag-idを使ってください。
schemaUriはcdm catalog list-schemasで確認できます--schemaはスキーマ ID(schemaId)での絞り込み、--schema-uriはschemaUriでの絞り込みです
- 閲覧権限が付与されているコネクションのみが検索対象になります
- 閲覧権限を持たないコネクションのIDを検索対象に指定した場合、エラーになります
検索キーワード(--query)
- 空白区切りの複数語は AND(例:
"users summary"は両方にマッチするテーブル) |で OR グループを指定(例:"users|orders")- 検索語は最大 100 文字
--queryを省略した場合は、フィルタ条件に合致するテーブルを--limit件ずつ取得します(既定 20 件。続きはhas_nextと--offsetでページング)
並び順(--sort)
--sort には次のいずれかを指定します。
| 指定値 | 意味 |
|---|---|
score(--query あり時のデフォルト) | キーワードとの関連度順 |
path(--query なし時のデフォルト) | カタログ上の位置順(昇順) |
path-desc | カタログ上の位置順(降順) |
rows | 行数降順 |
rows-asc | 行数昇順 |
popularity | 利用頻度順 |
テーブル種別(--type)
--type には次のいずれかを指定します(複数指定可)。
table, view, external, materializedView, snapshot, temporary, event, externalShallowClone, foreign, managedShallowClone, metricView, streamingTable
出力形式
text(既定)
テーブルごとに、種別・テーブル名・schemaUri・行数・タグを並べた見出し行と、テーブルの説明、そのテーブルのカラム一覧を出力します。末尾に件数のサマリを表示します。
$ cdm catalog search-tables -q user_daily
(table) user_daily_summary bq:my-project/analytics rows=482,000 tags=[Mart]
日次のユーザー行動サマリ(分析・レポート用)
Column Type Tags Description
user_id STRING [Not null]
summary_date DATE [Not null]
session_count INT64 当日のセッション数
(view) order_daily_summary bq:my-project/analytics rows=120,000
日次の注文サマリ
Column Type Tags Description
order_id STRING
ordered_at DATE
2 tables found- 続きがある場合は、サマリに
(more available, use --offset)を表示します - 各テーブルにはタグ名のみを表示します。タグの定義詳細は
--format jsonで確認してください
--compact を指定すると、各テーブルのカラムを省略し、1テーブル1行の表として一覧します。テーブルの一覧を俯瞰する用途に利用します。
$ cdm catalog search-tables -q summary --compact
Type TableId SchemaUri RowCount Tags Description
table user_daily_summary bq:my-project/analytics 482,000 [Mart] 日次のユーザー行動サマリ(分析・レポート用)
view order_daily_summary bq:my-project/analytics 120,000 日次の注文サマリ
2 tables foundjson
結果は次の形式の JSON です。
tables: テーブル配列referencedTags: タグの定義詳細(検索結果に含まれるタグのみが対象。0件の場合は省略)has_next: 続きがある場合true(--limit/--offsetでページング)
json
{
"tables": [
{
"type": "table",
"schemaUri": "bq:my-project/analytics",
"databaseId": "analytics",
"schemaId": "mart",
"tableId": "user_daily_summary",
"rowCount": 482000,
"description": "日次のユーザー行動サマリ(分析・レポート用)",
"tags": ["Mart"],
"columns": [
{ "name": "user_id", "type": "STRING", "tags": ["Not null"] },
{ "name": "summary_date", "type": "DATE", "tags": ["Not null"] },
{ "name": "session_count", "type": "INT64", "description": "当日のセッション数" }
]
}
],
"referencedTags": [
{
"id": "673cd14b0d08cf6c657df7dc",
"type": "column",
"name": "Not null",
"description": "This column is not null.",
"isSystem": true
},
{
"id": "672ab14b0d08cf6c657df7db",
"type": "table",
"name": "Mart",
"description": "Curated table for analysis and reporting"
}
],
"has_next": false
}利用例
bash
# 基本検索(text でカラムまで確認)
cdm catalog search-tables -q user_daily
# カラムを省略して一覧を俯瞰
cdm catalog search-tables -q summary --compact
# 複数キーワード(AND)
cdm catalog search-tables --query "user daily"
# OR 検索
cdm catalog search-tables -q "user_daily|order_daily"
# コネクション+スキーマ絞り込み
cdm catalog search-tables -q summary -c 671ef14b0d08cf6c657df7da -s mart
# schemaUri で絞り込み
cdm catalog search-tables -q summary --schema-uri bq:my-project/analytics -c 671ef14b0d08cf6c657df7da
# タグ名で絞り込み
cdm catalog search-tables --tag Mart
# タグIDで絞り込み
cdm catalog search-tables --tag-id 672ab14b0d08cf6c657df7db
# クエリなしで一覧(パス順・ページングは --limit / --offset)
cdm catalog search-tables -c 671ef14b0d08cf6c657df7da --sort path
# スター付きテーブル一覧
cdm catalog search-tables --starred -c 671ef14b0d08cf6c657df7da --sort path
# スクリプト用に JSON 出力
cdm catalog search-tables -q user_daily -f json | jq '.tables[].tableId'
# ページング
cdm catalog search-tables -q user_daily --limit 50 --offset 50スキーマ一覧
cdm catalog list-schemas [options]
-c, --connection-id <id> 対象のコネクション ID(複数指定可)
-f, --format <fmt> 出力形式: text | json(既定: text)
--profile <name> 利用する profile を指定カタログに登録されているスキーマ(database > schema > table の中間階層。BigQuery の dataset、Snowflake の schema などに相当)の一覧を取得します。
- コネクション ID は
cdm connection listで確認できます - 閲覧権限が付与されているコネクションのみが対象です
- 閲覧権限を持たないコネクションの ID を指定した場合、エラーになります
出力形式
text(既定)
$ cdm catalog list-schemas -c 671ef14b0d08cf6c657df7da
SchemaUri DatabaseId SchemaId Tables
bq:my-project/analytics my-project analytics 42
bq:my-project/raw my-project raw 18json
json
{
"schemas": [
{
"schemaUri": "bq:my-project/analytics",
"databaseId": "my-project",
"schemaId": "analytics",
"tableCount": 42
}
]
}利用例
bash
# コネクション配下のスキーマ一覧
cdm catalog list-schemas -c 671ef14b0d08cf6c657df7da
# スクリプト用に JSON 出力
cdm catalog list-schemas -c 671ef14b0d08cf6c657df7da -f jsonタグ一覧
cdm catalog tag list
-f, --format <fmt> 出力形式: text | json(既定: text)
--profile <name> 利用する profile を指定ワークスペースに登録されているテーブル用(type:table)とカラム用(type:column)のタグ一覧を取得します。
isSystemがtrueのタグは、システムで管理されているタグで、削除・名前変更ができません- 閲覧権限を持つコネクションが1つ以上必要です
出力形式
text(既定)
$ cdm catalog tag list
Id Name Type Color IsSystem Description
673cd14b0d08cf6c657df7dc Not null column #71767E yes This column is not null.
672ab14b0d08cf6c657df7db Mart table #666CFF no Curated table for analysis
and reporting- Description 列は切り捨てず折り返します。本文中の改行は
\nと表示します
json
json
{
"tags": [
{
"id": "673cd14b0d08cf6c657df7dc",
"type": "column",
"name": "Not null",
"color": "#71767E",
"description": "This column is not null.",
"isSystem": true
},
{
"id": "672ab14b0d08cf6c657df7db",
"type": "table",
"name": "Mart",
"color": "#666CFF",
"description": "Curated table for analysis and reporting",
"isSystem": false
}
]
}利用例
bash
# タグ一覧を取得
cdm catalog tag list
# スクリプト用に JSON 出力
cdm catalog tag list -f json | jq '.tags[] | select(.type == "table")'タグの作成・更新は タグの管理 を参照してください。