14
votes

I am trying to save a DataFrame to S3 in pyspark in Spark1.4 using DataFrameWriter

df = sqlContext.read.format("json").load("s3a://somefile")
df_writer = pyspark.sql.DataFrameWriter(df)
df_writer.partitionBy('col1')\
         .saveAsTable('test_table', format='parquet', mode='overwrite')

The parquet files went to "/tmp/hive/warehouse/...." which is a local tmp directory on my driver.

I did setup hive.metastore.warehouse.dir in hive-site.xml to a "s3a://...." location, but spark doesn't seem to respect to my hive warehouse setting.

2
It saves the file path with the "column name = " like s3a://bucket/foo/col1=1/,s3a://bucket/foo/col1=2/,s3a://bucket/foo/col1=3/,..... Is there any way to avoid appending the column name? like s3a://bucket/foo/1/,s3a://bucket/foo/2/ - androboy

2 Answers

35
votes

Use path.

df_writer.partitionBy('col1')\
         .saveAsTable('test_table', format='parquet', mode='overwrite',
                      path='s3a://bucket/foo')
0
votes

you can use insertInto(tablename) to overwrite a existing table since 1.4