分享

用spark写数据到hbase

remarkzhao 发表于 2017-7-19 14:20:15 [显示全部楼层] 只看大图 回帖奖励 阅读模式 关闭右栏 10 15397
本帖最后由 remarkzhao 于 2017-7-19 14:24 编辑

请问各位大神这是什么情况。。

从网上看了一个例子   用spark向hbase写数据  

抛出的异常:java.lang.IllegalArgumentException: Can not create a Path from a null string

用sbt打包的时候出现的warning:
[warn] there were four deprecation warnings; re-run with -deprecation for details
[warn] one warning found
[warn] Multiple main classes detected.  Run 'show discoveredMainClasses' to see the list  (我在里面写了2个scala,另一个scala能正常运行并已成功)

PS:hbase的student表能成功写入数据


我的环境: hadoop全分布集群  

                 hbase全分布集群

代码如下:

import org.apache.hadoop.hbase.HBaseConfiguration  import org.apache.hadoop.hbase.mapreduce.TableOutputFormat  import org.apache.spark._  import org.apache.hadoop.mapreduce.Job  import org.apache.hadoop.hbase.io.ImmutableBytesWritable  
import org.apache.hadoop.hbase.client.Result  import org.apache.hadoop.hbase.client.Put  
import org.apache.hadoop.hbase.util.Bytes  
object SparkWriteHBase {   
def main(args: Array[String]): Unit = {      
  val sparkConf = new SparkConf().setAppName("SparkWriteHBase").setMaster("local")      
  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)))        put.add(Bytes.toBytes("info"),Bytes.toBytes("gender"),Bytes.toBytes(arr(2)))              put.add(Bytes.toBytes("info"),Bytes.toBytes("age"),Bytes.toBytes(arr(3).toInt))       (new ImmutableBytesWritable, put)       }}            rdd.saveAsNewAPIHadoopDataset(job.getConfiguration())    }    }  

已有(10)人评论

跳转到指定楼层
starrycheng 发表于 2017-7-19 16:09:56
说的有点乱,每明白什么意思。好像错误,跟代码没有太大的关系。
java.lang.IllegalArgumentException: Can not create a Path from a null string

上面错误是关于路径的,也就是说想创建路径,但是路径为空,所以导致的异常。

回复

使用道具 举报

remarkzhao 发表于 2017-7-19 16:11:06
嗯嗯。。是的。数据写入hbase是成功的,可以查询的到。

但不知道这path是哪里的path
回复

使用道具 举报

remarkzhao 发表于 2017-7-19 16:13:01
starrycheng 发表于 2017-7-19 16:09
说的有点乱,每明白什么意思。好像错误,跟代码没有太大的关系。
java.lang.IllegalArgumentException: Ca ...

嗯嗯。。是的。数据写入hbase是成功的,可以查询的到。

但不知道这path是哪里的path
回复

使用道具 举报

starrycheng 发表于 2017-7-19 16:18:09
remarkzhao 发表于 2017-7-19 16:13
嗯嗯。。是的。数据写入hbase是成功的,可以查询的到。

但不知道这path是哪里的path

既然能成功,应该没有太大关系。
看看数据里面是否有空值的。
还有错误是出现在什么地方,最好有截图。
回复

使用道具 举报

remarkzhao 发表于 2017-7-19 16:22:32
HBASE里的数据存在且没问题。在代码里打了断点测试。在最后一行出现了问题。 微信图片_20170719162044.png
println("18")  这句没被执行到。。 看spark错误日志: 2.png


回复

使用道具 举报

starrycheng 发表于 2017-7-19 16:26:44
remarkzhao 发表于 2017-7-19 16:22
HBASE里的数据存在且没问题。在代码里打了断点测试。在最后一行出现了问题。
println("18")  这句没被执行 ...

是 spark on yarn,还是master slave模式
回复

使用道具 举报

nextuser 发表于 2017-7-19 16:28:56
remarkzhao 发表于 2017-7-19 16:22
HBASE里的数据存在且没问题。在代码里打了断点测试。在最后一行出现了问题。
println("18")  这句没被执行 ...

尝试加大excutor-memory的值,减少executor-cores的数量
回复

使用道具 举报

remarkzhao 发表于 2017-7-19 16:33:45
starrycheng 发表于 2017-7-19 16:26
是 spark on yarn,还是master slave模式

单机模式。就spark-shell 不带master跟yarn
回复

使用道具 举报

remarkzhao 发表于 2017-7-19 16:34:46
nextuser 发表于 2017-7-19 16:28
尝试加大excutor-memory的值,减少executor-cores的数量

好的。去试试。
回复

使用道具 举报

12下一页
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条