6
votes

I want to store Spark dataframe into Hive table in normal readable text format. For doing so I first did

sqlContext.sql("SET spark.sql.hive.convertMetastoreParquet=false")

My DataFrame is like:

final_data1_df = sqlContext.sql("select a, b from final_data")

and I am trying to write it by:

final_data1_df.write.partitionBy("b").mode("overwrite").saveAsTable("eefe_lstr3.final_data1")

but this is very slow, even slower than HIVE table write. So to resolve this I thought to define partition through Hive DDL statement and then load data like:

sqlContext.sql("""
CREATE TABLE IF NOT EXISTS eefe_lstr3.final_data1(
a BIGINT
)
PARTITIONED BY (b INT)
"""
)
sqlContext.sql("""
INSERT OVERWRITE TABLE eefe_lstr3.final_data1 PARTITION (stategroup)
select * from final_data1""")

but this is giving partitioned Hive table but still parquet formatted data. Am I missing something here?

1
What is the exact error message you are getting? Also, are you sure that your sqlContext = HiveContext(sc) ? - KartikKannapur
yes my sqlContext is in fact HiveContext. I am not getting any error. In first case writing is slow. In second case data is still parquet. - abhiieor
you got any solution for this by now? - Ram Ghadiyaram
No. I was trying this but eventually due to deadlines pressures moved back to map only architecture from Spark. - abhiieor

1 Answers

-1
votes

When you create the table explicitly then that DDL defines the table. Normally text file is the default in Hive but it could have been changed in your environment.

Add "STORED AS TEXTFILE" at the end of the CREATE statement to make sure the table is plain text.