为大型数据文件每行只能产生id
4个主要思路:
1 单线程处理
2 普通多线程
3 hive
4 Hadoop
搜到一些參考资料
《Hadoop实战》的笔记-2、Hadoop输入与输出
https://book.douban.com/annotation/17068812/
TextInputFormat:文件偏移量:整行数据
可是这个偏移量,貌似是在一个文件的偏移,而不是全局。
Generate Auto-increment Id in Map-reduceJob
http://shzhangji.com/blog/2013/10/31/generate-auto-increment-id-in-map-reduce-job/
Generate unique customer id / insert uniquerows in hive
http://stackoverflow.com/questions/26855003/generate-unique-customer-id-insert-unique-rows-in-hive
Need to add auto increment column in atable using hive
http://stackoverflow.com/questions/23082763/need-to-add-auto-increment-column-in-a-table-using-hive
https://hadooptutorial.info/writing-custom-udf-in-hive-auto-increment-column-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
本文链接:http://blog.csdn.net/lingerlanlan/article/details/46430747
版权声明:本文博主原创文章,博客,未经同意不得转载。
为大型数据文件每行只能产生id的更多相关文章
- SQLLoader7(只导入数据文件的其中几行记录)
数据文件: D:\oracletest\test1.txt SMITH CLERK ALLEN SALESMAN WARD SALESMAN JONES MANAGER MARTIN SALESMAN ...
- oracle维护表空间和数据文件
1:重要参考 wiki 2: oracle doc 表空间参考 3:来自dba-oracle的参考 26,27,28,29 一:oracle 表空间概念 表空间是联系数据库的物理磁盘(数据文件)和逻辑 ...
- (四) 一起学 Unix 环境高级编程(APUE) 之 系统数据文件和信息
. . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级编程 (APUE) 之 文件 IO (三) 一起学 Unix 环境高级编 ...
- Oracle逻辑体系:数据文件黑盒的内在洞天
select username,session_num,tablespace from v$sort_usage; Block: 块的组成 Header:包含数据块的概要信息:块地址,块属于哪个段,还 ...
- oracle数据库单个数据文件的大小限制
之前没有仔细想过这个问题,因为总是不会用到,也没有犯过类似错误. 顺便提一下学习方法吧. 卤肉的学习方法是:常用知识点,熟悉理论并反复做实验,深入理解:不常用的知识点,相关内容都了解大概,遇到问题时想 ...
- InnoDB的行溢出数据,Char的行结构存储
行溢出数据 InnoDB存储引擎可以将一条记录中的某些数据存储在真正的数据页面之外,即作为行溢出数据.一般认为BLOB.LOB这类的大对象列类型的存储会把数据存放在数据页面之外.但是,这个理解有点偏差 ...
- 电商网站垮IDC数据备份,MySql主从同步,图片及其它数据文件的同步
原文网址:http://www.bzfshop.net/article/180.html 对一个电子商务网站而言,最宝贵的资源就是数据.服务器是很廉价的东西,即使烧了好几个也问题不大,但是用户数据如果 ...
- SQL SERVER大话存储结构(6)_数据库数据文件
数据库文件有两大类:数据文件跟日志文件,每一个数据库至少各有一个数据文件或者日志文件,数据文件用来存储数据,日志文件用来存储数据库的事务修改情况,可用于恢复数据库使用. 这里分 ...
- ORACLE - 管理表空间和数据文件
ORACLE表空间是一个逻辑分区,一个数据文件只能属于一个表空间,一个表空间可以拥有多个数据文件. 一般情况下,如果一个实例分配给多个应用使用,需要创建不同的表空间,每个用户使用自己的表空间. 一.表 ...
随机推荐
- POJ 2299 Ultra-QuickSort (求序列的逆序对数)
题意:废话了一大堆就是要你去求一个序列冒泡排序所需的交换的次数. 思路:实际上是要你去求一个序列的逆序队数 看案例: 9 1 0 5 4 9后面比它小的的数有4个 1后面有1个 0后面没有 5后面1个 ...
- javascript一元操作符(递增,递减)
<script type="text/javascript"> var a="1"; var b=false; var c="dd&quo ...
- POJ1163 The Triangle 【DP】
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36918 Accepted: 22117 De ...
- 设计模式 - 模板方法模式(template method pattern) JFrame 具体解释
模板方法模式(template method pattern) JFrame 具体解释 本文地址: http://blog.csdn.net/caroline_wendy 參考模板方法模式(templ ...
- Git使用操作指南和GitHub
本文记录Git的使用操作,把散落的记忆整理到一起.并介绍GitHub的使用. 使用Git代表着一种思想和境地,和SVN相比,不是技术上的差异有多么大,而是代表融入了一种新的生态环境.一种开放开源的心态 ...
- Android数据库专家秘籍(七)经验LitePal查询艺术
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/40153833 经过了多篇文章的学习,我们已经把LitePal中的绝大部分内容都掌握 ...
- C语言简单的菜单选项
#include <stdio.h> char get_choice(void); char get_first(void); int get_int(void); void count( ...
- go - 内置基础类型
Go 语言中包括以下内置基础类型: 布尔型:bool 整型:int int64 int32 int16 int8 uint8(byte) uint16 uint32 uint64 uint 浮点型:f ...
- aspx向silverlight传值
原文:http://www.cnblogs.com/lensso/archive/2010/07/27/1785844.html 方法1: 向嵌入aspx页面的silverlight对象添加imnit ...
- Blend4精选案例图解教程(一):丰富的形状(Shape)资源
原文:Blend4精选案例图解教程(一):丰富的形状(Shape)资源 Blend4资源面板中内置了丰富的形状素材,为我们在构建程序时提供极大的方便.系统默认内置18种常用形状,通过其属性设置可以自定 ...