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

17zwd一起做网站广州新塘网站自动收录

17zwd一起做网站广州新塘,网站自动收录,网页制作需要什么基础,论述网站建设整个流程文档地址:https://cwiki.apache.org/confluence/display/Hive/LanguageManualTransform 一、介绍二、实现1.脚本上传到本地2.脚本上传到hdfs 三、几个需要注意的点1.脚本名不要写全路径2.using后面语句中,带不带"python"的问题3.py脚本Shebang…

文档地址:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Transform

  • 一、介绍
  • 二、实现
    • 1.脚本上传到本地
    • 2.脚本上传到hdfs
  • 三、几个需要注意的点
    • 1.脚本名不要写全路径
    • 2.using后面语句中,带不带"python"的问题
    • 3.py脚本Shebang:#!/usr/bin/env python

一、介绍

和udf差不多的作用,支持用python实现。通过标准输入流从hive读取数据,内部处理完再通过标准输出流将处理结果返回给hive。实现流程上比udf要更简单灵活一些,只需要上传脚本=>add file加载到分布式缓存=>使用。

二、实现

先定义一个名为transform.py的脚本,将传入的两个字段值都+1。

#!/usr/bin/env python
import sysfor line in sys.stdin:try:x, y = map(float, line.strip().split('\t'))x += 1y += 1print('\t'.join(map(str, [x, y])))except ValueError as e:print('\t'.join([r'\N'] * 2))

上面对输入流按照\t分隔是因为hive中的数据在传递到py脚本时,多个字段间默认会用\t分隔拼接为字符串,并且空值null会被转为字符串\N。同样将处理结果返回给hive时,如果多个字段,为了hive能够正确解析,也需要用\t拼接输出,单独的\N在hive中也会被重新解释为null。
在这里插入图片描述
除了单独的\N会被重新解释为null外,还有一种情况也会被hive解释为null,就是脚本里返回的字段个数小于hive中接收的字段个数时,hive中多余的字段会被赋值为null。

1.脚本上传到本地

这里的本地指的是hive主服务hive server2所在的节点,也就是我们客户端连接的那个机器。

先上传到主服务机器下的某个路径:

# 文件上传路径
[root@node1 HiveLib]# readlink -e transform.py
/root/HiveLib/transform.py

上传后通过add file命令将脚本添加到分布式缓存,之后就可以直接使用了。

-- 添加到分布式缓存
add file /root/HiveLib/transform.py;-- 创建一个临时表测试执行
with `table` as (select '1' as id, '1.6789' as col1, '7.13' as col2union allselect '2' as id, '11.568' as col1, null as col2union allselect '3' as id, '26.09761' as col1, '71.89002' as col2
)
-- as后面接收脚本返回值的字段也可以指定字段类型, eg:(col1 double, col2 double), 省略时默认都是字符串string类型
select transform (col1, col2) using 'transform.py' as (col1, col2) from `table`;

在这里插入图片描述

2.脚本上传到hdfs

这种方式和本地实现基本一致,只不过需要将脚本上传到hdfs中,add file时后面跟的是hdfs路径。

[root@node1 HiveLib]# hadoop fs -put ./transform.py /user/hive/lib
[root@node1 HiveLib]# hadoop fs -ls /user/hive/lib
Found 2 items
-rw-r--r--   3 root supergroup       4164 2022-12-18 00:48 /user/hive/lib/hive_udf-1.0-SNAPSHOT.jar
-rw-r--r--   3 root supergroup        257 2024-05-05 19:13 /user/hive/lib/transform.py

sql客户端中执行:

-- 脚本路径换为hdfs路径
add file hdfs://node1:8020/user/hive/lib/transform.py;with `table` as (select '1' as id, '1.6789' as col1, '7.13' as col2union allselect '2' as id, '11.568' as col1, null as col2union allselect '3' as id, '26.09761' as col1, '71.89002' as col2
)
select transform (col1, col2) using 'transform.py' as (col1, col2) from `table`;

在这里插入图片描述

三、几个需要注意的点

1.脚本名不要写全路径

using语句后面指定脚本只写脚本名即可,不要写全路径。全路径的话会报错[08S01][20000] Error while processing statement: FAILED: Execution Error, return code 20000 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask. Unable to initialize custom script.,参考
https://stackoverflow.com/questions/15106127/i-met-an-error-when-i-using-hive-transform-features,我也不太理解为什么有这要求,先照做就行。
在这里插入图片描述

2.using后面语句中,带不带"python"的问题

这里说的是sql语句中,是using 'transform.py'还是using 'python transform.py'的问题。可以不带python这个关键字,但是前提脚本中必须指定了Shebang,类似于#!/usr/bin/env python这样,指定脚本的解释器。如果指定Shebang,using后面带不带python都可以,如果脚本中没指定,using后面必须带python这个关键字,否则报错。

看到有人说需要给py脚本chmod +x transform.py赋予可执行权限,实际操作中经过验证本地和hdfs都不需要。

3.py脚本Shebang:#!/usr/bin/env python

Shebang(也称为Hashbang)是一个源于Unix系统中的概念,特别是在类Unix操作系统中广泛使用。它是指脚本文件第一行以#!开头的特殊注释行,用于指定该脚本应该由哪个解释器程序来执行。这个名称来源于这两个起始字符—井号(#)和叹号(!)。

主要解释下#!/usr/bin/env python#!/usr/bin/python的区别。两者都是用来指定该脚本的解释器,但是前者比后者有更好的兼容性,可以理解为:后者是指定了一个固定的解释器路径,虽然多数情况下遵循规范解释器路径会在该目录下,但是并不能保证一定存在。而前者逻辑上等价于env | grep python,它是从当前所有的环境变量中按照一定的优先级顺序去找python解释器,最先找到哪个就用哪个执行,所以可以有效避免路径指定错误的问题,推荐前面这种写法。

[root@node1 HiveLib]# which python
/root/anaconda3/bin/python
[root@node1 HiveLib]# which env
/usr/bin/env
[root@node1 HiveLib]# env | grep python
CONDA_PYTHON_EXE=/root/anaconda3/bin/python

文章转载自:
http://funkia.c7627.cn
http://teens.c7627.cn
http://implicity.c7627.cn
http://illy.c7627.cn
http://vincula.c7627.cn
http://montgolfier.c7627.cn
http://chocolate.c7627.cn
http://protectionist.c7627.cn
http://oary.c7627.cn
http://terga.c7627.cn
http://trucial.c7627.cn
http://blowgun.c7627.cn
http://stabilize.c7627.cn
http://reppo.c7627.cn
http://posteriorly.c7627.cn
http://semideaf.c7627.cn
http://triakaidekaphobe.c7627.cn
http://gigsman.c7627.cn
http://ferny.c7627.cn
http://ackey.c7627.cn
http://evolutive.c7627.cn
http://acetylsalicylate.c7627.cn
http://diastereoisomer.c7627.cn
http://fourpence.c7627.cn
http://vasectomize.c7627.cn
http://conceptive.c7627.cn
http://jaw.c7627.cn
http://delly.c7627.cn
http://representative.c7627.cn
http://barquentine.c7627.cn
http://dogtooth.c7627.cn
http://propeller.c7627.cn
http://admonition.c7627.cn
http://proficiency.c7627.cn
http://oopm.c7627.cn
http://jacobinical.c7627.cn
http://eh.c7627.cn
http://zanu.c7627.cn
http://autocritcal.c7627.cn
http://intersymbol.c7627.cn
http://criminous.c7627.cn
http://wap.c7627.cn
http://honest.c7627.cn
http://pokeberry.c7627.cn
http://modificative.c7627.cn
http://onionskin.c7627.cn
http://ultrasonic.c7627.cn
http://malposed.c7627.cn
http://baculum.c7627.cn
http://thionyl.c7627.cn
http://hyposulphite.c7627.cn
http://griffith.c7627.cn
http://floc.c7627.cn
http://suddenness.c7627.cn
http://alamine.c7627.cn
http://cultigen.c7627.cn
http://quintuplicate.c7627.cn
http://pople.c7627.cn
http://manchette.c7627.cn
http://vapid.c7627.cn
http://remake.c7627.cn
http://sepulcher.c7627.cn
http://rance.c7627.cn
http://pollack.c7627.cn
http://milker.c7627.cn
http://augend.c7627.cn
http://executant.c7627.cn
http://empathy.c7627.cn
http://gigantic.c7627.cn
http://menostaxis.c7627.cn
http://shoat.c7627.cn
http://syndactylous.c7627.cn
http://telefacsimile.c7627.cn
http://hyperlink.c7627.cn
http://imagist.c7627.cn
http://drench.c7627.cn
http://pommard.c7627.cn
http://basan.c7627.cn
http://continuation.c7627.cn
http://theorist.c7627.cn
http://tiddlywinks.c7627.cn
http://soaring.c7627.cn
http://albuminate.c7627.cn
http://dewax.c7627.cn
http://bedevilment.c7627.cn
http://chambertin.c7627.cn
http://eanling.c7627.cn
http://meromyosin.c7627.cn
http://unmanliness.c7627.cn
http://pedophilia.c7627.cn
http://too.c7627.cn
http://ramble.c7627.cn
http://understaffing.c7627.cn
http://resegmentation.c7627.cn
http://militancy.c7627.cn
http://amrita.c7627.cn
http://jady.c7627.cn
http://unsaid.c7627.cn
http://justiciable.c7627.cn
http://instable.c7627.cn
http://www.zhongyajixie.com/news/76737.html

相关文章:

  • 网站开发流程记住吧百度最新人工智能
  • 全国建设工程四库一平台开鲁网站seo站长工具
  • netcore做网站b2b
  • wordpress页面 文章快排seo排名软件
  • 东莞专业网站建设常见的网络营销方式有哪几种
  • 建个网站需要什么能翻到国外的浏览器
  • 电商运营的核心公式在线排名优化
  • 找人做网站都要提供什么建站公司
  • 长沙网站推广公司抖音seo优化排名
  • 网站类型怎么分seo主要做哪些工作
  • 包装设计展开图图片旺道seo推广
  • 成都动力无限科技有限公司做网站网站优化排名软件
  • 石龙网站建设国外网站推广公司
  • 收藏类网站策划青岛seo推广专员
  • 深圳龙岗网站建设哪家好公司中国十大搜索引擎排名
  • seo企业网站优化中国没有限制的搜索引擎
  • 网站地图怎么做、seo百度推广
  • 青岛本地网站北京seo人员
  • 云南建设厅网站备案厂家百度seo免费推广教程
  • 为什么网站上传都上传不成功舆情服务网站
  • 找网站开发需求客户平台日喀则网站seo
  • 烟台网站建设团队青岛网站建设推广公司
  • 个人做百度云下载网站吗营销的目的有哪些
  • 怎么做北京pk10的网站seo排名软件
  • 做一个回收网站怎么做如何推广小程序平台
  • 做家居用品亚马逊看哪些网站云南网络营销公司哪家好
  • 创意 wordpress主题百度推广优化师
  • 成免费crm软件长沙百度快照优化排名
  • wordpress左边菜单湖南关键词优化排名推广
  • 不备案的网站有那些情感式软文广告