Filename的一部分作为Hive Table中的一列 [英] Part of Filename as a column in Hive Table

查看:226
本文介绍了Filename的一部分作为Hive Table中的一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的文件名的第一部分作为我的Hive表中的一列

 我的文件名是:20151102114450.46400_Always_1446482638967 .xml 

我在Microsoft Azure的Hive中使用正则表达式编写了一个查询(查询下面)它的一部分,即20151102114450



但是当我运行查询时,我得到的输出为20151102164358

  select CAST(regexp_replace(regexp_replace(regexp_replace(CAST(CAST(regexp_replace(split(INPUT__FILE__NAME,'[_]')[2],'。xml','')AS BIGINT)TimeStamp) ,'',''),' - ',''),'','')AS BIGINT)作为VERSION 

任何人都可以告诉我我要去哪里,哪些地方需要改正? 这在Cloudera,希望它也应该在Azure中工作。

  select from_unixtime(unix_timestamp(regexp_extract('20151102114450.46400_Always _1446482638967.xml','^(。*?)\\\'。,'yyyyMMddHHmmss'),'yyyy-MMM-dd HH:mm:ss'); 

2015-Nov-02 11:44:50
拍摄时间:19.644秒,已获取:1行

另一个选项:

  select from_unixtime(unix_timestamp(split('20151102114450.46400 _Always_1446482638967.xml','\\。')[0],'yyyyMMddHHmmss'),'yyyy-MMM-dd HH:mm:ss')


I want to get the first part of my filename as a column in my Hive Table

My filename is : 20151102114450.46400_Always_1446482638967.xml

I wrote a query (below query) using regex in Hive of Microsoft Azure to get the first part of it i.e., 20151102114450

But when I run query I am getting the output as 20151102164358

select CAST(regexp_replace(regexp_replace(regexp_replace(CAST(CAST(regexp_replace(split(INPUT__FILE__NAME,'[_]')[2],'.xml','') AS BIGINT) as TimeStamp),':',''),'-',''),' ','') AS BIGINT) as VERSION

Can anyone tell me where I am going wrong and what needs to be corrected ?

解决方案

I tried this in Cloudera, hopefully it should work in Azure as well.

select from_unixtime(unix_timestamp(regexp_extract('20151102114450.46400_Always_1446482638967.xml','^(.*?)\\.'),'yyyyMMddHHmmss'),'yyyy-MMM-dd HH:mm:ss');

2015-Nov-02 11:44:50
Time taken: 19.644 seconds, Fetched: 1 row(s)

Another option:

select from_unixtime(unix_timestamp(split('20151102114450.46400_Always_1446482638967.xml','\\.')[0],'yyyyMMddHHmmss'),'yyyy-MMM-dd HH:mm:ss')

这篇关于Filename的一部分作为Hive Table中的一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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