spark怎么从hbase数据库当中创建rdd

spark怎么从hbase数据库当中创建rdd,第1张

Configuration conf = HBaseConfiguration.create()

String tableName = "testTable"

Scan scan = new Scan()

scan.setCaching(10000)

scan.setCacheBlocks(false)

conf.set(TableInputFormat.INPUT_TABLE, tableName)

ClientProtos.Scan proto = ProtobufUtil.toScan(scan)

String ScanToString = Base64.encodeBytes(proto.toByteArray())

conf.set(TableInputFormat.SCAN, ScanToString)

JavaPairRDD<ImmutableBytesWritable, Result>myRDD = sc

.newAPIHadoopRDD(conf, TableInputFormat.class,

ImmutableBytesWritable.class, Result.class)

在Spark使用如上Hadoop提供的标准接口读取HBase表数据(全表读),读取5亿左右数据,要20M+,而同样的数据保存在Hive中,读取却只需要1M以内,性能差别非常大

直接看代码

[java] view plain copy

import org.apache.spark.sql.{DataFrame, SQLContext}

import org.apache.spark.{SparkConf, SparkContext}

/**

* wo xi huan xie dai ma

* Created by wangtuntun on 16-5-7.

*/

object clean {

def main(args: Array[String]) {

//设置环境

val conf=new SparkConf().setAppName("tianchi").setMaster("local")

val sc=new SparkContext(conf)

val sqc=new SQLContext(sc)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9932350.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存