1.1. 数据类型

1.1.1.  数字类型

TINYINT (1-bytesigned integer, from -128 to 127)

SMALLINT (2-bytesigned integer, from -32,768 to 32,767)

INT/INTEGER(4-byte signed integer, from -2,147,483,648 to 2,147,483,647)

BIGINT (8-bytesigned integer,from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)

FLOAT (4-byte single precisionfloating point number)

DOUBLE (8-byte double precisionfloating point number)

示例:

create table t_test(a string,b int,c bigint,d float,e double,f tinyint,g smallint)

1.1.2.  日期时间类型

TIMESTAMP (Note:Only available starting with Hive 0.8.0)

DATE (Note:Only available starting with Hive 0.12.0)

示例,假如有以下数据文件:

1,zhangsan,1985-06-30

2,lisi,1986-07-10

3,wangwu,1985-08-09

那么,就可以建一个表来对数据进行映射

create table t_customer(id int,namestring,birthday date)

row format delimited fields terminated by',';

然后导入数据

load data local inpath '/root/customer.dat'into table t_customer;

然后,就可以正确查询

1.1.3.  字符串类型

STRING

VARCHAR (Note:Only available starting with Hive 0.12.0)

CHAR (Note:Only available starting with Hive 0.13.0)

1.1.4.  混杂类型

BOOLEAN

BINARY (Note: Only available startingwith Hive 0.8.0)

1.1.5.  复合类型

1.1.5.1.          array数组类型

arrays: ARRAY<data_type> (Note:negative values and non-constant expressions are allowed as of Hive 0.14.)

示例:array类型的应用

假如有如下数据需要用hive的表去映射:

钢铁侠3,唐尼:小辣椒:哈皮,2013-05-04

蜘蛛侠英雄归来,荷兰弟:唐尼,2017-07-07

设想:如果主演信息用一个数组来映射比较方便

建表:

create tablet_movie(moive_name string,actors array<string>,first_show date)

row formatdelimited fields terminated by ','

collection itemsterminated by ':';

导入数据:

load data local inpath '/root/movie.dat'into table t_movie;

查询:

select * from t_movie;

select moive_name,actors[0] from t_movie;

select moive_name,actors from t_movie where array_contains(actors,'唐尼');

select moive_name,size(actors) fromt_movie;

1.1.5.2.          map类型

maps: MAP<primitive_type,data_type> (Note: negative values and non-constant expressions areallowed as of Hive 0.14.)

1)       假如有以下数据:

1,zhangsan,father:xiaoming#mother:xiaohuang#brother:xiaoxu,28

2,lisi,father:mayun#mother:huangyi#brother:guanyu,22

3,wangwu,father:wangjianlin#mother:ruhua#sister:jingtian,29

4,mayun,father:mayongzhen#mother:angelababy,26

可以用一个map类型来对上述数据中的家庭成员进行描述

2)       建表语句:

create table t_person(id int,name string,family_members map<string,string>,age int)

row format delimited fields terminated by','

collection items terminated by '#'

map keys terminated by':';

3)       查询

select * from t_person;

## 取map字段的指定key的值

select id,name,family_members['father'] asfather from t_person;

## 取map字段的所有key

select id,name,map_keys(family_members) asrelation from t_person;

## 取map字段的所有value

select id,name,map_values(family_members)from t_person;

select id,name,map_values(family_members)[0]from t_person;

## 综合:查询有brother的用户信息

select id,name,father

from

(select id,name,family_members['brother'] as father from t_person) tmp

where father is not null;

1.1.5.3.          struct类型

structs: STRUCT<col_name :data_type, ...>

1)       假如有如下数据:

1,zhangsan,18:male:beijing

2,lisi,28:female:shanghai

其中的用户信息包含:年龄:整数,性别:字符串,地址:字符串

设想用一个字段来描述整个用户信息,可以采用struct

2)       建表:

create table t_person_struct(id int,namestring,info struct<age:int,sex:string,addr:string>)

row format delimited fields terminatedby ','

collection items terminated by ':';

3)       查询

select * from t_person_struct;

select id,name,info.agefrom t_person_struct;

1.2. 修改表定义

仅修改Hive元数据,不会触动表中的数据,用户需要确定实际的数据布局符合元数据的定义。

修改表名:

ALTER TABLE table_name RENAME TOnew_table_name

示例:alter table t_1 rename to t_x;

修改分区名:

alter table t_partitionpartition(department='xiangsheng',sex='male',howold=20) rename topartition(department='1',sex='1',howold=20);

添加分区:

alter table t_partition addpartition (department='2',sex='0',howold=40);

删除分区:

alter table t_partition droppartition (department='2',sex='2',howold=24);

修改表的文件格式定义:

ALTER TABLE table_name [PARTITIONpartitionSpec] SET FILEFORMAT file_format

alter table t_partitionpartition(department='2',sex='0',howold=40 ) set fileformat sequencefile;

修改列名定义:

ALTER TABLE table_name CHANGE[COLUMN] col_old_name col_new_name column_type [COMMENTcol_comment][FIRST|(AFTER column_name)]

alter table t_user change price jiage floatfirst;

增加/替换列:

ALTER TABLE table_nameADD|REPLACE COLUMNS (col_name data_type[COMMENT col_comment], ...)

alter table t_user add columns (sexstring,addr string);

alter table t_user replace columns (idstring,age int,price float);

HIVE精炼笔记总结——[类型篇]相关推荐

  1. HIVE精炼笔记总结——[建导篇]

    1. hive建库建表与数据导入 1.1. 建库 hive中有一个默认的库: 库名: default 库目录:hdfs://hdp20-01:9000/user/hive/warehouse 新建库: ...

  2. 完结篇 | 吴恩达deeplearning.ai专项课程精炼笔记全部汇总

    红色石头的个人网站:redstonewill.com 从去年8月份开始,AI界大IP吴恩达在coursera上开设了由5们课组成的深度学习专项课程,掀起了一股人工智能深度学习热潮.这里附上deeple ...

  3. 完结篇 | 吴恩达《序列模型》精炼笔记(3)-- 序列模型和注意力机制

    AI有道 不可错过的AI技术公众号 关注 1 Basic Models Sequence to sequence(序列)模型在机器翻译和语音识别方面都有着广泛的应用.下面,我们来看一个机器翻译的简单例 ...

  4. flink1.12.0学习笔记第2篇-流批一体API

    flink1.12.0学习笔记第 2 篇-流批一体API flink1.12.0学习笔记第1篇-部署与入门 flink1.12.0学习笔记第2篇-流批一体API flink1.12.0学习笔记第3篇- ...

  5. 吴恩达《Machine Learning》精炼笔记 12:大规模机器学习和图片文字识别 OCR

    作者 | Peter 编辑 | AI有道 系列文章: 吴恩达<Machine Learning>精炼笔记 1:监督学习与非监督学习 吴恩达<Machine Learning>精 ...

  6. 吴恩达《Machine Learning》精炼笔记 10:异常检测

    作者 | Peter 编辑 | AI有道 系列文章: 吴恩达<Machine Learning>精炼笔记 1:监督学习与非监督学习 吴恩达<Machine Learning>精 ...

  7. 吴恩达《Machine Learning》精炼笔记 6:关于机器学习的建议

    作者 | Peter 编辑 | AI有道 系列文章: 吴恩达<Machine Learning>精炼笔记 1:监督学习与非监督学习 吴恩达<Machine Learning>精 ...

  8. 力荐 | 吴恩达《序列模型》精炼笔记(1)-- 循环神经网络(RNN)

    AI有道 不可错过的AI技术公众号 关注 序列模型(Recurrent Neural Networks)是Andrw Ng深度学习专项课程中的第五门课,也是最后一门课.这门课主要介绍循环神经网络(RN ...

  9. 吴恩达《卷积神经网络》精炼笔记(2)-- 深度卷积模型:案例研究

    AI有道 不可错过的AI技术公众号 关注 1 Why Look at Case Studies 本文将主要介绍几个典型的CNN案例.通过对具体CNN模型及案例的研究,来帮助我们理解知识并训练实际的模型 ...

最新文章

  1. BZOJ2738 矩阵乘法 【整体二分 + BIT】
  2. 【Android 高性能音频】Oboe 音频流打开后 耳机 / 音箱 插拔事件处理 ( 设置 Oboe 音频设备 ID | setDeviceId 函数原型 | AudioStream 音频流 )
  3. linux文本文件和win文本文件的格式互换
  4. java类继承语法_java类的继承(基础)
  5. 18个C/C++的基本知识点,带好小本子记录一下
  6. python自定义修饰器_Python概述
  7. 解析对偶理论与对偶单纯性法
  8. 如何避免开源安全噩梦?
  9. 轻芒 CEO 王俊煜:高品质内容是核心,小程序是它的最好载体
  10. php设计模式总结-单件模式
  11. [转载] numpy.ma详解
  12. Java开发工程师,每个阶段需要掌握什么重点?
  13. rtx web 分级管理系统 二次开发
  14. VRF-Virtual Routing Forwarding
  15. python求字典的平均值_获取字典列表中值的平均值
  16. 算法实践——数独的基本解法
  17. 1万字精讲,这你还学不废?Python爬取腾讯视频《斛珠夫人》弹幕,并转换成词云(单线程)——爬虫实例2
  18. H5兼容问题及解决方法
  19. 神秘感十足的磁悬浮盆栽,敢不敢剁手来一款?
  20. 如何入驻拼多多商城 拼多多入驻形式有那些

热门文章

  1. Clenshaw–Curtis quadrature
  2. 使用计算机处理信息 一般要经历,高一信息技术课程总复习
  3. 职称考试 计算机 xp,全国计算机职称考试XP题库及答案[1][1].docx
  4. 多重背包问题与分组背包
  5. Code::Blocks介绍
  6. 2019/03/20 格林威治时间(Tue Jan 01 00:00:00 CST 2019)[ Date ]转化 为 [ 2019-01-01 10:10:10 ]
  7. java document创建节点_javasript 的DOM 节点操作:创建,插入,删除,复制以及查找节点...
  8. 卷积神经网络pytorch_使用PyTorch和卷积神经网络进行动物分类
  9. android 从手机自带图库选取图片作为应用背景图
  10. 【论文阅读】TranAD: Deep Transformer Networks for Anomaly Detection inMultivariate Time Series Data