テーブル名の一覧表示Listing table names
この記事で spark.catalog.listTables()
は、とのパフォーマンス特性が異なる理由について説明し %sql show tables
ます。This article explains why spark.catalog.listTables()
and %sql show tables
have different performance characteristics.
問題Problem
Metastore からすべてのテーブル名を取得するには、 spark.catalog.listTables()
またはを使用でき %sql show tables
ます。To fetch all the table names from metastore you can use either spark.catalog.listTables()
or %sql show tables
.
詳細を取得するのに時間がかかっている場合は、 spark.catalog.listTables()
通常よりも時間がかかり %sql show tables
ます。If you observe the duration to fetch the details you can see spark.catalog.listTables()
usually takes longer than %sql show tables
.
原因Cause
spark.catalog.listTables()
は、最初にすべてのテーブルのメタデータをフェッチし、次に要求されたテーブル名を表示しようとします。spark.catalog.listTables()
tries to fetch every table’s metadata first and then show the requested table names. 複雑なスキーマや多数のテーブルを処理する場合、このプロセスは遅くなります。This process is slow when dealing with complex schemas and larger numbers of tables.
解決策Solution
テーブル名だけを取得するには、 %sql show tables
テーブル名のみをフェッチする内部で呼び出すを使用し SessionCatalog.listTables
ます。To get only the table names, use %sql show tables
which internally invokes SessionCatalog.listTables
which fetches only the table names.