hive命令2

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个标题行来显示文件内容

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值