Specified partition columns do not match the partition columns of the table.Please use () as the partition columns

jack AKA karthik picture jack AKA karthik · Jan 12, 2017 · Viewed 8.4k times · Source

here i'm trying to persist the data frame in to a partitioned hive table and getting this silly exception. I have looked in to it many times but not able to find the fault.

org.apache.spark.sql.AnalysisException: Specified partition columns (timestamp value) do not match the partition columns of the table. Please use () as the partition columns.;

Here is the script by which the external table is created with,

CREATE EXTERNAL TABLEIF NOT EXISTS events2 (
action string
,device_os_ver string
,device_type string
,event_name string
,item_name string
,lat DOUBLE
,lon DOUBLE
,memberid BIGINT
,productupccd BIGINT
,tenantid BIGINT
) partitioned BY (timestamp_val DATE) 
row format serde 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
stored AS inputformat 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
outputformat 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat' 
location 'maprfs:///location/of/events2' 
tblproperties ('serialization.null.format' = '');

Here is the result of describe formatted of table "events2"

hive> describe  formatted events2;
OK
# col_name              data_type               comment             

action                  string                                      
device_os_ver           string                                      
device_type             string                                      
event_name              string                                      
item_name               string                                      
lat                     double                                      
lon                     double                                      
memberid                bigint                                      
productupccd            bigint                                      
tenantid                bigint                                      

# Partition Information      
# col_name              data_type               comment             

timestamp_val           date                                        

# Detailed Table Information         
Database:               default                                  
CreateTime:             Wed Jan 11 16:58:55 IST 2017     
LastAccessTime:         UNKNOWN                  
Protect Mode:           None                     
Retention:              0                        
Location:               maprfs:/location/of/events2  
Table Type:             EXTERNAL_TABLE           
Table Parameters:        
    EXTERNAL                TRUE                
    serialization.null.format                       
    transient_lastDdlTime   1484134135          

# Storage Information        
SerDe Library:          org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe  
InputFormat:            org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat    
OutputFormat:           org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat   
Compressed:             No                       
Num Buckets:            -1                       
Bucket Columns:         []                       
Sort Columns:           []                       
Storage Desc Params:         
    serialization.format    1                   
Time taken: 0.078 seconds, Fetched: 42 row(s)

Here is the line of code where the data is partitioned and stored in to a table,

val tablepath = Map("path" -> "maprfs:///location/of/events2")

AppendDF.write.format("parquet").partitionBy("Timestamp_val").options(tablepath).mode(org.apache.spark.sql.SaveMode.Append).saveAsTable("events2")

While running the application, i'm getting the below

Specified partition columns (timestamp_val) do not match the partition columns of the table.Please use () as the partition columns.

I might be committing an obvious error, any help is much appreciated with an upvote :)

Answer

KiranM picture KiranM · Jan 12, 2017

Please print schema of df:

AppendDF.printSchema()

Make sure it is not type mismatch??