package udf_example;
import org.apache.hadoop.hive.ql.exec.UDF;
public class DataStandardization extends UDF{
public String evaluate(String input){
if(input == null){
return null;
}
return (input.toUpperCase());
}
}
rankfunctions.txt
Frank,1150
Frank,1700
CREATE TABLE IF NOT EXISTS rankchcektable(
col1 string,
col2 int
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' line terminated by '\n' STORED AS TEXTFILE
load data local inpath '/Users/basan/rankfunctions.txt' into table rankchcektable
Create jar
//Add the jar to hive
hive>add jar /users/basan/my_udf.jar
It will add jar to classpath
//create the function in hive
create temporary function f1 as 'udf_example.DataStandardization';
create temporary function functionname as 'packagename.classname';
//applying udf function
select f1(col1) from rankchcektable
import org.apache.hadoop.hive.ql.exec.UDF;
public class DataStandardization extends UDF{
public String evaluate(String input){
if(input == null){
return null;
}
return (input.toUpperCase());
}
}
rankfunctions.txt
Frank,1150
Frank,1700
CREATE TABLE IF NOT EXISTS rankchcektable(
col1 string,
col2 int
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' line terminated by '\n' STORED AS TEXTFILE
load data local inpath '/Users/basan/rankfunctions.txt' into table rankchcektable
Create jar
//Add the jar to hive
hive>add jar /users/basan/my_udf.jar
It will add jar to classpath
//create the function in hive
create temporary function f1 as 'udf_example.DataStandardization';
create temporary function functionname as 'packagename.classname';
//applying udf function
select f1(col1) from rankchcektable
No comments:
Post a Comment