1
votes

I am following spark hbase connector basic example to read a HBase table in spark2 shell version 2.2.0. It looks like the code is working, but when I run df.show() command, I do not see any results and it seems to run forever.

import org.apache.spark.sql.{ DataFrame, Row, SQLContext }
import org.apache.spark.sql.execution.datasources.hbase._

val sqlContext = new org.apache.spark.sql.SQLContext(sc); 

def catalog = s"""{
         |"table":{"namespace":"default", "name":"testmeta"},
         |"rowkey":"vgil",
         |"columns":{
            |"id":{"cf":"rowkey", "col":"vgil", "type":"string"},
           |"col1":{"cf":"pp", "col":"dtyp", "type":"string"}
         |}
       |}""".stripMargin


def withCatalog(cat: String): DataFrame = { sqlContext.read.options(Map(HBaseTableCatalog.tableCatalog->cat)).format("org.apache.spark.sql.execution.datasources.hbase").load()}

val df = withCatalog(catalog)

df.show()

df.show() will neither give any output nor any error. It will keep on running forever.

Also, how can I run queryy for range of row keys.

Here is the scan of the HBase test table.

hbase(main):001:0> scan 'testmeta'
ROW                                 COLUMN+CELL                                                                                            
 fmix                            column=pp:dtyp, timestamp=1541714925380, value=ss1                                                     
 fmix                            column=pp:lati, timestamp=1541714925371, value=41.50                                                   
 fmix                            column=pp:long, timestamp=1541714925374, value=-81.61                                                  
 fmix                            column=pp:modm, timestamp=1541714925377, value=ABC                                                                                                   
 vgil                            column=pp:dtyp, timestamp=1541714925405, value=ss2                                                     
 vgil                            column=pp:lati, timestamp=1541714925397, value=41.50                                                   

I have followed some of solutions on the web, but unfortunately not able to get the data from HBase.

Thanks in advance for help!

1

1 Answers

1
votes

Posting my answer after lots of trial, so I found that adding --conf option to start spark shell helped me connect to HBase.

spark2-shell --master yarn --deploy-mode client --packages com.hortonworks:shc-core:1.1.1-2.1-s_2.11,it.nerdammer.bigdata:spark-hbase-connector_2.10:1.0.3 --repositories http://repo.hortonworks.com/content/groups/public/ --conf spark.hbase.host=192.168.xxx.xxx --files /mnt/fs1/opt/cloudera/parcels/CDH-5.13.0-1.cdh5.13.0.p0.29/share/doc/hbase-solr-doc-1.5+cdh5.13.0+71/demo/hbase-site.xml

Then the following code snippet could fetch a value for one column qualifier.

val hBaseRDD_iacp = sc.hbaseTable[(String)]("testmeta").select("lati").inColumnFamily("pp").withStartRow("vg").withStopRow("vgz")      
object myschema {
      val column1 = StructField("column1",  StringType)
      val struct = StructType(Array(column1))
    }


val rowRDD = hBaseRDD.map(x => Row(x))
val myDf = sqlContext.createDataFrame(rowRDD,myschema.struct)  
myDf.show()