1. hive的数据类型
Hive的内置数据类型可以分为两大类:(1)、基础数据类型;(2)、复杂数据类型
2. hive基本数据类型
基础数据类型包括:TINYINT,SMALLINT,INT,BIGINT,BOOLEAN,FLOAT,DOUBLE,STRING,BINARY,TIMESTAMP,DECIMAL,CHAR,VARCHAR,DATE。

3. hive集合类型
集合类型主要包括:array,map,struct等,hive的特性支持集合类型,这特性是关系型数据库所不支持的,利用好集合类型可以有效提升SQL的查询速率。
3.1 集合类型之array
(1) 先创建一张表

create table t_array(id int,name string,hobby array<string>)
row format delimited
fields terminated by ','
collection items terminated by '-';

(2) 准备数据文件 array.txt

1,zhangsan,唱歌-跳舞-游泳
2,lisi,打游戏-篮球

(2) 加载数据文件到t_array表中

load data local inpath '/root/array.txt' into table t_array;

(3) 查询数据

select id ,name,hobby[],hobby[] from t_array;

注意:array的访问元素和java中是一样的,这里通过索引来访问。

3.2 集合类型之map

(1) 先创建一张表

create table t_map(id int,name string,hobby map<string,string>)
row format delimited
fields terminated by ','
collection items terminated by '-'
map keys terminated by ':' ;

(2) 准备数据文件 map.txt

1,zhangsan,唱歌:非常喜欢-跳舞:喜欢-游泳:一般般
2,lisi,打游戏:非常喜欢-篮球:不喜欢

(2) 加载数据文件到t_map表中

load data local inpath '/root/map.txt' into table t_map;

(3) 查询数据

select id,name,hobby['唱歌'] from t_map;

注意:map的访问元素中的value和java中是一样的,这里通过key来访问。

3.3集合类型之struct

(1) 先创建一张表

create table t_struct(id int,name string,address struct<country:string,city:string>)
row format delimited
fields terminated by ','
collection items terminated by '-';

(2) 准备数据文件 struct.txt

1,zhangsan,china-beijing
2,lisi,USA-newyork

(2) 加载数据文件到t_struct表中

load data local inpath  '/root/struct.txt'  into table t_struct;

(3) 查询数据

select id,name,address.country,address.city from t_struct;

总结:struct访问元素的方式是通过.符号

大数据学习——hive数据类型的更多相关文章

  1. 大数据学习——hive基本操作

    1 建表 create table student(id int,name string ,age int) row format delimitedfields terminated by ','; ...

  2. 大数据学习——hive函数

    1 内置函数 测试各种内置函数的快捷方法: 1.创建一个dual表 create table dual(id string); 2.load一个文件(一行,一个空格)到dual表 3.select s ...

  3. 大数据学习——hive的sql练习

    1新建一个数据库 create database db3; 2创建一个外部表 --外部表建表语句示例: create external table student_ext(Sno int,Sname ...

  4. 大数据学习——hive显示命令

    show databases; desc t_partition001; desc extended t_partition002; desc formatted t_partition002; !c ...

  5. 大数据学习——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 设置环 ...

  6. 大数据学习——hive的sql练习题

    ABC三个hive表 每个表中都只有一列int类型且列名相同,求三个表中互不重复的数 create table a(age int) row format delimited fields termi ...

  7. 大数据学习——hive数仓DML和DDL操作

    1 创建一个分区表 create table t_partition001(ip string,duration int) partitioned by(country string) row for ...

  8. 大数据学习——hive使用

    Hive交互shell bin/hive Hive JDBC服务 hive也可以启动为一个服务器,来对外提供 启动方式,(假如是在itcast01上): 启动为前台:bin/hiveserver2 启 ...

  9. 大数据学习day26----hive01----1hive的简介 2 hive的安装(hive的两种连接方式,后台启动,标准输出,错误输出)3. 数据库的基本操作 4. 建表(内部表和外部表的创建以及应用场景,数据导入,学生、分数sql练习)5.分区表 6加载数据的方式

    1. hive的简介(具体见文档) Hive是分析处理结构化数据的工具   本质:将hive sql转化成MapReduce程序或者spark程序 Hive处理的数据一般存储在HDFS上,其分析数据底 ...

随机推荐

  1. 线段树(单点更新) POJ 2828 Buy tickets

    题目传送门 /* 结点存储下面有几个空位 每次从根结点往下找找到该插入的位置, 同时更新每个节点的值 */ #include <cstdio> #define lson l, m, rt ...

  2. SpringMVC之基于注解的Controller

    参考博客:https://www.cnblogs.com/qq78292959/p/3760560.html Controller注解: 传统风格的Controller需要实现Controller接口 ...

  3. [已读]Sass与Compass实战

    介绍了Sass基础语法与Compass框架,这个网上参考文档就OK了,另外介绍了compass生成图片精灵和相应的css,貌似现在单纯用sass和compass的挺少,要不grunt,要不FIS,而g ...

  4. Backbone学习记录(2)

    创建一个集合 1)new Backbone.Collection()方式 var user=new Backbone.Model({'name':'susan'}); var list=new Bac ...

  5. Suricata的性能

    不多说,直接上干货! 见官网 https://suricata.readthedocs.io/en/latest/performance/index.html Docs » 7. Performanc ...

  6. idea web项目热部署

    之前用idea写web项目的时候,一直都是改一点东西就要重启一下,很烦.今天终于忍受不了百度了一下idea怎么热部署web项目. 在此记录下. 第一步 编辑tomcat配置 第二步 选择打包的项目,并 ...

  7. html制作简单框架网页二 实现自己的影音驿站 操作步骤及源文件下载 (可播放mp4、avi、mpg、asx、swf各种文件的视频播放代码)

    新增视频播放功能如下图: 左侧网页left.html代码如下: <meta charset="utf-8"> <body style="backgrou ...

  8. redis集群架构(含面试题解析)

    老规矩,我还是以循序渐进的方式来讲,我一共经历过三套集群架构的演进! Replication+Sentinel 这套架构使用的是社区版本推出的原生高可用解决方案,其架构图如下! 这里Sentinel的 ...

  9. 云原生技术图谱 (CNCF Landscape)

    转自:https://raw.githubusercontent.com/cncf/landscape/master/landscape/CloudNativeLandscape_latest.jpg

  10. 图解在Ubuntu16.04中安装MySQL

    1.安装mysql-server sudo apt-get install mysql-server 输入y,回车.等待下载,安装 出现下图,需要设定Mysql的密码. 输入密码,回车,弹出确认对话框 ...