问题描述
我使用的火花流蟒蛇读卡夫卡和写入HBase的,我发现saveAsNewAPIHadoopDataset阶段很容易被堵塞的工作。正如下面的图片:
你会发现时间是这个舞台上8个小时。通过HBase的API并火花写数据或直接写信通过HDFS API吗? 数据p>
一个有点晚了,但这里是一个类似的例子
要保存RDD HBase的:搜索结果
考虑包含一行的RDD:
{ID:3,名:月亮脸,色:灰色,说明:黑白猫咪}
变换RDD 结果
我们NEET到RDD转变成一个(键,值)对具有下列内容:
(rowkey,[行键,列族,列名,值])
数据映射= rdd.map(波长X:(STR(json.loads(X)[ID]),[STR(json.loads(X)[身份证 ]),cfamily,cats_json中,x))
保存到HBase的
结果,我们可以使用 RDD.saveAsNewAPIHadoopDataset
函数在这个例子中使用:的来保存RDD到HBase的
?
您可以参考我的博客:为工作示例的完整code。
I’m using spark-streaming python read kafka and write to hbase, I found the job on stage of saveAsNewAPIHadoopDataset very easily get blocked. As the below picture:You will find the duration is 8 hours on this stage. Does the spark write data by Hbase api or directly write the data via HDFS api please?
A bit late , but here is a similar example To save an RDD to hbase :
Consider an RDD containing a single line :
{"id":3,"name":"Moony","color":"grey","description":"Monochrome kitty"}
Transform the RDD
We neet to transform the RDD into a (key,value) pair having the following contents:
( rowkey , [ row key , column family , column name , value ] )
datamap = rdd.map(lambda x: (str(json.loads(x)["id"]),[str(json.loads(x)["id"]),"cfamily","cats_json",x]))
Save to HBase
We can make use of the RDD.saveAsNewAPIHadoopDataset
function as used in this example: PySpark Hbase example to save the RDD to HBase?
datamap.saveAsNewAPIHadoopDataset(conf=conf,keyConverter=keyConv,valueConverter=valueConv)
You can refer to my blog :pyspark-sparkstreaming hbase for the complete code of the working example.
这篇关于火花写数据分流到HBase的与Python封锁saveAsNewAPIHadoopDataset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!