大数据全系列 教程
1869个小节阅读:467.5k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
MapReduce 可用于完成批量数据的分布式处理,而 HBase 中表格的数据是非常庞大的,通常是 GB 或 TB 级,将 MapReduce 和 HBase 结合,能快速完成批量数据的处理。
xxxxxxxxxx
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-mapreduce</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
xxxxxxxxxx
object VirtualStationsProcessor {
}
xxxxxxxxxx
package com.itbaizhan.core
import com.itbaizhan.common.Constants
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.Result
import org.apache.hadoop.hbase.io.ImmutableBytesWritable
import org.apache.hadoop.hbase.mapreduce.TableInputFormat
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SparkSession
/**
* 虚拟车站
*/
object VirtualStationsProcessor {
def main(args: Array[String]): Unit = {
// 1、SparkSession 是 spark sql的入口。
val sparkSession = SparkSession.builder()
.master("local[*]")
.appName("VirtualStationsProcessor")
.getOrCreate()
// 2、获取Hbase链接
val conf:Configuration = HBaseConfiguration.create()
conf.set("hbase.zookeeper.quorum", "node2,node3,node4")
conf.set("hbase.zookeeper.property.clientPort", "2181")
// 3、读取HBase那个表
conf.set(TableInputFormat.INPUT_TABLE, Constants.HTAB_HAIKOU_ORDER)
// 4、读取表中数据RDD
val hRDD:RDD[(ImmutableBytesWritable,Result)] = sparkSession.sparkContext.newAPIHadoopRDD(
conf,
classOf[TableInputFormat],
classOf[ImmutableBytesWritable] , //HBASE TABLE rowkey ImmutableBytesWritable = String
classOf[Result] // V result
)
// 5、 打印
hRDD.foreach( result =>{
println(result)
})
}
}