@awsekfozc
2015-12-03T23:04:38.000000Z
字数 1545
阅读 1928
Hive
<!-- Hive Client -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>${hive.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>${hive.version}</version>
</dependency>
package bigdata.hadoop.hive.bigdata.hadoop.hive.udf;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
public class RemoveQuotes extends UDF{
public Text evaluate(Text inputValue){
return new Text();
}
}
hive (testdb)> add jar /opt/datas/udf_removequotes.jar;
Added /opt/datas/udf_removequotes.jar to class path
Added resource: /opt/datas/udf_removequotes.jar
hive (testdb)> create temporary function zc_removequotes as 'bigdata.hadoop.hive.bigdata.hadoop.hive.udf.RemoveQuotes';
OK
Time taken: 0.011 seconds
package bigdata.hadoop.hive.bigdata.hadoop.hive.udf;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
public class RemoveQuotes extends UDF{
public Text evaluate(Text inputValue){
if(null == inputValue){
return null;
}
if(StringUtils.isBlank(inputValue.toString())){
return null;
}
String str = inputValue.toString();
String reStr = str;
if(str.length()>1){
if ("\"".equals(str.substring(0,1))) {
reStr = reStr.substring(1);
}
if ("\"".equals(str.substring(str.length()-1))) {
reStr = reStr.substring(0,reStr.length()-1);
}
}
return new Text(reStr);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(new RemoveQuotes().evaluate(new Text("\"1\"")));
}
}
在此输入正文