HBase 表上的 SparkSQL [英] SparkSQL on HBase Tables
问题描述
任何人都直接在 HBase 表上使用 SparkSQL,就像在 Hive 表上使用 SparkSQL.我是spark新手.请指导我如何连接hbase和spark.如何查询hbase表.
Anybody is using SparkSQL on HBase tables directly, like SparkSQL on Hive tables. I am new to spark.Please guide me how to connect hbase and spark.How to query on hbase tables.
推荐答案
AFAIK 有两种方法可以连接到 hbase 表
AFAIK there are 2 ways to connect to hbase tables
直接连接 hbase 并从 RDD
创建一个 DataFrame
并在其上执行 SQL.我不会重新发明轮子,请参阅 如何使用 spark 从 hbase 读取正如上面链接中@iMKanchwala 的回答已经描述了它.唯一的事情是将其转换为数据帧(使用 toDF
)并遵循 sql 方法.
Directly connect hbase and create a DataFrame
from RDD
and execute SQL on top of that.
Im not going to re-invent the wheel please see How to read from hbase using spark
as the answer from @iMKanchwala in the above link has already described it. only thing is convert that in to dataframe (using toDF
) and follow the sql approach.
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");
如何做到这一点,请参阅示例
How to do that please see as an example
我更喜欢方法 1.
希望有帮助...
这篇关于HBase 表上的 SparkSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!