0
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?

Databricks にて Hadoop Catalog 管理下にある Apache Iceberg テーブルを DROP する方法

Posted at

概要

Databricks にて Hadoop Catalog 管理下にある Apache Iceberg テーブルに対して DROP TABLE 文を実行したところ下記のエラーが発生したため、対応方法を共有します。

AnalysisException: [TABLE_OR_VIEW_NOT_FOUND] The table or view spark_catalog.default.ICEBERG_TBL_5 cannot be found. Verify the spelling and correctness of the schema and catalog.
If you did not qualify the name with a schema, verify the current_schema() output, or qualify the name with the correct schema and catalog.
To tolerate the error on drop use DROP VIEW IF EXISTS or DROP TABLE IF EXISTS.

image.png

DROP 文が想定通りに動作していないようなので、テーブルのディレクトリを直接削除後に、テーブルの更新を実施することで対応しました。

# ディレクトリ、 Namespace、テーブル名を変数にセット
wh_dir = spark.conf.get("spark.sql.catalog.spark_catalog.warehouse")
namespace_name = "default"
table_name = "ICEBERG_TBL_5"

# テーブルのディレクトリごと削除
table_dir = f"{wh_dir}/{namespace_name}/{table_name}"
dbutils.fs.rm(table_dir, True)

# Hadoop Catalog を更新
spark.sql(f"REFRESH TABLE {namespace_name}.{table_name}")

image.png

エラーの再現方法

テーブル作成後にテーブルの存在確認を実施

%sql
CREATE TABLE ICEBERG_TBL_5(ID INT,NAME STRING) USING ICEBERG;
SHOW TABLES IN default;

image.png

DROP TABLE 文がエラーとなることを確認

%sql
DROP TABLE default.ICEBERG_TBL_5;

AnalysisException: [TABLE_OR_VIEW_NOT_FOUND] The table or view spark_catalog.default.ICEBERG_TBL_5 cannot be found. Verify the spelling and correctness of the schema and catalog.
If you did not qualify the name with a schema, verify the current_schema() output, or qualify the name with the correct schema and catalog.
To tolerate the error on drop use DROP VIEW IF EXISTS or DROP TABLE IF EXISTS.

image.png

DROP TABLE PURGE 文がエラーとなることを確認

%sql
DROP TABLE default.ICEBERG_TBL_5 PURGE;

AnalysisException: [TABLE_OR_VIEW_NOT_FOUND] The table or view spark_catalog.default.ICEBERG_TBL_5 cannot be found. Verify the spelling and correctness of the schema and catalog.
If you did not qualify the name with a schema, verify the current_schema() output, or qualify the name with the correct schema and catalog.
To tolerate the error on drop use DROP VIEW IF EXISTS or DROP TABLE IF EXISTS.

image.png

エラーへの対応方法

テーブルのディレクトリを削除してカタログを更新

# ディレクトリ、 Namespace、テーブル名を変数にセット
wh_dir = spark.conf.get("spark.sql.catalog.spark_catalog.warehouse")
namespace_name = "default"
table_name = "ICEBERG_TBL_5"

# テーブルのディレクトリごと削除
table_dir = f"{wh_dir}/{namespace_name}/{table_name}"
dbutils.fs.rm(table_dir, True)

# Hadoop Catalog を更新
spark.sql(f"REFRESH TABLE {namespace_name}.{table_name}")

image.png

テーブルがなくなったことを確認

%sql
SHOW TABLES IN default;

image.png

0
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
0
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?