码迷,mamicode.com
首页 > 其他好文 > 详细

hive

时间:2016-10-31 13:37:38      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:cal   default   com   oca   where   table   hdf   覆盖   overwrite   

hive包:hive-2.1.0

安装:

1、解压缩

2、重命名hive-default.xml.template 为hive-default.xml

3、./schematool -initSchema -dbType derby初始化数据

 

进入hive命令行:

./bin/hive

显示数据库

show databases;

创建数据库

 create database test;

使用数据库:

use test;

显示数据库中的表

show tables;

创建表

CREATE TABLE pokes (foo INT, bar STRING);

创建分区表

CREATE TABLE invites (foo INT, bar STRING) PARTITIONED BY (ds STRING);

通过正则表达式查看表

SHOW TABLES ‘.*s‘;

查看表的结构

describe pokes;

更新表的名称

 alter table pokes rename to pokes2;

给表添加一列 

 alter table pokes2 add columns (new_col int);

给表添加一列,并对列添加注释

alter table pokes2 add columns (new_col_2 int comment "new column");

删除表:

drop table pokes2;

 

为了后面的测试先创建一个表:create table test(name string, age int);

 加载本地数据到表中:

load data local inpath ‘./1.txt‘ into table test; 
local代表加载本地数据,如果没有则代表加载HDFS的数据
加载本地数据到表中并覆盖原来的数据:
load data local inpath ‘./1.txt‘ overwrite into table test;

 overwrite表示覆盖原来的数据

 

创建一个分区表: create table p_test(name string, age int) partitioned by (year string);

加载数据到分区表:

load data local inpath ‘./1.txt‘ overwrite into table test partition (year=‘2016‘);

查询某一分区的数据(where)

select * from p_test where year = ‘2016‘;

查询数据:

select name from test;

把查询的结果存储在HDFS上:

insert overwrite  directory ‘/2.txt‘ select * from test;

 

hive

标签:cal   default   com   oca   where   table   hdf   覆盖   overwrite   

原文地址:http://www.cnblogs.com/heml/p/6004745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!