任何人直接在HBase表上使用SparkSQL,就像在Hive表上使用SparkSQL一样。我是spark.Please新手,指导我如何连接hbase和spark.How来查询hbase表。
发布于 2016-09-20 00:28:02
AFAIK有两种方法可以连接到hbase表
-直接接入Hbase:
直接连接hbase并从RDD创建一个DataFrame,然后在上面执行SQL。我不打算重新发明轮子,请参阅How to read from hbase using spark,因为在上面的链接中@iMKanchwala的答案已经描述了它。唯一要做的就是将其转换为数据帧(使用toDF)并遵循sql方法。
-使用hbase存储处理程序将表注册为hive外部表,您可以在hivecontext中使用hive on spark。这也是一种简单的方法。
Ex :
CREATE TABLE users(
userid int, name string, email string, notes string)
STORED BY
'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES (
"hbase.columns.mapping" =
”small:name,small:email,large:notes”);具体操作方法请参阅example
我更喜欢方法1。
希望这能帮上忙。
https://stackoverflow.com/questions/39530938
复制相似问题