目录
1、hive基本数据类型
2、数据类型
2.1实例:创建不同数据类型的表
create table test(
name string,
friends array<string>,
children map<string, int>,
address struct<street:string, city:string>
)
row format delimited fields terminated by ','
collection items terminated by '_'
map keys terminated by ':'
lines terminated by '\n';
字段解释:
row format delimited fields terminated by ',' -- 列分隔符
collection items terminated by '_' --MAP STRUCT 和 ARRAY 的分隔符(数据分割符号)
map keys terminated by ':'
-- MAP 中的 key 与 value 的分隔符
lines terminated by '\n'; -- 行分隔符
实例:
首先准备数据:新建测试文件test.txt
加载本地文件数据到hive表
load data local inpath '/usr/local/apache-hive-1.2.1-bin/test.txt' into table test;
查看内容
不同结构访问方式
3、数据库和表的操作
3.1、数据库的操作
hive数据库在HDFS上默认存储路径:/user/hive/warehouse/*.db
use db_hive; --切换数据库;
create database db_hive; --创建数据库
create database if not exists db_hive ; --标准写法:避免数据库已经存在,if not exists用来判断数据库是否存在
show databases like 'db_*'; --模糊查找数据库
create database db_hive location '/db_hive.db'; --指定数据库在hdfs上的存放路径
show