创建用于处理固定长度文件的Hive表 [英] Creating Hive table for handling fixed length file

查看:214
本文介绍了创建用于处理固定长度文件的Hive表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HDFS中有一个固定长度的文件,其中我必须使用正则表达式创建外部表。
我的文件是这样的:

  12piyush34stack10 
13pankaj21abcde41

我希望它将它转换为表格:

  key_column Value_column 
---------- -----------------
1234stack 12piyush34stack10
1321stack 13pankaj21abcde41

我甚至通过substr使用insert尝试过,但我无法指向key_columns。
请帮助解决这个问题。

解决方案

我不知道你为什么使用regexp外部表,但是如果我,我会创建一个正则表达式serde表,然后创建两列(key_column,Value_column),然后创建两个列(key_column,Value_column)如下所示指定serde选项:


SERDE'org.apache.hadoop.hive.serde2.RegexSerDe'



WITH SERDEPROPERTIES(

 input.regex=(\ d \ d)\\ \\ w {6}(\ d \ d)。*,

output.format.string=%1 $ s%2 $ sstack%0 $ s


输出选项将按空间顺序将空格分隔的数据写入相应的列。



尚未测试它,请注意,在java中,反斜杠可能无法正确解释。


I have a fixed length file in HDFS on top of which i have to create external table using regex. My file is something like this:

12piyush34stack10
13pankaj21abcde41

I want it to convert it into a table like:

key_column   Value_column
----------   ----------------- 
1234stack    12piyush34stack10
1321stack    13pankaj21abcde41

I tried even by substr using insert but i am unable to point to key_columns. Please help with solving this problem.

解决方案

I don't know why you've used regexp external table but the way cannot workout so as to need also use another substring operation.

If me , I would make a regexp serde table then create two columns(key_column , Value_column) and just specify serde option as follows:

SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'

WITH SERDEPROPERTIES (

 "input.regex" ="(\d\d)\w{6}(\d\d).*",

 "output.format.string" = "%1$s%2$sstack %0$s"

)

The output option will write the space separated data to corresponding columns by order.

Haven't yet test it , mind the back slash may not interpreted right in java.

这篇关于创建用于处理固定长度文件的Hive表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆