spark向hbase写入数据,用spark-submit提交程序报错
spark吧
全部回复
仅看楼主
level 2
L光阴荏苒 楼主
求各位大佬帮忙解决
object SparkWriteHBase {
def main(args: Array[String]): Unit = {
val sparkConf = new SparkConf().setAppName("SparkWriteHBase").setMaster("local[2]")
val sc = new SparkContext(sparkConf)
val tablename = "student"
sc.hadoopConfiguration.set(TableOutputFormat.OUTPUT_TABLE, tablename)
val job = new Job(sc.hadoopConfiguration)
job.setOutputKeyClass(classOf[ImmutableBytesWritable])
job.setOutputValueClass(classOf[Result])
job.setOutputFormatClass(classOf[TableOutputFormat[ImmutableBytesWritable]])
val indataRDD = sc.makeRDD(Array("3,Rongcheng,M,26","4,Guanhua,M,27")) //构建两行记录
val rdd = indataRDD.map(_.split(',')).map{arr=>{
val put = new Put(Bytes.toBytes(arr(0))) //行健的值
put.add(Bytes.toBytes("info"),Bytes.toBytes("name"),Bytes.toBytes(arr(1))) //info:name列的值
put.add(Bytes.toBytes("info"),Bytes.toBytes("gender"),Bytes.toBytes(arr(2))) //info:gender列的值
put.add(Bytes.toBytes("info"),Bytes.toBytes("age"),Bytes.toBytes(arr(3).toInt)) //info:age列的值
(new ImmutableBytesWritable, put)
}}
rdd.saveAsNewAPIHadoopDataset(job.getConfiguration())
}
}
2019年04月06日 06点04分 1
level 2
请问可以用JAVA编写spark程序来写数据进hbase吗
2019年04月12日 06点04分 2
好像不行吧,目前我只知道python和scala可以
2019年04月17日 05点04分
都可以
2019年05月24日 12点05分
level 2
我最近也在做这个,但是scala不咋懂
2019年04月12日 06点04分 3
哦哦,我已经解决了
2019年04月17日 05点04分
怎么解决的
2020年05月11日 02点05分
level 9
堆栈信息没全,应该是实例返回null的问题
2019年05月01日 16点05分 4
1