表 Hive的基本数据类型:
类型 |
描述 |
示例 |
TINYINT |
1个字节(8位)有符号整数 |
1 |
SMALLINT |
2个字节(16位)有符号整数 |
1 |
INT |
4个字节(32位)有符号整数 |
1 |
BIGINT |
8个字节(64位)有符号整数 |
1 |
FLOAT |
4个字节(32位)单精度浮点数 |
1.0 |
DOUBLE |
8个字节(64位)双精度浮点数 |
1.0 |
BOOLEAN |
布尔类型,true/false |
true |
STRING |
字符串,可以指定字符集 |
“xmu” |
TIMESTAMP |
整数、浮点数或者字符串 |
1327882394(Unix新纪元秒) |
BINARY |
字节数组 |
[0,1,0,1,0,1,0,1] |
ARRAY |
一组有序字段,字段的类型必须相同 |
Array(1,2) |
MAP |
一组无序的键/值对,键的类型必须是原子的,值可以是任何数据类型,同一个映射的键和值的类型必须相同 |
Map(‘a’,1,’b’,2) |
STRUCT |
一组命名的字段,字段类型可以不同 |
Struct(‘a’,1,1,0) |
Hive的基本操作:
1.create: 创建数据库、表、视图
hive>create database hive;
hive>create database if not exists hive;
hive> use hive;
hive>create table if not exists usr(idbigint,name string,age int);
hive>create table if not existshive.usr(id bigint,name string,age int)
>location ‘/usr/local/hive/warehouse/hive/usr’;
hive>createview little_usr as select id,age from usr;
2. show:查看数据库、表、视图
hive> show databases;
hive>show databases like ‘h.*’;
hive> use hive;
hive> show tables;
hive> show tables in hive like ‘u.*’;
3.load:向表中装载数据
hive> load data local inpath ‘/usr/local/data’ overwrite into tableusr;
hive> load data local inpath ‘/usr/local/data’ into tableusr;
hive> load data inpath ‘hdfs://master_server/usr/local/data’
>overwrite into table usr;
4.insert:向表中插入数据或从表中导出数据
hive> insert overwrite table usr1
> select * from usrwhere age=10;
hive> insert into table usr1
> select * from usr
> where age=10;