Raghav
Raghav

Reputation: 2238

spark hbase connector - Exception "java.lang.UnsupportedOperationException: empty.tail"

We are on HDP 2.4.2, with spark 1.6 compiled with Scala 2.10.5. Hbase is version 1.1.2.2.4.2.0-258

The environment is a basic dev cluster (<10 nodes) with hbase & spark running in cluster mode.

Attempts to use spark hbase connector for getting soem data from hbase into a data frame in spark are failing with the following error -

Exception in thread "main" java.lang.UnsupportedOperationException: empty.tail
    at scala.collection.TraversableLike$class.tail(TraversableLike.scala:445)
    at scala.collection.mutable.ArraySeq.scala$collection$IndexedSeqOptimized$super$tail(ArraySeq.scala:45)
    at scala.collection.IndexedSeqOptimized$class.tail(IndexedSeqOptimized.scala:123)
    at scala.collection.mutable.ArraySeq.tail(ArraySeq.scala:45)
    at org.apache.spark.sql.execution.datasources.hbase.HBaseTableCatalog.initRowKey(HBaseTableCatalog.scala:150)
    at org.apache.spark.sql.execution.datasources.hbase.HBaseTableCatalog.<init>(HBaseTableCatalog.scala:164)
    at org.apache.spark.sql.execution.datasources.hbase.HBaseTableCatalog$.apply(HBaseTableCatalog.scala:239)
    at hbaseReaderHDPCon$.main(hbaseReaderHDPCon.scala:42)
    at hbaseReaderHDPCon.main(hbaseReaderHDPCon.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$runMain(SparkSubmit.scala:731)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

At line 42 in my code - this is happening -

val cat =
      s"""{
          |"table":{"namespace":"myTable", "name":"person", "tableCoder":"PrimitiveType"},
          |"rowkey":"ROW",
          |"columns":{
            |"col0":{"cf":"person", "col":"detail", "type":"string"}
          |}
          |}""".stripMargin
    val scon = new SparkConf()
    val sparkContext = new SparkContext(scon)

Upvotes: 4

Views: 2631

Answers (1)

L. CWI
L. CWI

Reputation: 962

Given your code, I think the field "columns" in your catalog is missing the rowkey. Below an exemple which works for me. I'm using Spark 2.0 (SparkSession) but it should work with Spark 1.6 :

    val catalog =
        s"""{
            |"table":{"namespace":"default", "name":"person"},
            |"rowkey":"id",
            |"columns":{
            |"id":{"cf":"rowkey", "col":"id", "type":"string"},
            |"name":{"cf":"info", "col":"name", "type":"string"},
            |"age":{"cf":"info", "col":"age", "type":"string"}
            |}
            |}""".stripMargin

    val spark = SparkSession
        .builder()
        .appName("HbaseWriteTest")
        .getOrCreate()

    val df = spark
        .read
        .options(
            Map(
                HBaseTableCatalog.tableCatalog -> catalog
            )
        )
        .format("org.apache.spark.sql.execution.datasources.hbase")
        .load()

Upvotes: 6

Related Questions