hive concat_ws源代码
其他相关源码可以到以下链接查看: https://github.com/apache/hive/tree/master/ql/src/java/org/apache/hadoop/hive/ql/udf/generic
package org.apache.hadoop.hive.ql.udf.generic;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.serde.serdeConstants;
import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils.PrimitiveGrouping;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector;
import org.apache.hadoop.io.Text;
/**
* Generic UDF for string function
* <code>CONCAT_WS(sep, [string | array(string)]+)</code>.
* This mimics the function from
* MySQL http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#
* function_concat-ws
*
* @see org.apache.hadoop.hive.ql.udf.generic.GenericUDF
*/
@Description(name = "concat_ws",
value = "_FUNC_(separator, [string | array(string)]+) - "
+ "returns the concatenation of the strings separated by the separator.",
extended = "Example:\n"
+ " > SELECT _FUNC_('.', 'www', array('facebook', 'com')) FROM src LIMIT 1;\n"
+ " 'www.facebook.com'")
public class GenericUDFConcatWS extends GenericUDF {
private transient ObjectInspector[] argumentOIs;
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length < 2) {
throw new UDFArgumentLengthException(
"The function CONCAT_WS(separator,[string | array(string)]+) "
+ "needs at least two arguments.");
}
// check if argument is a string or an array of strings
for (int i = 0; i < arguments.length; i++) {
switch(arguments[i].getCategory()) {
case LIST:
if (isStringOrVoidType(
((ListObjectInspector) arguments[i]).getListElementObjectInspector())) {
break;
}
case PRIMITIVE:
if (isStringOrVoidType(arguments[i])) {
break;
}
default:
throw new UDFArgumentTypeException(i, "Argument " + (i + 1)
+ " of function CONCAT_WS must be \"" + serdeConstants.STRING_TYPE_NAME
+ " or " + serdeConstants.LIST_TYPE_NAME + "<" + serdeConstants.STRING_TYPE_NAME
+ ">\", but \"" + arguments[i].getTypeName() + "\" was found.");
}
}
argumentOIs = arguments;
return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
protected boolean isStringOrVoidType(ObjectInspector oi) {
if (oi.getCategory() == Category.PRIMITIVE) {
if (PrimitiveGrouping.STRING_GROUP
== PrimitiveObjectInspectorUtils.getPrimitiveGrouping(
((PrimitiveObjectInspector) oi).getPrimitiveCategory())
|| ((PrimitiveObjectInspector) oi).getPrimitiveCategory() == PrimitiveCategory.VOID) {
return true;
}
}
return false;
}
private final Text resultText = new Text();
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
if (arguments[0].get() == null) {
return null;
}
String separator = PrimitiveObjectInspectorUtils.getString(
arguments[0].get(), (PrimitiveObjectInspector)argumentOIs[0]);
StringBuilder sb = new StringBuilder();
boolean first = true;
for (int i = 1; i < arguments.length; i++) {
if (arguments[i].get() != null) {
if (first) {
first = false;
} else {
sb.append(separator);
}
if (argumentOIs[i].getCategory().equals(Category.LIST)) {
Object strArray = arguments[i].get();
ListObjectInspector strArrayOI = (ListObjectInspector) argumentOIs[i];
boolean strArrayFirst = true;
for (int j = 0; j < strArrayOI.getListLength(strArray); j++) {
if (strArrayFirst) {
strArrayFirst = false;
} else {
sb.append(separator);
}
sb.append(strArrayOI.getListElement(strArray, j));
}
} else {
sb.append(PrimitiveObjectInspectorUtils.getString(
arguments[i].get(), (PrimitiveObjectInspector)argumentOIs[i]));
}
}
}
resultText.set(sb.toString());
return resultText;
}
@Override
public String getDisplayString(String[] children) {
assert (children.length >= 2);
return getStandardDisplayString("concat_ws", children);
}
}
hive concat_ws源代码的更多相关文章
- hive UDAF源代码分析
sss /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license a ...
- 037 对于HIVE架构的理解
0.发展 在hive公布源代码之后 公司又公布了presto,这个比较快,是基于内存的. impala:3s处理1PB数据. 1.Hive 能做什么,与 MapReduce 相比优势在哪里 关于hi ...
- Hive Web Interface的安装
Hive Web Interface,简称hwi,是Hive的Web接口. 首先,安装ant,下载ant,解压,并在/etc/profile中设置: export ANT_HOME=/opt/apac ...
- Hive内置函数和自定义函数的使用
一.内置函数的使用 查看当前hive版本支持的所有内置函数 show function; 查看某个函数的使用方法及作用,比如查看upper函数 desc function upper; 查看upper ...
- CIA Hive Beacon Infrastructure复现1——使用Apache mod_rewrite实现http流量分发
0x00 前言 2017年11月9日维基解密公布一个代号为Vault8的文档,包含服务器远程控制工具Hive的源代码和开发文档.开发文档中的框架图显示Hive支持流量分发功能,若流量有效,转发至Hon ...
- 远程调试hadoop各组件
远程调试对应用程序开发十分有用.例如,为不能托管开发平台的低端机器开发程序,或在专用的机器上(比如服务不能中断的 Web 服务器)调试程序.其他情况包括:运行在内存小或 CUP 性能低的设备上的 Ja ...
- 【转】大数据分析(Big Data OLAP)引擎Dremel, Tenzing 以及Impala
引自:http://blog.csdn.net/xhanfriend/article/details/8434896 对于数据分析师来说,SQL是主要的语言. Hive为Hadoop提供了支持SQL运 ...
- hive源代码解析之一hive主函数入口
hive其实做的就是解析一条sql然后形成到mapreduce任务,就是一个代码解释器.hive源代码本身就可以分为ql/metasotre/service/serde 这几块:其中 对于Hive来说 ...
- concat_ws 使用在hive spark-sql上的区别
concat_ws() 在hive中,被连接对象必须为string或者array<string>,否则报错如下: hive> select concat_ws(',',unix_ti ...
随机推荐
- Java开发面试题汇总 -- 精选版(附答案)
最近事情太多,没太时间写公众号.今天抽空再整理整理面试中的那点事吧,帮助那些正在找工作或想跳槽找工作的兄弟姐妹们. 前面我己写过多篇推文,相信关注此公众号的伙伴们已经了解掌握了不少.从目前流行的开发技 ...
- MyBatis从入门到精通(十三):使用discriminator鉴别器映射
最近在读刘增辉老师所著的<MyBatis从入门到精通>一书,很有收获,于是将自己学习的过程以博客形式输出,如有错误,欢迎指正,如帮助到你,不胜荣幸! 本篇博客主要讲解鉴别器映射discri ...
- Lock和synchronized比较详解(转)
从Java5之后,在java.util.concurrent.locks包下提供了另外一种方式来实现同步访问,那就是Lock. 也许有朋友会问,既然都可以通过synchronized来实现同步访问了, ...
- 抓包自定义过滤器需加%XXXX%,如%third_play%
抓包自定义过滤器需加%XXXX%,如%third_play%
- python调用WebService遇到的问题'Document' object has no attribute 'set'
代码: from suds import WebFault from suds.client import Client url = 'http://******/bns/PtDataSvc.asmx ...
- sql format 格式化数字(前面补0)
将一个数字例如33,或1使用t-sql语句转换成033或001 以下是详细分析: 1.select power(10,3)得到1000 2.select cast(1000+33 as varchar ...
- spring-Scheduler
作者:纯洁的微笑出处:http://www.ityouknow.com/ 版权所有,欢迎保留原文链接进行转载:) 在我们的项目开发过程中,经常需要定时任务来帮助我们来做一些内容,springboot默 ...
- 【eclipse】No enclosing instance of type A is accessible. Must qualify the allocation with an enclosing instance of type A
用 eclipse 写 Java 代码时出现了这个问题,详细如下: No enclosing instance of type TestParsingLinkedList is accessible. ...
- 电信光猫带路由器(F452)的虚拟服务器端口映射
现在电信宽带的光猫一般都自带路由器功能,为了方便运营商管理网络用户,电信公司插入了企业局域网,网络用户的光猫路由器都是这个局域网的节点.用户家里的电脑在网络中的结构位置一般如下所示: 互联网(公网)= ...
- MOCTF-Crypt-writeup
MOctf Crypt Writeup记录 都不难,就随便记录记录下. MOCTF平台地址:http://www.moctf.com 0x01 数据库密码 hint:20岁的小刚,自幼热爱信息安全,一 ...