####遇到一个问题。
spark sql dataset 写入表的时候,我写的是一个用ymd分区的表,我想设置输出格式format(“hive”),然后报错了
代码如下
ds.write().partitionBy(partitionsStr)
.option("path", hdfspath)
.mode(SaveMode.Append).format("hive")
.saveAsTable( newtable);*/
查询了一些资料,得到的结论是
- ds这块partitionBy是得到的dataframe的分区,而不是hive的分区
###所以,想到的解决方案是
先建表,再去写数据
###这种方案又遇到一个问题
我想通过 create external table newtable like oldtable location "hdfs://xxxx"的方式去建立
但是spark sql并不支持external这个关键字
###后面处理的方式是
- 通过jdbc连接hive的方式去执行create external table newtable like oldtable location "hdfs://xxxx"
- ds.write().option("path", hdfspath)
.mode(SaveMode.Append)
.insertInto( newtable);