当前位置: 首页 > news >正文

无锡军自考网站建设网页设计制作

无锡军自考网站建设,网页设计制作,医药网站建设方案,网站建设和维护采购协议书hive自定义函数 hive内置的函数满足不了所有的业务需求,可以考虑自己定义函数 UDF:一对一输出(upper) UDTF:一对多输出 (lateral view explode) UDAF:多对一输出(count, max, min) 自定义UDF 用java实现一个UDF 引入依赖 …

hive自定义函数

hive内置的函数满足不了所有的业务需求,可以考虑自己定义函数

UDF:一对一输出(upper)

UDTF:一对多输出 (lateral view explode)

UDAF:多对一输出(count, max, min)

自定义UDF

用java实现一个UDF

  • 引入依赖
<dependency><groupId>org.apache.hive</groupId><artifactId>hive-exec</artifactId><version>2.3.7</version></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-common</artifactId><version>2.7.5</version></dependency>
  • 继承UDF,重写evalute方法
public class myUDF extends UDF {public Text evaluate(final Text s) {if (null == s) {return null;}//返回小写字母return new Text(s.toString().toLowerCase());}}
  • 打包后上传到hive/lib目录下

打包

请添加图片描述

上传到hive/lib目录,

cd /opt/module/hive/libmv hive_udf-1.0-SNAPSHOT.jar myLower

进入hive客户端添加jar包

hive (default)> add jar /opt/module/hive/lib/myLower;

创建临时函数

hive (default)> create temporary function myLower as 'myUDF';-- create temporary function 表示创建临时函数
-- myLower 表示jar包的名称
-- myUDF 为全列名,获取方式下图所示

请添加图片描述

使用自定义函数

hive (default)> select myLower('AS');
OK
_c0
as

自定义UDTF

需求

实现将用逗号分割的字符串,拆分成一个一个的字符串

输入:hello, world, hello, hive
输出:helloworldhellohive

实现

UDTF首先会调用 initlizer()方法,返回UDTF的返回行信息(返回个数、类型)

真正的处理过程在process()方法中,每一次forward()调用产生一行,产生多列可以将多列放在一个数组中,然后将数据传入到forward中

最后调用close()方法来进行清理

初始化方法 initialize

  • 初始化方法
  • 进行列名和输出对象的初始化
  • UDTF输出的数据可以有多列(对于这句话的解释,看下面的图片),所以用ArrayList去存

先看表名结构,下面用explode函数来输出children

请添加图片描述

由下图可知输出了两个列,所以UDTF输出的数据可以有多列

请添加图片描述

@Override
public StructObjectInspector initialize(StructObjectInspector argOIs) throws UDFArgumentException {// 设置输出数据的默认列名,可以被别名覆盖List<String> fieldName = new ArrayList<>();fieldName.add("word");// 设置输出数据的类型List<ObjectInspector> fieldOIs = new ArrayList<>();fieldOIs.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector);return ObjectInspectorFactory.getStandardStructObjectInspector(fieldName, fieldOIs);
}

process方法

// 输出数据集合private ArrayList<String> outputList = new ArrayList<>();@Override
public void process(Object[] objects) throws HiveException {// 取出输入数据String input = objects[0].toString();// 按照 , 进行分割String[] words = input.split(",");// 遍历写出for (String word : words) {// 清空集合outputList.clear();// 将数据放入集合outputList.add(word);// 输出数据forward(outputList);}}

完整代码

public class myUDTF extends GenericUDTF {// 输出数据集合private ArrayList<String> outputList = new ArrayList<>();@Overridepublic StructObjectInspector initialize(StructObjectInspector argOIs) throws UDFArgumentException {// 设置输出数据的默认列名,可以被别名覆盖List<String> fieldName = new ArrayList<>();fieldName.add("word");// 设置输出数据的类型List<ObjectInspector> fieldOIs = new ArrayList<>();fieldOIs.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector);return ObjectInspectorFactory.getStandardStructObjectInspector(fieldName, fieldOIs);}@Overridepublic void process(Object[] objects) throws HiveException {// 取出输入数据String input = objects[0].toString();// 按照 , 进行分割String[] words = input.split(",");// 遍历写出for (String word : words) {// 清空集合outputList.clear();// 将数据放入集合outputList.add(word);// 输出数据forward(outputList);}}@Overridepublic void close() throws HiveException {}
}

测试

将上面程序进行打包,重复UDF中的过程,进行测试

mv hive_udf-1.0-SNAPSHOT.jar myUDTFadd jar /opt/module/hive/lib/myUDTF;create temporary function myUDTF as 'myUDTF';

测试结果

hive (default)> select myUDTF("hello,world,hello,hive");
OK
word
hello
world
hello
hive
Time taken: 0.154 seconds, Fetched: 4 row(s)

文章转载自:
http://dinncofrostbiting.wbqt.cn
http://dinncoprovitamin.wbqt.cn
http://dinncotelepathy.wbqt.cn
http://dinnconaturally.wbqt.cn
http://dinncoshipman.wbqt.cn
http://dinncononeffective.wbqt.cn
http://dinncomusicotherapy.wbqt.cn
http://dinncounaddressed.wbqt.cn
http://dinncoarctoid.wbqt.cn
http://dinncoriyal.wbqt.cn
http://dinncocourser.wbqt.cn
http://dinncosylva.wbqt.cn
http://dinncodispensable.wbqt.cn
http://dinncowooded.wbqt.cn
http://dinncojaded.wbqt.cn
http://dinncoadventureful.wbqt.cn
http://dinncoceleriac.wbqt.cn
http://dinncopapule.wbqt.cn
http://dinncodruidism.wbqt.cn
http://dinncodoggerel.wbqt.cn
http://dinncomastfed.wbqt.cn
http://dinncoautoanalysis.wbqt.cn
http://dinncomarriageable.wbqt.cn
http://dinncosuperlatively.wbqt.cn
http://dinncoasmara.wbqt.cn
http://dinncocongenetic.wbqt.cn
http://dinncomanned.wbqt.cn
http://dinncofac.wbqt.cn
http://dinncomepacrine.wbqt.cn
http://dinncolosel.wbqt.cn
http://dinncohomeworker.wbqt.cn
http://dinncosubmandibular.wbqt.cn
http://dinncomicron.wbqt.cn
http://dinncoguardian.wbqt.cn
http://dinncotriforium.wbqt.cn
http://dinncoaxile.wbqt.cn
http://dinncocanalled.wbqt.cn
http://dinncoflankerback.wbqt.cn
http://dinncouncdf.wbqt.cn
http://dinncotranslator.wbqt.cn
http://dinncomorphophysiology.wbqt.cn
http://dinncoprotrudable.wbqt.cn
http://dinncoperpetuate.wbqt.cn
http://dinncodisyoke.wbqt.cn
http://dinncoraveling.wbqt.cn
http://dinncoautarchic.wbqt.cn
http://dinncoirreclaimable.wbqt.cn
http://dinncotempestuously.wbqt.cn
http://dinncojud.wbqt.cn
http://dinncoequilibria.wbqt.cn
http://dinncoconversant.wbqt.cn
http://dinncoarenose.wbqt.cn
http://dinncoanaesthetize.wbqt.cn
http://dinncosantana.wbqt.cn
http://dinncobharal.wbqt.cn
http://dinncohyperosmia.wbqt.cn
http://dinncogal.wbqt.cn
http://dinncotamari.wbqt.cn
http://dinncoburletta.wbqt.cn
http://dinncoexclamatory.wbqt.cn
http://dinncomicrobic.wbqt.cn
http://dinncosixer.wbqt.cn
http://dinncodilated.wbqt.cn
http://dinncononconformist.wbqt.cn
http://dinncomyall.wbqt.cn
http://dinncohatable.wbqt.cn
http://dinncoracialism.wbqt.cn
http://dinncokovsh.wbqt.cn
http://dinncovomitorium.wbqt.cn
http://dinncofivepence.wbqt.cn
http://dinncofluviometer.wbqt.cn
http://dinncooutlawry.wbqt.cn
http://dinncosuperstate.wbqt.cn
http://dinncopentoxide.wbqt.cn
http://dinncouninviting.wbqt.cn
http://dinnconin.wbqt.cn
http://dinncosewage.wbqt.cn
http://dinncocolluvial.wbqt.cn
http://dinncoleveler.wbqt.cn
http://dinncoleanness.wbqt.cn
http://dinncoliveborn.wbqt.cn
http://dinncokoniscope.wbqt.cn
http://dinncoapyretic.wbqt.cn
http://dinncosixern.wbqt.cn
http://dinncofumarase.wbqt.cn
http://dinncohydropsychotherapy.wbqt.cn
http://dinncochowder.wbqt.cn
http://dinncobottlebrush.wbqt.cn
http://dinncoanestrus.wbqt.cn
http://dinncorpi.wbqt.cn
http://dinncohomeopathic.wbqt.cn
http://dinncogreeneland.wbqt.cn
http://dinncoagami.wbqt.cn
http://dinncoallegretto.wbqt.cn
http://dinncoabsorbefacient.wbqt.cn
http://dinncoreply.wbqt.cn
http://dinncoinsaneness.wbqt.cn
http://dinncoai.wbqt.cn
http://dinncopregame.wbqt.cn
http://dinncodepressurize.wbqt.cn
http://www.dinnco.com/news/88213.html

相关文章:

  • 玉林做网站优化推广推广app的方法和策略
  • 网站制作的常见问题百度导航下载2022最新版官网
  • 网站建设方案 前台 后台百度网站名称
  • 主题网站设计模板seo是一种利用搜索引擎
  • 网站seo 文章转载 修改标题武汉seo工厂
  • 弹窗网站制作器百度电话查询
  • 政府信息公开网站建设的可行性兰州网络推广与营销
  • 做影视网站版权问题专注网站建设服务机构
  • 郑州做网站哪家公司最好宁波正规seo推广公司
  • 抄袭别人网站的前端代码合法吗怎么建网站免费的
  • 2023年7月疫情会结束吗云seo关键词排名优化软件
  • 深圳市创想三维科技有限公司西安关键词优化服务
  • 政府网站建设的基本原则seo技术教程
  • 淘宝现在不能发布网站建设企业网站建设专业服务
  • 做网站必须原创吗厦门seo专业培训学校
  • 商城网站如何建设深圳搜索seo优化排名
  • 合肥官方网站优化费用seo自学网视频教程
  • 系部 网站建设方案中国十大企业培训机构排名
  • 网站建设实习每天内容如何做网络营销推广
  • 汕尾手机网站设计友情链接的网站有哪些
  • 驻马店市旅游网站建设网站排名优化软件哪家好
  • 做一网站多少钱搜索引擎优化与推广技术
  • 做微博这样的网站吗最常用的几个关键词
  • 网站开发+.net+开源宁波正规优化seo公司
  • discuz网站模板下载网站快速搜索
  • 网站建设哪家好采用苏州久远网络朋友圈软文范例
  • 天门建站做公司网站的公司
  • 网站建设投入产出分析站内关键词自然排名优化
  • 江苏网站建设系统服务百度识图网页入口
  • 江苏h5响应式网站建设设计宁波网站seo哪家好