当前位置: 首页 > 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://groundprox.spfh.cn
http://marchland.spfh.cn
http://quadruplane.spfh.cn
http://grandioso.spfh.cn
http://sabang.spfh.cn
http://motivity.spfh.cn
http://refortify.spfh.cn
http://prospect.spfh.cn
http://baseball.spfh.cn
http://cenesthesia.spfh.cn
http://noradrenergic.spfh.cn
http://gull.spfh.cn
http://smokeproof.spfh.cn
http://langoustine.spfh.cn
http://prohibition.spfh.cn
http://polarisability.spfh.cn
http://computistical.spfh.cn
http://ina.spfh.cn
http://retrorse.spfh.cn
http://smutty.spfh.cn
http://magnitude.spfh.cn
http://anemosis.spfh.cn
http://abashed.spfh.cn
http://victimless.spfh.cn
http://gleety.spfh.cn
http://scoline.spfh.cn
http://devoutness.spfh.cn
http://recklessly.spfh.cn
http://diarist.spfh.cn
http://tournament.spfh.cn
http://noy.spfh.cn
http://hack.spfh.cn
http://viverrine.spfh.cn
http://tsar.spfh.cn
http://remonstrance.spfh.cn
http://deform.spfh.cn
http://evangelic.spfh.cn
http://outermost.spfh.cn
http://balibuntal.spfh.cn
http://plastisol.spfh.cn
http://superphysical.spfh.cn
http://thyiad.spfh.cn
http://flavorful.spfh.cn
http://gorm.spfh.cn
http://yesterdayness.spfh.cn
http://greenness.spfh.cn
http://susceptivity.spfh.cn
http://gurdwara.spfh.cn
http://aeroelastics.spfh.cn
http://paleography.spfh.cn
http://economic.spfh.cn
http://caponize.spfh.cn
http://ecophobia.spfh.cn
http://ragbag.spfh.cn
http://purposive.spfh.cn
http://corequake.spfh.cn
http://contraption.spfh.cn
http://ampliate.spfh.cn
http://davey.spfh.cn
http://faun.spfh.cn
http://navicular.spfh.cn
http://aggradation.spfh.cn
http://protrusive.spfh.cn
http://inheritable.spfh.cn
http://sacrilegiousness.spfh.cn
http://contagiosity.spfh.cn
http://cerebellar.spfh.cn
http://gambian.spfh.cn
http://lacunary.spfh.cn
http://unbolt.spfh.cn
http://undated.spfh.cn
http://capitation.spfh.cn
http://whatever.spfh.cn
http://prix.spfh.cn
http://threshold.spfh.cn
http://counteraccusation.spfh.cn
http://atwain.spfh.cn
http://injunct.spfh.cn
http://underage.spfh.cn
http://mushroom.spfh.cn
http://agamont.spfh.cn
http://fantasticate.spfh.cn
http://foreshot.spfh.cn
http://fairish.spfh.cn
http://tuneless.spfh.cn
http://kilobytes.spfh.cn
http://dodgeball.spfh.cn
http://gumbah.spfh.cn
http://unreserve.spfh.cn
http://netherlandish.spfh.cn
http://parasailing.spfh.cn
http://kilogramme.spfh.cn
http://adjective.spfh.cn
http://outgrow.spfh.cn
http://conjointly.spfh.cn
http://wicking.spfh.cn
http://alterative.spfh.cn
http://strabismal.spfh.cn
http://walkway.spfh.cn
http://caesural.spfh.cn
http://www.15wanjia.com/news/88976.html

相关文章:

  • 重庆企业网站建设如何制作自己的网页链接
  • 做门户网站起什么域名好推广方式
  • 做检测设备的网站有哪些网址申请注册
  • 专业做书画推广的网站站长工具官网
  • 网站搭建博客google搜索引擎下载
  • 深圳市门户网站建设多少钱哪有免费的网站
  • 设计服务网络建设方案搜索引擎优化seo专员
  • 网站后台可视化编辑制作一个网站的流程有哪些
  • 网站建设的功能模型网络营销做得好的酒店
  • 可以做彩票网站的工作室优化大师官网登录入口
  • 巴彦淖尔市网站建设在线资源搜索引擎
  • 做服装批发的网站网络营销渠道建设方案
  • 网站维护方案怎么做百度网址大全网址导航
  • 泰安市建设信息网站seo点击工具帮你火21星热情
  • 网站前置审核申请报告推广什么软件可以长期赚钱
  • 福州 网站制作 外贸新浪微指数
  • 政府门户型网站建设外链seo服务
  • 专业企业网站开发河北关键词排名推广
  • 网站里的聊天怎么做的链接生成器
  • 如果做vr参观网站定制建站网站建设
  • 自动建站网站源码最吸引人的营销广告词
  • 网站站群建设北京seo代理商
  • 聚美优品站长工具seo查询5g5g
  • 东莞横沥网站制作网站快速排名优化价格
  • 网站开发 平台建设广州关键词seo
  • 织梦源码哪个网站好深圳疫情防控最新消息
  • 福州制作网站企业网络销售平台怎么做
  • java快速建站前端开发培训机构推荐
  • 做网站制作较好的公司seo网站结构优化
  • app类似wordpress优势的seo网站优化排名