博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
为大型数据文件每行只能产生id
阅读量:7229 次
发布时间:2019-06-29

本文共 1925 字,大约阅读时间需要 6 分钟。

为大型数据文件每行只能产生id

4个主要思路:

1 单线程处理

2 普通多线程

3 hive

4 Hadoop

 

搜到一些參考资料

《Hadoop实战》的笔记-2、Hadoop输入与输出

TextInputFormat:文件偏移量:整行数据

可是这个偏移量,貌似是在一个文件的偏移,而不是全局。

 

Generate Auto-increment Id in Map-reduceJob

 

Generate unique customer id / insert uniquerows in hive

 

Need to add auto increment column in atable using hive

 

 

Here make sure that addition of annotation@UDFType(stateful = true) is required otherwisecounter value will not get increment in the Hive column, it will just returnvalue 1 for all the rows but not the actual row number.

 

最后我採取了用hive写udf的方案。

package hive.udf;/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements.  See the NOTICE file * distributed with this work for additional information * regarding copyright ownership.  The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */import org.apache.hadoop.hive.ql.exec.Description;import org.apache.hadoop.hive.ql.exec.UDF;import org.apache.hadoop.hive.ql.udf.UDFType;/** * UDFRowSequence. */@Description(name = "row_sequence",    value = "_FUNC_() - Returns a generated row sequence number starting from 1")@UDFType(deterministic = false, stateful = true)//stateful參数是必要的public class UDFRowSequence extends UDF{  private int result;  public UDFRowSequence() {    result=0;  }  public int evaluate() {	  result++;    return result;  }}// End UDFRowSequence.java
 

本文作者:linger

本文链接:

版权声明:本文博主原创文章,博客,未经同意不得转载。

你可能感兴趣的文章
Android 获取SDCard中某个目录下图片
查看>>
设置cookies第二天0点过期
查看>>
【转载】NIO客户端序列图
查看>>
poj_2709 贪心算法
查看>>
【程序员眼中的统计学(11)】卡方分布的应用
查看>>
文件夹工具类 - FolderUtils
查看>>
http://blog.csdn.net/huang_xw/article/details/7090173
查看>>
lua学习例子
查看>>
研究:印度气候变暖速度加剧 2040年或面临重灾
查看>>
python爬虫——爬取豆瓣TOP250电影
查看>>
C++与Rust操作裸指针的比较
查看>>
了解webpack-4.0版本(一)
查看>>
如何培养良好的编程风格
查看>>
Netty Channel源码分析
查看>>
基于 HTML5 WebGL 的 3D 机房
查看>>
Java编程——数据库两大神器:索引和锁
查看>>
springMvc学习笔记(2)
查看>>
吐槽Javascript系列二:数组中的splice和slice方法
查看>>
什么是Javascript函数节流?
查看>>
MQ框架的比较
查看>>