大数据学习——hive函数
1 内置函数
测试各种内置函数的快捷方法:
1、创建一个dual表
create table dual(id string);
2、load一个文件(一行,一个空格)到dual表
3、select substr('angelababy',2,3) from dual;
2 自定义函数UDF(user-defined function)和transform
自定义函数类别
UDF 作用于单个数据行,产生一个数据行作为输出。(数学函数,字符串函数)
UDAF(用户定义聚集函数):接收多个输入数据行,并产生一个输出数据行。(count,max)
UDTF(User-Defined Table-Generating Functions),一进多出(输入一行,输出多行),比如:collect_set()、collect_list()
1、先开发一个java类,继承UDF,并重载evaluate方法
package cn.itcast.bigdata.udf
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text; public final class Lower extends UDF{
public Text evaluate(final Text s){
if(s==null){return null;}
return new Text(s.toString().toLowerCase());
}
}
2、打成jar包上传到服务器
3、将jar包添加到hive的classpath
add JAR /home/hadoop/udf.jar;
4、创建临时函数与开发好的java class关联
create temporary function tolowercase as 'cn.itcast.bigdata.udf.ToProvince';
5、即可在hql中使用自定义的函数tolowercase ip
Select tolowercase(name),age from t_test;
大数据学习——hive函数的更多相关文章
- 大数据学习——hive基本操作
1 建表 create table student(id int,name string ,age int) row format delimitedfields terminated by ','; ...
- 大数据学习——hive数据类型
1. hive的数据类型Hive的内置数据类型可以分为两大类:(1).基础数据类型:(2).复杂数据类型2. hive基本数据类型基础数据类型包括:TINYINT,SMALLINT,INT,BIGIN ...
- 大数据学习——hive的sql练习
1新建一个数据库 create database db3; 2创建一个外部表 --外部表建表语句示例: create external table student_ext(Sno int,Sname ...
- 大数据学习——hive显示命令
show databases; desc t_partition001; desc extended t_partition002; desc formatted t_partition002; !c ...
- 大数据学习——hive安装部署
1上传压缩包 2 解压 tar -zxvf apache-hive-1.2.1-bin.tar.gz -C apps 3 重命名 mv apache-hive-1.2.1-bin hive 4 设置环 ...
- 大数据学习——scala函数与方法
package com /** * Created by Administrator on 2019/4/8. */ object TestMap { def ttt(f: Int => Int ...
- 大数据学习——hive的sql练习题
ABC三个hive表 每个表中都只有一列int类型且列名相同,求三个表中互不重复的数 create table a(age int) row format delimited fields termi ...
- 大数据学习——hive数仓DML和DDL操作
1 创建一个分区表 create table t_partition001(ip string,duration int) partitioned by(country string) row for ...
- 大数据学习——hive使用
Hive交互shell bin/hive Hive JDBC服务 hive也可以启动为一个服务器,来对外提供 启动方式,(假如是在itcast01上): 启动为前台:bin/hiveserver2 启 ...
随机推荐
- 【loj6034】「雅礼集训 2017 Day2」线段游戏
#6034. 「雅礼集训 2017 Day2」线段游戏 内存限制:256 MiB 时间限制:1000 ms 标准输入输出 题目类型:传统 评测方式:Special Judge 上传者: 匿名 题目描述 ...
- ForeignKeyConstraint 外键约束的使用及作用的学习[转]
原文链接 da.SelectCommand.CommandText="select au_id,au_fname,au_lname from authors"; da.Fill(d ...
- python关于文件的一些记录
1.文件打开: file("data.txt")或open("data.txt")注意不要漏了文件的后缀.(不加参数时,file为你默认为'r',reading ...
- 一个因xdata声明引起的隐含错误
我们知道一般增强型c51自身的RAM只有128BYTES,根本不够用,所以一般在定义全局变量,静态变量时都要用XDATA作为关键字修饰数据的的存储类型.但要注意的是,定义和声明一定要一致,不然出现错误 ...
- Log4net系列一:Log4net搭建之文本格式输出
Log4net简介 前言 项目开发中,记录项目日志是必须的,如果非要说日志的重要性(日志可看做,飞机的黑匣子,或者汽车的行车记录仪),根据等级进行记录,方便我们排查相关问题,以后项目运维中,也方便很多 ...
- iOS面试题之runloop
本文围绕以下几个部分展开对runloop的叙述. 1.runloop是什么/runloop的概念? 2.NSRunLoop 和 CFRunLoopRef? 3.runloop和线程的关系? 4.run ...
- springdata-jpa 八种查询方法
使用:maven+Spring+jpa+Junit4 查询方式:SQL,JPQL查询,Specification多条件复杂查询 返回类型:list<POJO>,list<Stinrg ...
- 7z解压参数
7z.exe x D:/test/dwpath/xxx.zip -oD:/test/dwpath/ -aoa
- Elasticsearch 插入地理索引文档一直为空
今天在获取插入索引数据的时候,一直提示插入不成功,尝试了很多方法,原来是因为在插入的时候应该先 插入Latitude后插入longitude修改后的代码如下 public boolean insert ...
- HttpClient 接口调用
String url = "http://127.0.0.1:8080/api"; //然后根据表名获取公司信息 HttpPost httppost = new HttpPost( ...