Background是一个简单的pyspark程序,我是在1.6上使用databricks csv读/写开发的,所有人都很高兴。我的数据框有一个时间戳列,以标准YYYY-MM-DD HH24:MI:SS
格式写出。
foo,bar,2016-10-14 14:30:31.985
现在我在使用Spark 2的EMR上运行它,时间戳列被写为纪元,以微秒为单位。这会导致问题,因为目标(Redshift)无法原生处理此问题(仅秒或毫秒)。
foo,bar,1476455559456000
查看the docs,似乎我应该可以指定timestampFormat
使用的格式,但我只是收到错误:
TypeError: csv() got an unexpected keyword argument 'timestampFormat'
我是说错了,还是选项不存在?以任何其他方式干净地将我的时间戳数据以不微秒的格式输出(毫无疑问,毫无疑问,或任何其他标准时间格式)
重现的简单代码:
df = sqlContext.createDataFrame([('foo','bar')]).withColumn('foo',pyspark.sql.functions.current_timestamp())
df.printSchema()
df.show()
# Use the new Spark 2 native method
df.write.csv(path='/tmp/foo',mode='overwrite')
# Use the databricks CSV method, pre Spark 2
df.write.save(path='/tmp/foo2',format='com.databricks.spark.csv',mode='overwrite')
答案 0 :(得分:0)
原来我看到的文档是2.0.1,而我是在2.0.0上运行 - timestampFormat
是2.0.1中的新内容。