2014-11-25 47 views
1

我有一個216列的表「Gazelle」,我想在javaPairRDD中獲得他們的一些列。 我一直在努力,請點擊此鏈接:使用火花閱讀hbase表

How to read from hbase using spark 這一個:how to fetch all of data from hbase table in spark

爲了導入我需要我添加了這種依賴關係到我的POM文件的jar文件:

'<?xml version="1.0" encoding="UTF-8"?> 

http://maven.apache.org/xsd/maven-4.0.0.xsd「> 4.0.0

<groupId>fr.aid.cim</groupId> 
<artifactId>spark-poc</artifactId> 
<version>1.0-SNAPSHOT</version> 


<dependencies> 
    <dependency> 
     <groupId>org.apache.spark</groupId> 
     <artifactId>spark-core_2.10</artifactId> 
     <version>1.1.0</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.hbase</groupId> 
     <artifactId>hbase-client</artifactId> 
     <version>0.96.0-hadoop2</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.hbase</groupId> 
     <artifactId>hbase</artifactId> 
     <version>0.20.6</version> 
    </dependency> 
</dependencies> 


</project>'  

,這是我的代碼:

'SparkConf sparkConf = new SparkConf().setAppName("JavaWordCount"); 
    JavaSparkContext ctx = new JavaSparkContext(sparkConf); 
    //JavaSQLContext jsql = new JavaSQLContext(sc); 
    //test hbase table 
    HBaseConfiguration conf = new HBaseConfiguration(); 
    conf.set("hbase.zookeeper.quorum", "192.168.10.32"); 
    conf.set("hbase.zookeeper.property.clientPort","2181"); 
    conf.set("hbase.master", "192.168.10.32" + ":60000"); 
    conf.set("hbase.cluster.distributed", "true"); 
    conf.set("hbase.rootdir", "hdfs://localhost:8020/hbase"); 

    //conf.set(TableInputFormat.INPUT_TABLE, "gazelle_hive4"); 
    String tableName = "gazelle_hbase4"; 
    HTable table = new HTable(conf,tableName); 
    JavaPairRDD<ImmutableBytesWritable, Result> hBaseRDD = ctx 
      .newAPIHadoopRDD(
        conf, 
        TableInputFormat.class,, 
        org.apache.hadoop.hbase.io.ImmutableBytesWritable.class, 
        org.apache.hadoop.hbase.client.Result.class); 
    hBaseRDD.coalesce(1, true).saveAsTextFile(path + "hBaseRDD");' 

但我有 「TableInputFormat」

Error : Cannot resolve symbol TableInputFormat. Is their another library i should import or another dependency i should add?

注意一個問題:我還沒有創建任何XML文件。 我應該創建「hbase-default.xml」和「hbase-site.xml」嗎?如果是,如何?

非常感謝您的幫助。

回答

1

根據Apache Spark用戶列表中的this thread,您可能還需要一些其他的東西。

如果錯誤發生在運行時,您應該明確指定hbase jar到Spark。

spark-submit --driver-class-path $(hbase classpath) --jars /usr/lib/hbase/hbase-server.jar,/usr/lib/hbase/hbase-client.jar,/usr/lib/hbase/hbase-common.jar,/usr/lib/hbase/hbase-protocol.jar,/usr/lib/hbase/lib/protobuf-java-2.5.0.jar,/usr/lib/hbase/lib/htrace-core.jar --class YourClassName --master local App.jar

如果錯誤是在編譯時發生的事情,你可能缺少的依賴。 (hbase-server如線程中所述)。

+0

是的,謝謝你的回答:)我錯過了Hbase-Server。但是現在我在運行時出現了另一個錯誤:線程「main」中的異常java.lang.NoClassDefFoundError:org/apache/hadoop/hbase/HBaseConfiguration。 – 2014-11-25 13:55:56

+0

你對這個問題的根源有什麼想法嗎?謝謝 – 2014-11-25 13:57:41

+0

你的工作如何提交給Spark? Spark工作人員應該知道你所有的外部庫。 (在maven中有依賴關係*不夠*) – jchampemont 2014-11-25 14:21:53