Error: HIVE_PATH_ALREADY_EXISTS: Target directory for table
Author: Omid Vahdaty 11.2.2019
I got this error while working in Athena.
The good News- CTAS in Athena exist.
The bad news- the error messages still require some work to make them human readable….
"HIVE_PATH_ALREADY_EXISTS: Target directory for table 'sampledb.ctas_json_partitioned' already exists: s3://myBucket/."
In order to run the CTAS command in Athena, it is always preferable to use an explicit location. If you don’t specify the explicit location, Athena uses this location by default :
For example, if we are running following CTAS query with location ‘s3://mybucket/my_ctas_table/’:
CREATE my_ctas_table WITH ( external_location = 's3://mybucket/my_ctas_table/' ) AS SELECT ...
In this example, we’d first want to make sure the location (exists !) and is empty.
To check the location, use the CLI command:
aws s3 ls s3://aws-athena-query-results-783591744239-eu-west-1/Unsaved/2019/02/03/tables/ --recursive
I put a lot of thoughts into these blogs, so I could share the information in a clear and useful way.
If you have any comments, thoughts, questions, or you need someone to consult with,/
feel free to contact me via LinkedIn: