hive命令2
1.创建表–stud:表名 retail–数据库名
create external table stud(
fname string,
lname string,
address struct (houseno:string, street:string, city:string), //这一行用()代替<>,<>代码不显示
active boolean,
create date,
location ‘/opt/stud’);
2.可以在数据库中直接创建一个表
在表名前加上数据库名
create external table retail.stud()
3.列出表
show tables in retail
4.如果数据库中有很多表,可以用通配符搜索特定的表
5.外部表,其在被删除时,数据保留,在create table 中使用
external关键字来创建外部表
create external table retail.stud()
6.内部表,其在被删除时,数据不保留
create table retail.stud()
7.查看表内容
select * from stud;
8.查看表的模式,其中在table type中指明表是否是内部表(外部表)
describe formatted stud;
9.表的属性
(1)last_modified_user
(2)last_modified_time
(3)immutable
(4)orc.compress
(5)skip.header.line.count
(1)(2)属性可控,由hive自动增加,hive通过它们
将上次修改的用户和时间信息存放在metastore中
(3)当immutable属性设置为true,此时一个表里已经有一些数据了,则无法
在向其插入新行,强行插入,会报错
insert into text1 values (‘bacon’);
failed: SemanticException…immutable table is not allowed text1
(4)orc.compress属性用于指定基于orc的存储所采用的算法
(5)skip.header.line.count
使用该属性,可以跳过底层数据文件的标题行
例子,如果一个文件中有2个标题行,那么跳过标题行写法如下
create external table stud (states string) location ‘/opt/stud’
tblproperties(“skip.header.line.count” = “2”);
此时创建的新表,再次查询时就会跳过2个标题行来显示文件内容