开端:

今天咱先说问题,经过几天测试题的练习,我们有从某题库中找到了新题型,并且成功把我们干趴下,昨天今天就干了一件事,站起来。
沙问题?
java mapeduce 清洗 hive 中的数据 ,清晰之后将driver代码 进行截图提交。

坑号1: spark之前抽取的数据是.parquet格式的, 对 mapreduce 不太友好,我决定从新抽取, 还是用spark技术,换一种文件格式
坑号2: 使用新方法进行sink的时候我是直接like别的现成表结构折磨干的,后来hive分割字段都TM乱套啦,赞看看!

需求:

1.使用scala+spark技术实现抽取mysql到Hive中
2.使用java+ Mapeduce 技术实现清洗Hive数据

问题产生:

  • Mapeduce 无法 正常读取Hive数据
  • Mapeduce 无法 正常将结果sink到Hive中

解决路线:

首先从spark入手
为了解决spark写入hive后文件格式为 .parquet 问题

首先我们需要创建一个表,至于为什么不用自动建表,是因为自动建表 spark使用的是.parquet文件格式存储的

hive>  CREATE TABLE `ods.region2`(>   `regionkey` string,>    `name` string,>    `comment` string)>    PARTITIONED BY (>   `etldate` string>    )>   row format delimited>   fields terminated by '|' ;OK
Time taken: 0.055 seconds

spark sink hive 部分代码

    spark.sql("select *,'20220616' as etldate from data ").write.partitionBy("etldate").mode(saveMode = SaveMode.Overwrite).format("hive").option("delimiter","|").insertInto("ods.region2")

重点是这两条
.format("hive")
.insertInto("ods.region2")

我们看一下写好的数据
hdfs dfs -cat /user/hive/warehouse/ods.db/region2/etldate=20220616/*

3|EUROPE|ly final courts cajole furiously final excuse
4|MIDDLE EAST|uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl
0|AFRICA|lar deposits. blithely final packages cajole. regular waters are final requests. regular accounts are according to
1|AMERICA|hs use ironic, even requests. s
2|ASIA|ges. thinly even pinto beans ca

可以正常编写和运行java mapReduce 代码啦
代码不再一一贴出,放一个driver把

 <groupId>org.li</groupId><artifactId>mapreduce_06-21</artifactId><version>1.0</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><parquet.version>1.8.1</parquet.version><!-- JDateTime 依赖 --><jodd.version>3.3.8</jodd.version></properties>    <dependencies><!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common --><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-common</artifactId><version>2.7.6</version></dependency><!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client --><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-client</artifactId><version>2.7.6</version></dependency><!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-hdfs --><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-hdfs</artifactId><version>2.7.6</version></dependency><!-- parquet-hadoop --><dependency><groupId>org.apache.parquet</groupId><artifactId>parquet-hadoop</artifactId><version>${parquet.version}</version></dependency><!-- jodd --><dependency><groupId>org.jodd</groupId><artifactId>jodd</artifactId><version>${jodd.version}</version></dependency></dependencies>
package com.li.mapreduce;import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.db.DBInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.parquet.hadoop.ParquetInputFormat;
//import org.apache.parquet.hadoop.ParquetInputFormat;import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;public class HiveDriver{public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException, URISyntaxException {System.setProperty("HADOOP_USER_NAME","root");System.out.println("删除本地目录" + new File("/home/rjxy/output").delete());Configuration configuration = new Configuration();configuration.set("dfs.client.use.datanode.hostname","true");//hadoop配值文件//获取i工作势力Job instance = Job.getInstance(configuration);//关联driverinstance.setJarByClass(HiveDriver.class);//关联mapper reduceinstance.setMapperClass(HiveMapper.class);instance.setReducerClass(HiveReduce.class);//设置map输出的kv类型instance.setMapOutputKeyClass(LongWritable.class);instance.setMapOutputValueClass(Text.class);//设置最终的输入输出类型instance.setOutputKeyClass(NullWritable.class);instance.setOutputValueClass(Text.class);//Parquet
//        instance.setInputFormatClass();
//        instance.setInputFormatClass(ParquetInputFormat.class);//设置输入输出路径FileInputFormat.setInputPaths(instance,new Path("hdfs://master:9000/user/hive/warehouse/ods.db/" + "region2" + "/*/*"));Path outputDir = new Path("hdfs://master:9000/test4");
//        Path outputDir = new Path("/home/rjxy/output");FileOutputFormat.setOutputPath(instance, outputDir);//7 提交jobboolean result = instance.waitForCompletion(true);System.exit(result?0:1);}
}

这些代码就包含啦我的resource 数据信息 sink 位置
现在看一下怎么将hdfs数据进行load进hive表中
先建好表

hive>  CREATE TABLE `ods.region2`(>   `regionkey` string,>    `name` string,>    `comment` string)>    PARTITIONED BY (>   `etldate` string>    )>   row format delimited>   fields terminated by '|' ;OK
Time taken: 0.055 seconds
LOAD DATA INPATH '/test2' INTO TABLE ods.region2 partition(etldate="20220622");

查看hive清洗后的数据

hive (default)> select * from ods.region2 where etldate="20220622";
OK
region2.regionkey   region2.name    region2.comment region2.etldate
3   EUROPE  ly final courts cajole furiously final excuse   20220622
3   EUROPE  ly final courts cajole furiously final excuse   20220622
4   MIDDLE EAST uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl    20220622
4   MIDDLE EAST uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl    20220622
0   AFRICA  lar deposits. blithely final packages cajole. regular waters are final requests. regular accounts are according to  20220622
0   AFRICA  lar deposits. blithely final packages cajole. regular waters are final requests. regular accounts are according to  20220622
1   AMERICA hs use ironic, even requests. s 20220622
1   AMERICA hs use ironic, even requests. s 20220622
2   ASIA    ges. thinly even pinto beans ca 20220622
2   ASIA    ges. thinly even pinto beans ca 20220622Time taken: 0.194 seconds, Fetched: 10 row(s)

HADOOP MapReduce 处理 Spark 抽取的 Hive 数据【解决方案一】相关推荐

  1. spark sql读取hive底层_[大数据]spark sql读写Hive数据不一致

    在大数据公司中,任何一家公司都不会只使用一个框架吧?! skr,skr~~ 那我们今天就来聊一段 Hive 与 Spark的爱恨情仇 就像 在一些场景中,需要将外部的数据导入到Hive表中,然后再对这 ...

  2. Spark与Hadoop MapReduce相比,有哪些优点你知道吗?

    一提到大数据处理,相信很多人第一时间想到的是 Hadoop MapReduce.没错,Hadoop MapReduce 为大数据处理技术奠定了基础.近年来,随着 Spark 的发展,越来越多的声音提到 ...

  3. 数仓实战|两步搞定Hive数据加载到Greenplum

    如果说Hive是离线数仓的代表,那么Greenplum就是MPP数据库的代表.在离线数仓的年代,以Hive为核心的数据仓库席卷数据仓库市场,几乎成为了离线数仓的代名词.但是Hive的查询能力非常弱,通 ...

  4. python - hadoop,mapreduce demo

    Hadoop,mapreduce 介绍 59888745@qq.com 大数据工程师是在Linux系统下搭建Hadoop生态系统(cloudera是最大的输出者类似于Linux的红帽), 把用户的交易 ...

  5. hadooppythonsql_python - hadoop,mapreduce demo

    Hadoop,mapreduce 介绍 59888745@qq.com 大数据工程师是在Linux系统下搭建Hadoop生态系统(cloudera是最大的输出者类似于Linux的红帽), 把用户的交易 ...

  6. 大数据学习系列之七 ----- Hadoop+Spark+Zookeeper+HBase+Hive集群搭建 图文详解

    引言 在之前的大数据学习系列中,搭建了Hadoop+Spark+HBase+Hive 环境以及一些测试.其实要说的话,我开始学习大数据的时候,搭建的就是集群,并不是单机模式和伪分布式.至于为什么先写单 ...

  7. 编写Scala代码,使用Spark讲Mysql数据表中的数据抽取到Hive的ODS层

    编写Scala代码,使用Spark讲Mysql数据表中的数据抽取到Hive的ODS层 抽取MySQL的metast库中Production表的全量数据进入Hive的ods库中表production,字 ...

  8. Hive数据导入——数据存储在Hadoop分布式文件系统中,往Hive表里面导入数据只是简单的将数据移动到表所在的目录中!...

    转自:http://blog.csdn.net/lifuxiangcaohui/article/details/40588929 Hive是基于Hadoop分布式文件系统的,它的数据存储在Hadoop ...

  9. 使用Spark SQL读取Hive上的数据

    Spark SQL主要目的是使得用户可以在Spark上使用SQL,其数据源既可以是RDD,也可以是外部的数据源(比如Parquet.Hive.Json等).Spark SQL的其中一个分支就是Spar ...

最新文章

  1. 207. Course Schedule 210. Course Schedule II
  2. golang map 判断key是否存在
  3. Python处理小学体育中的跑步计时数据并统计得分
  4. python pip工具命令_python 工具链 包管理工具 pip
  5. Qt-Threads和QObjects详解
  6. 西交利物浦计算机专业分数线,西交利物浦大学2018年各省及各专业录取分数线及最低录投档线【理科 文科】...
  7. 不要笑!写 | 还是 || ,还真是一个问题
  8. sjf调度算法_如何通过静态方法预测SJF调度中未来过程的突发时间?
  9. 深度学习模型可解释性初探
  10. 世界上最伟大的推销员--2
  11. 【Flink】Flink on RocksDB 参数调优指南
  12. Linux内核概念:per-CPU,cpumask,inicall机制,通知链
  13. PhotoMill X for Mac(图片批处理工具)
  14. idea取消大小写自动提示
  15. python课程设计爬虫篇_11 个案例开启 Python 爬虫初体验
  16. 【板栗糖GIS】GIS如何导出obj格式的建筑白膜数据
  17. 浅谈ERP数据的重要性
  18. 大数据技术就在生活中: 登机牌、阅卷与 Map-Reduce(归约)
  19. 恩,今天把git和sublime结合了一下。。然后看了下《西部世界》
  20. 绪论--《可以量化的经济学》

热门文章

  1. elementary os 配置单
  2. freerots原理介绍
  3. K210口罩+人脸分辨+自学习+测温+串口屏
  4. 用endnote ,为什么总显示第一个作者的名(解决办法)
  5. 湖南阿波罗智行L4级低速自动驾驶小车亮相 湖南自动驾驶“朋友圈”再添新成员
  6. Python爬取素材网站的音频文件
  7. KIS 标准版 银行存款日记账扎帐后本期期初不等于上期期末余额
  8. 浅谈Linux下的媒体播放器(转)
  9. RC无源高低通滤波器
  10. amlogic红外遥控器适配