cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue in renaming the table

Rajasaiharish
New Contributor

We have tried to rename a table

Ex: alter rename tablea to tableb

while we checked the table b properties we are seeing the tableb location is being pointed to tablea location.

2 ACCEPTED SOLUTIONS

Accepted Solutions

szymon_dybczak
Esteemed Contributor III

Hi @Rajasaiharish ,

Just like @Khaja_Zaffer  correctly suggested - renaming table doesn't change its location. If you want to change location as well use following command:

 

ALTER TABLE table_name SET LOCATION path_to_the_new_location

 

 

View solution in original post

K_Anudeep
Databricks Employee
Databricks Employee

Hello @Rajasaiharish ,

The above is expected by design.ALTER TABLE RENAME TO updates only the table name in the catalog.The underlying Delta log + data files remain in the original storage location

 

Try setting the location to a new location 

ALTER TABLE table_name SET LOCATION path_to_the_new_location

 or drop and recreate or run a CRTAS as a solution

View solution in original post

6 REPLIES 6

Khaja_Zaffer
Contributor

Hello @Rajasaiharish 

Thats expected behaviour 

so if you run DESCRIBE EXTENDED tableb; you might see that it could point the same location as tablea. 

 

we are just renaming not changing the location right?

 

In general in CDP environment,we just rename the table and underlying location also gets changed 

Hi @Rajasaiharish !
Yes, that's correct! In hive/CDP (HMS word) rename operation (ALTER TABLE RENAME) automatically renames the directory in HDFS to match because Hive Metastore directly controls both the metadata and the storage path.

But in Databricks, UC separates logical metadata (catalogue/schema/table) from physical storage.

 

szymon_dybczak
Esteemed Contributor III

Hi @Rajasaiharish ,

Just like @Khaja_Zaffer  correctly suggested - renaming table doesn't change its location. If you want to change location as well use following command:

 

ALTER TABLE table_name SET LOCATION path_to_the_new_location

 

 

K_Anudeep
Databricks Employee
Databricks Employee

Hello @Rajasaiharish ,

The above is expected by design.ALTER TABLE RENAME TO updates only the table name in the catalog.The underlying Delta log + data files remain in the original storage location

 

Try setting the location to a new location 

ALTER TABLE table_name SET LOCATION path_to_the_new_location

 or drop and recreate or run a CRTAS as a solution

So after step alter table a to table b we need to run alter table table name set location ? And we did not faced this in our cdp environment 

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now