0

I am getting the error:

Cannot create table ('hive_metastore.MY_SCHEMA.MY_TABLE'). The associated location ('dbfs:/user/hive/warehouse/my_schema.db/my_table') is not empty and also not a Delta table.

I tried to overcome this by running

drop table 'hive_metastore`.`MY_SCHEMA`.`MY_TABLE`

But then I am getting

[TABLE_OR_VIEW_NOT_FOUND] The table or view hive_metastore.MY_SCHEMA.MY_TABLE cannot be found. Verify the spelling and correctness of the schema and catalog.

How Can I overcome that and recreate the table the that name in that location? I already tried create of *replace* table but still getting the original error location is not empty

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
Gilo
  • 640
  • 3
  • 23

1 Answers1

1

If the table exists, you can drop it using the following command:

DROP TABLE IF EXISTS hive_metastore.MY_SCHEMA.MY_TABLE;

If the table does not exist, you can create it using the following command:

CREATE TABLE hive_metastore.MY_SCHEMA.MY_TABLE () USING DELTA LOCATION 'dbfs:/user/hive/warehouse/my_schema.db/my_table';

If you still get the same error, you can delete the contents of the location associated with the table using the following command:

dbutils.fs.rm('dbfs:/user/hive/warehouse/my_schema.db/my_table', True)

After deleting the contents of the location, you can try to create the table again using the above command.

Please see the below threads for your reference.

Databricks - is not empty but it's not a Delta table

https://community.databricks.com/t5/data-engineering/error-the-associated-location-is-not-empty-but-it-s-not-a-delta/m-p/7430#M3314