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 ...
随机推荐
- The Summer Training Summary-- the first
The Summer Training Summary-- the first A - vector的使用 UVa 101 关于vector 的几个注意点 vector p p.push_back() ...
- 关于ftp响应码的分析【转载】
转载地址: http://www.jb51.net/article/26649.htm 1开头-成功 2开头-成功 3开头-权限问题 4开头-文件问题 5开头-服务器问题 150 FILE: %s 1 ...
- redis 发布与订阅原理分析
前言:用了redis也有一段时间了,但是发布与订阅的使用频率也不高,趁着这次空闲,深究下redis的发布与订阅模式. 一.订阅频道和信息发布 功能说明:Redis 的 SUBSCRIBE 命令可以让客 ...
- CUDA编程学习笔记2
第二章 cuda代码写在.cu/.cuh里面 cuda 7.0 / 9.0开始,NVCC就支持c++11 / 14里面绝大部分的语言特性了. Dim3 __host__ __device__ dim3 ...
- 下拉选择框,PopupWindow的使用
实现下拉选择框 直接上代码 Activity.java package com.example.shaofei.customerviewdemo1; import android.os.Bundle; ...
- 总结暨JAVAWEB学习开篇(一)
匆匆,距上一篇博客已经过去7月有余,遂作文一篇总结暨JAVAWEB学习开篇. 1. 啃英文新概念.在多方讨教英语大佬后改变学习方式,通过背诵英文书籍以及多听英文录音来学习,效果还不错(等真正有成效了跟 ...
- c的格式输出“%”
- java练习---4
//程序员:罗元昊 2017.9.17 今天好累吖咦吖咦吖 package demo;import java.util.Scanner;public class Lk { public static ...
- java用最少循环求两个数组的交集、差集、并集
import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List ...
- rabbitMQ_routing(四)
路由 本次我们将通过路由将信息发送到指定的队列中,将消息发送给指定的队列需要在转发器和队列之间建立一个routeKey 绑定 在以前的例子中,我们已经创建了绑定.你可能会记得如下代码: channel ...