hive

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;
原文地址:https://www.cnblogs.com/heml/p/6004745.html