我在使用spark scala连接Hbase时得到了这个“java.lang.NumberFormatException.forInputString(Unknown Source)”的预期

时间:2016-09-29 06:46:26

标签: scala apache-spark hbase

我正在使用spark scala阅读Hbase表。

代码如下:

package HBase

import org.apache.hadoop.hbase.client.{HBaseAdmin, Result}
import org.apache.hadoop.hbase.{ HBaseConfiguration, HTableDescriptor }
import org.apache.hadoop.hbase.mapreduce.TableInputFormat
import org.apache.hadoop.hbase.io.ImmutableBytesWritable
import it.nerdammer.spark.hbase._
import org.apache.spark._

object Connector  {

    def main(args: Array[String]) {  

    val sparkConf = new        SparkConf().setAppName("HBaseApp").setMaster("local[2]")
    val sc = new SparkContext(sparkConf)
    val conf = HBaseConfiguration.create()
    val tableName = "cars"

    conf.set("hbase.master", "10.163.12.87")
    conf.setInt("timeout", 40000)
    conf.set("hbase.zookeeper.quorum", "10.163.12.87")
    conf.set("zookeeper.znode.parent", "/hbase-unsecure")
   conf.set(TableInputFormat.INPUT_TABLE, tableName)

    val admin = new HBaseAdmin(conf)
    if (!admin.isTableAvailable(tableName)) {
      val tableDesc = new HTableDescriptor(tableName)
      admin.createTable(tableDesc)
    }

    val hBaseRDD = sc.newAPIHadoopRDD(conf, classOf[TableInputFormat],      classOf[ImmutableBytesWritable], classOf[Result])
    println("Number of Records found : " + hBaseRDD.count())
    sc.stop()
     }
 }

我收到以下错误:

线程“main”中的异常java.lang.NumberFormatException:对于输入字符串:“16000 I PBUF HDP1.Node1}ڞ*

at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at org.apache.hadoop.hbase.HServerAddress.<init>(HServerAddress.java:63)
at org.apache.hadoop.hbase.MasterAddressTracker.getMasterAddress(MasterAddressTracker.java:63)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getMaster(HConnectionManager.java:353)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:89)
at HBase.Connector$.main(Connector.scala:32)
at HBase.Connector.main(Connector.scala)

1 个答案:

答案 0 :(得分:0)

尝试在hbase.master配置中设置端口号。

conf.set("hbase.master", "10.163.12.87:60000")