HIVE 第二章 目录和表

1.目录篇

创建表目录

create database companys

create database companys location  table

create database companys location table with dbproperties('name'='kedde','data'='2012-01-02')

查看database信息,无法查看当前表目录

describe database companys

describe database extended companys

改变默认的表目录

use companys

删除表目录

drop database financials

修改表目录属性,无法删除表属性

alter database financials setdbproperties('owner'='dirk')

2.表篇

新建表 mydb必须是存在的,location可以不存在,hive会新建

CREATE TABLE IF NOT EXISTS mydb.employees (

name STRING COMMENT 'Employee name',

salary FLOAT COMMENT 'Employee salary',

subordinates ARRAY<STRING> COMMENT 'Names of subordinates',

deductions MAP<STRING, FLOAT>

COMMENT 'Keys are deductions names, values are percentages',

address STRUCT<street:STRING, city:STRING, state:STRING, zip:INT>

COMMENT 'Home address')

COMMENT 'Description of the table'

TBLPROPERTIES ('creator'='me', 'created_at'='2012-01-02 10:00:00', ...)

LOCATION '/user/hive/warehouse/mydb.db/employees';

新建表,copy已有表结构schema,不包含数据

create table if not exists mydb.empoyees link mydb.employees;

查看表

show tables;

show tables in companys;

show tables 'emp.*'; #注意是.*

查看表信息

describe extended companys.tables;

规定分隔符为/t

row format delimited fields terminated by '/t';

猜你喜欢

转载自blackproof.iteye.com/blog/1797936