Вы можете решить свою проблему, используя hive udf.
package com.practice;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.apache.hadoop.hive.ql.exec.UDF;
public class addYearWithTimestamp extends UDF{
private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
public String evaluate(String t, int year) throws ParseException{
long time=formatter.parse(t.toString()).getTime();
java.sql.Timestamp ts = new Timestamp(time);
Calendar cal = Calendar.getInstance();
cal.setTime(ts);
cal.add(Calendar.YEAR, year);
ts.setTime(cal.getTime().getTime());
return ts.toString();
}
}
После создания addYearWithTimestamp.jar зарегистрируйте его в кусте и создайте udf:
ADD JAR /home/cloudera/Desktop/addYearWithTimestamp.jar;
CREATE TEMPORARY FUNCTION addYear as 'com.practice.addYearWithTimestamp';
Используйте этот udf:
hive> SELECT addYear(current_timestamp,1);
OK
2021-04-25 08:22:17.948
Time taken: 0.083 seconds, Fetched: 1 row(s)