本文介绍了适用于Impala的BigInt的Java时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读取一个文本文件,该文件的时间戳记格式为"yyyy-MM-dd HH:mm:ss"

I am reading a text file which has a field in Timestamp in this format "yyyy-MM-dd HH:mm:ss"

我希望能够将其转换为BigInt的Impala中的字段,并且应该喜欢Java中的yyyMMddHHmmss.

I want to be able to convert it to a field in Impala as BigInt and should like yyyMMddHHmmss in Java.

我将Talend用于ETL,但出现此错误此组件的模式dbType不正确"所以我想在我的tImpalaOutput组件中进行正确的转换

I am using Talend for the ETL but I get this error "schema's dbType not correct for this component"and so I want to have the right transformation in my tImpalaOutput component

推荐答案

一个明显的选择是,将日期作为字符串读取,将其格式化为所需的输出,然后将其转换为很长的时间,然后再将其发送到Impala.

One obvious option is to read the date in as a string, format it to the output you want and then convert it to a long before sending it to Impala.

要做到这一点,您首先需要使用Talend的parseDate函数,例如:

To do this you would start by using Talend's parseDate function with something like:

TalendDate.parseDate("yyyy-MM-dd HH:mm:ss",row1.date)

这会将日期字符串解析为Date类型的对象.在这里,您可以使用以下方法将其转换为所需的字符串格式:

This parses the date string into a Date type object. From here you can convert this into your desired string format with:

TalendDate.formatDate("yyyMMddHHmmss",row2.date)

或者,可以通过以下方式一次性完成此操作:

Alternatively this can be done in one go with:

TalendDate.formatDate("yyyMMddHHmmss",TalendDate.parseDate("yyyy-MM-dd HH:mm:ss",row1.date))

此后,您应该具有所需格式的日期字符串.然后,您可以使用tConvertType组件或以下Java代码将此类型转换为Long:

After this you should have a date string in your desired format. You can then cast this to a Long using a tConvertType component or the following Java code:

Long.valueOf(row3.date)

或者,我们可以再次在一个衬里中完成整个事情:

Or, once again we can do the whole thing in a one liner:

Long.valueOf(TalendDate.formatDate("yyyMMddHHmmss",TalendDate.parseDate("yyyy-MM-dd HH:mm:ss",row1.date)))

从这里,您应该可以将它作为Java Long发送到Impala BIGINT字段.

From here you should be able to send this to Impala as a Java Long to an Impala BIGINT field.

这篇关于适用于Impala的BigInt的Java时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 08:18