合并hive仓库中小文件
来源:互联网 发布:天猫抢优惠券软件 编辑:程序博客网 时间:2024/06/15 14:08
使用lijie库下的test表做实验
1.查看hdfs下该表的文件存储:
hadoop dfs -ls /user/hive/warehouse/lijie.db/test
结果如下:
2.模拟小文件
insert into table test select * from test;上面语句执行多次
3.合并
insert overwrite table test select * from test;
没错就是这一条语句搞定!
如图:
4.如果用java程序合并小文件,可以参考下面的程序:
package com.lijie.hebingxiaowenjian;import java.net.URI;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FSDataInputStream;import org.apache.hadoop.fs.FSDataOutputStream;import org.apache.hadoop.fs.FileStatus;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.FileUtil;import org.apache.hadoop.fs.LocalFileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.fs.PathFilter;import org.apache.hadoop.io.IOUtils;public class HeBing { public static void main(String[] args) throws IllegalArgumentException, Exception { uploadCom(new Path("F://hebing/*"), new Path("/hb")); } public static void uploadCom(Path src,Path dest) throws Exception{ Configuration conf = new Configuration(); URI uri = new URI("hdfs://lijie:9000"); FileSystem fs = FileSystem.get(uri, conf); LocalFileSystem lfs = FileSystem.getLocal(conf); FileStatus[] gs1 = lfs.globStatus(src, new NoFilter("^.*svn$")); Path[] ps1 = FileUtil.stat2Paths(gs1); FSDataInputStream in = null; FSDataOutputStream out = null; for (Path path : ps1) { String name = path.getName().replaceAll("-", ""); FileStatus[] gs2 = lfs.globStatus(new Path(path+"/*"), new YesFilter("^.*txt$")); Path[] ps2 = FileUtil.stat2Paths(gs2); Path destNow = new Path(dest+"/"+name+".txt"); out = fs.create(destNow); for (Path path2 : ps2) { in = lfs.open(path2); IOUtils.copyBytes(in, out, 4096, false); in.close(); } out.close(); } }}class YesFilter implements PathFilter{ private String reg; public YesFilter(String reg) { super(); this.reg = reg; } @Override public boolean accept(Path arg0) { // TODO Auto-generated method stub return arg0.toString().matches(reg); }}class NoFilter implements PathFilter{ private String reg; public NoFilter(String reg) { super(); this.reg = reg; } @Override public boolean accept(Path arg0) { return !arg0.toString().matches(reg); }}
0 0
- 合并hive仓库中小文件
- hadop hive中小文件自动合并设置。
- hql中小文件合并操作
- hive小文件合并
- Hive小文件合并
- Hive 合并输入输出文件
- hive合并小文件
- hive 小文件合并
- Hive小文件合并
- Hive 合并小文件
- hive合并小文件
- hive合并小文件
- Hive小文件合并调研
- Hive小文件合并调研
- hive小文件合并问题
- Hive小文件合并汇总
- Hive 之 合并小文件
- hive小文件问题及hive小文件合并
- 烟雾传感器MQ-2的应用
- 自定义的广告轮播---(二)(无限循环)
- 【latex】插入图片Figure相关参数
- LWIP 学习博客
- 数字图像处理的基本原理和常用方法
- 合并hive仓库中小文件
- 面试题解析001:Java对象创建及初始化
- 通用管理系统的思考
- 线程同步面试题,3个线程打印一个1-100的数组,要求P1=1,P2=2,P3=3,P1=4的形式
- HDU 4465 Candy【指数表示法】E
- 不是打印控件没有安装
- BZOJ 斜率优化大水题(集)2 1096
- PHP 为Thinkphp 配置 Nginx phpinfo 模式
- Connection attempts: 11Adb connection Error:远程主机强迫关闭了一个现有的连接