【发布时间】:2019-07-20 05:03:13
【问题描述】:
我正在使用 pyspark 通过 shc 访问 hbase 的表。该表有大量记录,但我的spark集群只有三台服务器,性能很差。我认为从那个hbase表中读取整个数据然后用spark的过滤器处理它是不合理的,那么我怎么能用pyspark和shc从hbase中读取部分数据呢? 例如,我想要筛选具有起始值结束值或筛选列的行键
有一个基本的读写方法,谢谢
from pyspark.sql import SparkSession
spark = SparkSession.builder.master('localhost').appName('test_1').getOrCreate()
def test_shc():
catalog = ''.join("""{
"table":{"namespace":"test", "name":"test_shc"},
"rowkey":"key",
"columns":{
"col0":{"cf":"rowkey", "col":"key", "type":"string"},
"col1":{"cf":"result", "col":"class", "type":"string"}
}
}""".split())
data_source_format = 'org.apache.spark.sql.execution.datasources.hbase'
df = spark.sparkContext.parallelize([('a', '1.0'), ('b', '2.0')]).toDF(schema=['col0', 'col1'])
df.show()
df.write.options(catalog=catalog, newTable="5").format(data_source_format).save()
df_read = spark.read.options(catalog=catalog).format(data_source_format).load()
df_read.show()
【问题讨论】: