Unable to rename an external location in Azure ADLS for existing tables

We have an ETL pipeline with landing, bronze, silver layer tables. The data is stored in Azure ADLS containers as external tables. The pipeline is running on daily basis, and data is stored in the desired location.

But now we found that the external location directory name is incorrect and this need to be renamed without impacting the daily pipelines, and downstream data access for these tables.

I found some references about ALTER EXTERNAL LOCATIONS, etc. but when I try it with some assumptions since am not sure this COMMAND NEED TO BE RUN after renaming the folder in ADLS container or should this be done later.

Also am getting errors “AnalysisException: /mnt/bronze/user_data is not a Delta table.” when i try the command. Can someone please explain the steps to follow so that the external location can be renamed, and also apply to all the tables referencing to older location.

I am providing herewith reproducible code for testing please.

  1. Create a directory in a ADLS container with name “users_info”

  2. Create a databricks notebook, and have a mount point created for this location, say “/mnt/bronze/users_info”

  3. Create a database : user_master

  4. Create a table with following code:

    %sql
    CREATE TABLE user_master.user
    (
    id INT,
    name STRING,
    age INT
    )
    USING DELTA
    LOCATION ‘/mnt/bronze/users_info/user’;

  5. Insert few sample records:

    %sql
    insert into user_master.user values(1, ‘James’, 25)
    insert into user_master.user values(2, ‘Rechard’, 25)

  6. Verify its external location path by running the command describe extended user_master.user”

  7. Now try to rename the external location as follows:

ALTER TABLE hive_metastore.user_master.user SET LOCATION ‘/mnt/bronze/user_data’;

If I try to rename the folder in ADLS container before running this command, then we get table not found error.

APPRECIATE ANY help, to rename the ADLS container/folder path and also rename path external locations of existing tables, without any impact.

6

I have tried the below and I received same ERROR like you:

ALTER TABLE hive_metastore.default.b02 SET LOCATION '/mnt/raw/new02/dds.csv';
[DELTA_MISSING_DELTA_TABLE] `/mnt/raw/new02/dds.csv` is not a Delta table. SQLSTATE: 42P01

As the ERROR message says the created external table is not Delta table.
I have tried the below approach creating a Delta table:

path = "/mnt/raw02/dilip/external_delta_table"
df.write.format("delta").save(path)
spark.sql(f"""
CREATE TABLE hive_metastore.default.b02
USING DELTA
LOCATION '{path}'
""")
spark.sql("""
INSERT INTO hive_metastore.default.b02
VALUES (4,"jaya shankar")
""")

In the above code specifying the path in ADLS where you want to save the Delta table
Writing the DataFrame out in the Delta format to create an external Delta table
Creating an external table pointing to this Delta table
Creating a new directory with the desired name in ADLS.
Using the Databricks filesystem utilities (dbutils.fs.cp) to copy the data from the old directory to the new one.
After copying the data, update the Delta table’s location to point to the new directory. This can be done using the ALTER TABLE SQL command.

Results:

df = spark.read.format("delta").option("header", "true").option("inferSchema", "true").load("/mnt/raw02/dilip/external_delta_table")
display(df)
ID  Name
1   dilip
2   raj
3   Narayan
4   jaya shankar

As you mentioned you want to rename an external location in ADLS for existing tables.

The below is the approach:

dbutils.fs.cp("/mnt/raw02/dilip/external_delta_table", "/mnt/raw02/dilip/new_external_delta_table", recurse=True)
spark.sql("""
ALTER TABLE hive_metastore.default.b02
SET LOCATION '/mnt/raw02/dilip/new_external_delta_table'
""")

Results:

spark.sql("DESCRIBE DETAIL hive_metastore.default.b02").display(truncate=False)

You can also use the below command to delete the old directory.

dbutils.fs.rm("/mnt/raw02/dilip/external_delta_table", recurse=True)

You can also refer ALTER EXTERNAL LOCATION

Recognized by Microsoft Azure Collective

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật