设为首页 加入收藏

TOP

hive——2.使用
2019-04-22 00:58:13 】 浏览:49
Tags:hive 使用

启动hive:

启动hadoop:start-all.sh

启动hive:hive

[root@hadoop01 ~]# hive

hive>

DDL操作:

创建表:

create命令

hive> create table student(id bigint,name string,age int);

OK

Time taken: 0.945 seconds

hive>

查看表:

show命令

hive> show tables;

OK

student

Time taken: 0.074 seconds,

Fetched: 1 row(s)

hive>

查看以t结尾的表:

hive> SHOW TABLES '.*t';

OK student

Time taken: 0.016 seconds,

Fetched: 1 row(s)

hive>

查看表的结构:

hive> describe student;

OK

id bigint

name string

age int

Time taken: 0.1 seconds,

Fetched: 3 row(s)

hive>

改变表:

alter命令

改表名:

hive> alter table student rename to stu;

加列:

hive> alter table stu add columns (birthplace string);

修改列:(没仔细研究)

hive> alter table stu replace columns (birthplace string,home string,id int,name string);

OK

Time taken: 0.246 seconds

hive>

请注意,REPLACE COLUMNS将替换所有现有列,仅更改表的架构,而不是数据。该表必须使用native SerDe。

REPLACE COLUMNS也可用于从表的模式中删除列。

删除表:

drop table stu;

元数据存储:

元数据默认存储在Derby数据库中,其磁盘存储位置在hive-site.xml中配置,javax.jdo.option.ConnectionURL。

加载数据:

1.将本地或hdfs文件中的数据加载到Hive中:

hive> LOAD DATA LOCAL INPATH'./examples/files/kv1.txt'OVERWRITE INTO TABLE pokes;

hive> LOAD DATA INPATH '/user/myname/kv2.txt' OVERWRITE INTO TABLE invites PARTITION (ds='2008-08-15');

类sql语句:

参考hive官网:

https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-RunningHiveCLI

遇到的错误:

1.在hive中执行sql语句报错:

SemanticException org.apache.hadoop.hive.ql.metadata.HiveException

解决:

参考:https://blog.csdn.net/xiaoqiu_cr/article/details/80913437

重新初始化元数据,再启动hive即可

[root@hadoop01 ~]# schematool -dbType mysql -initSchema

[root@hadoop01 ~]# hive

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MetaException(message:Hive Sche.. 下一篇spark on hive原理与环境搭建 &nb..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目