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.