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: 

Renamed table cannot be written to or deleted from

477061
Contributor

I have renamed a table, however on trying to write to it (or delete from it) I get the following error:

`java.io.FileNotFoundException: No such file or directory: s3a://.../hive/warehouse/testing.db/renamed_table_name/_delta_log/00000000000000000002.json`

My cluster version is 10.4 LTS

The following python snippet can be used to recreate the issue:

```

DB_NAME = 'testing'

def rename(old_table_name, new_table_name):

spark.conf.set("spark.databricks.delta.alterTable.rename.enabledOnAWS", "true")

spark.sql(f"ALTER TABLE {DB_NAME}.{old_table_name} RENAME TO {DB_NAME}.{new_table_name}")

def overwrite(table_name, source_df):

(source_df.write

.mode("overwrite")

.format("delta")

.saveAsTable(f"{DB_NAME}.{table_name}")

)

def get_df():

data = [

("Name1", "Surname1", 12345),

("Name2", "Surname2", 67890),

]

return spark.createDataFrame(data)

sparkDf = get_df()

# Create table

overwrite('table_name', sparkDf)

# Rename table

rename('table_name', 'renamed_table_name')

# Try to write to renamed table (or delete from). Failure happens here

overwrite('renamed_table_name', sparkDf)

```

Any help would be appreciated

1 ACCEPTED SOLUTION

Accepted Solutions

AmanSehgal
Honored Contributor III

I tried your code in 11.1 (includes Apache Spark 3.3.0, Scala 2.12) and it worked perfectly fine.

However it will work perfectly only the first time because if you try to rerun the same code, it'll error out stating renamed_table_name exists.

P.S: Please use code snippet(</> button) to include your code in your question

View solution in original post

3 REPLIES 3

AmanSehgal
Honored Contributor III

I tried your code in 11.1 (includes Apache Spark 3.3.0, Scala 2.12) and it worked perfectly fine.

However it will work perfectly only the first time because if you try to rerun the same code, it'll error out stating renamed_table_name exists.

P.S: Please use code snippet(</> button) to include your code in your question

Vidula
Honored Contributor

Hi @julie.holtzhausen​ 

Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help. 

We'd love to hear from you.

Thanks!

Noopur_Nigam
Databricks Employee
Databricks Employee

Hi @477061 Could you please try to test it in DBR 11.1 and see if the issue persists for you?

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group