java timestamp int,适用于Impala的BigInt的Java时间戳

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

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

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

解决方案

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.

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)

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))

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)))

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值