Forum Discussion

KimTutein's avatar
KimTutein
Icon for Advocate IV rankAdvocate IV
1 year ago
Solved

"ALTER TABLE RENAME TO" does not work with tables in upper casee

Hi Community   I think I have discovered a bug in the ALTER TABLE RENAME TO command.  It does not seem to be able to handle capital letters when the spark property “spark.sql.caseSensitive” is sat ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi KimTutein ,

     

    I can reproduce your error, running the command will, despite successfully renaming the table name to another uppercase table name, also create an unidentified folder, and when querying the data it will report an error saying that the current table doesn't exist.

     

    This issue may be related to Delta Lake's behavior when dealing with uppercase table names. Specifically, the way Delta Lake handles table names can lead to inconsistent metadata in some cases, especially when the spark.sql.caseSensitive property is set to true.

     

    To rename an uppercase table name to another uppercase table name, you can manually copy the data from the old table to the new table, make sure the data is written correctly in the new table, and then delete the old table. This method avoids the problems that can result from using the ALTER TABLE RENAME TO command.

     

    The steps are as follows:

    First, create a table named in uppercase letters and insert data.

     

    Next, use the following command to rename and delete the original table.

    # read original table
    df = spark.sql(“SELECT * FROM A_TEST”)
    # create new table
    df.write.format(“delta”).mode(“overwrite”).saveAsTable(“A_TEST_RENAME_1”)
    # drop table
    spark.sql(“DROP TABLE IF EXISTS A_TEST”)

     

    As you can see, it runs fine. Finally, perform a query on the data.

    %%sql
    SELECT * FROM A_TEST_RENAME_1

     

    If you have any other questions please feel free to contact me.

     

    Best Regards,
    Yang
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!