sparksql HiveHBaseTableOutputFormat cannot be cast to HiveOutputFormat

mtj66 2016-09-22 10:29:24
工作中发现sparksql 在向hive的hbase外表插入数据的时候报错问题:
HiveHBaseTableOutputFormat cannot be cast to org.apache.hadoop.hive.ql.io.HiveOutputFormat .
采用ALTER TABLE tablename SET TBLPEOPERTIES ('OutputFormat'='HiveOutputFormat' )是不行的。
不知道大侠有没有什么处理办法。
这是第一种方法,已经被列为bug。
https://issues.apache.org/jira/browse/SPARK-6628
方案二 ,目前采用的是分批次往hbase中put数据,是可行的。
方案三,采用saveAsNewAPIHadoopDataset处理 ,先前试过也会报错。
不过为了使结果尽量接近sql,尽量是采用方案一比较合理。
方案三也是可以接收的,但是还是要验证具体可行才行。
...全文
1980 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
batsom 2018-10-25
  • 打赏
  • 举报
回复
能免费提供下载不?
futhead 2018-08-14
  • 打赏
  • 举报
回复
https://blog.csdn.net/fuhtead/article/details/81635326,打了个补丁,自己基于branch2.1编译了个版本,亲测可用
pucheung 2017-08-08
  • 打赏
  • 举报
回复
这个问题用什么方法解决的呢
mtj66 2016-09-23
  • 打赏
  • 举报
回复
目前使用的代码示例: val locus_df = hiveContext.sql("select concat(obd_id,'_',adjust_time) as obd_id,from_unixtime(cast(start_time as int)) as start_time, " + " from_unixtime(cast(end_time as int)) as end_time, from_unixtime(cast(adjust_time as int)) gps_time, longitude,latitude,cast(speed as string) " + " from locus ") locus_for_app_df.mapPartitions { rowList => { val tableName = "obd_locus:locus_for_app" val myConf = HBaseConfiguration.create() myConf.set("hbase.zookeeper.quorum", "10.172.10.168,10.172.10.169,10.172.10.170") myConf.set("hbase.zookeeper.property.clientPort", "2181") myConf.set("hbase.defaults.for.version.skip", "true") val myTable = new HTable(myConf, TableName.valueOf(tableName)) myTable.setAutoFlush(false, false) //关键点1 myTable.setWriteBufferSize(3 * 1024 * 1024) //关键点2 rowList.foreach { row => { val p = new Put(Bytes.toBytes(row.getAs[String]("obd_id") )) //为put操作指定 column 和 value (以前的 put.add 方法被弃用了) // p.addColumn("f1".getBytes, "obd_id".getBytes, Bytes.toBytes(row.getAs[String]("obd_id"))) p.addColumn("f1".getBytes, "start_time".getBytes, Bytes.toBytes(row.getAs[String]("start_time"))) p.addColumn("f1".getBytes, "end_time".getBytes, Bytes.toBytes(row.getAs[String]("end_time"))) p.addColumn("f1".getBytes, "gps_time".getBytes, Bytes.toBytes(row.getAs[String]("gps_time"))) p.addColumn("f1".getBytes, "longitude".getBytes, Bytes.toBytes(row.getAs[String]("longitude"))) p.addColumn("f1".getBytes, "latitude".getBytes, Bytes.toBytes(row.getAs[String]("latitude"))) p.addColumn("f1".getBytes, "speed".getBytes, Bytes.toBytes(row.getAs[String]("speed"))) myTable.put(p) } } logger.error("------------------- flush to hbase now ---------------- rowList.size " + rowList.size) myTable.flushCommits() //关键点3 } rowList }.count()
LinkSe7en 2016-09-23
  • 打赏
  • 举报
回复
我们都是用方案二的 ds.foreachPartition()

2,208

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 其他数据库
社区管理员
  • 其他数据库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧