0.依赖
<dependencies>
<!--添加hive依赖-->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>3.1.2</version>
</dependency>
</dependencies>
1.UDF
功能:输入根据时间,返回星座类型。
关键点:1.extends UDF;2.在evaluate()方法中写逻辑;
如下代码:
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDF;
public class UDFDemo extends UDF {
private SimpleDateFormat df;
public UDFDemo(){
df= new SimpleDateFormat("yyyy-MM-dd");
}
public String evaluate(String date_str) throws Exception{
int month;
int day;
try{
java.util.Date bday = df.parse(date_str);
Calendar cal = Calendar.getInstance();
|