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: 

Unable to create a partitioned table on s3 data

Constantine
Contributor III

I write data to s3 like

data.write.format("delta").mode("append").option("mergeSchema", "true").save(s3_location)

and create a partitioned table like

CREATE TABLE IF NOT EXISTS demo_table
USING DELTA
PARTITIONED BY (column_a)
LOCATION {s3_location};

which throws an error

Error in SQL statement: AnalysisException: It is not allowed to specify partitioning when the table schema is not defined.

Is there a different way to write to s3 location so that I can solve this issue

1 ACCEPTED SOLUTION

Accepted Solutions

Hubert-Dudek
Esteemed Contributor III

@John Constantine​ , In CREATE TABLE, you need to specify fields:

CREATE TABLE IF NOT EXISTS demo_table
    (column_a STRING,
    number INT)
USING DELTA PARTITIONED BY
     (column_a)
LOCATION 
   {s3_location};

and when you save data before creating a table, it should include a partition. I think it better first register the table and then write to it.

View solution in original post

2 REPLIES 2

Hubert-Dudek
Esteemed Contributor III

@John Constantine​ , In CREATE TABLE, you need to specify fields:

CREATE TABLE IF NOT EXISTS demo_table
    (column_a STRING,
    number INT)
USING DELTA PARTITIONED BY
     (column_a)
LOCATION 
   {s3_location};

and when you save data before creating a table, it should include a partition. I think it better first register the table and then write to it.

Kaniz_Fatma
Community Manager
Community Manager

Hi @John Constantine​ , Did the above suggestions provided by @Hubert Dudek​ help your case?

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