美文网首页
Hive基本命令整理

Hive基本命令整理

作者: 先生_吕 | 来源:发表于2016-12-29 18:28 被阅读205次

创建表:
Hive> CREATE TABLE pokes (foo INT, bar STRING);
Creates a table called pokes with two columns, the first being an integer and the other a string

创建一个新表,结构与其他一样
hive> create table new_table like records;

创建分区表:
hive> create table logs(ts bigint,line string) partitioned by (dt String,country String);

加载分区表数据:
hive> load data local inpath '/home/Hadoop/input/hive/partitions/file1' into table logs partition (dt='2001-01-01',country='GB');

展示表中有多少分区:
hive> show partitions logs;

展示所有表:
hive> SHOW TABLES;
lists all the tables
hive> SHOW TABLES '.*s';

显示表的结构信息
hive> DESCRIBE invites;
shows the list of columns

更新表的名称:
hive> ALTER TABLE source RENAME TO target;

添加新一列
hive> ALTER TABLE invites ADD COLUMNS (new_col2 INT COMMENT 'a comment');

删除表:
hive> DROP TABLE records;

删除表中数据,但要保持表的结构定义
hive> dfs -rmr /user/hive/warehouse/records;

从本地文件加载数据:
hive> LOAD DATA LOCAL INPATH '/home/hadoop/input/ncdc/micro-tab/sample.txt' OVERWRITE INTO TABLE records;

显示所有函数:
hive> show functions;

查看函数用法:
hive> describe function substr;

查看数组、map、结构
hive> select col1[0],col2['b'],col3.c from complex;

内连接:
hive> SELECT sales., things. FROM sales JOIN things ON (sales.id = things.id);

查看hive为某个查询使用多少个MapReduce作业
hive> Explain SELECT sales., things. FROM sales JOIN things ON (sales.id = things.id);

外连接:
hive> SELECT sales., things. FROM sales LEFT OUTER JOIN things ON (sales.id = things.id);
hive> SELECT sales., things. FROM sales RIGHT OUTER JOIN things ON (sales.id = things.id);
hive> SELECT sales., things. FROM sales FULL OUTER JOIN things ON (sales.id = things.id);

in查询:Hive不支持,但可以使用LEFT SEMI JOIN
hive> SELECT * FROM things LEFT SEMI JOIN sales ON (sales.id = things.id);

Map连接:Hive可以把较小的表放入每个Mapper的内存来执行连接操作
hive> SELECT /+ MAPJOIN(things) / sales., things. FROM sales JOIN things ON (sales.id = things.id);

INSERT OVERWRITE TABLE ..SELECT:新表预先存在
hive> FROM records2

INSERT OVERWRITE TABLE stations_by_year SELECT year, COUNT(DISTINCT station) GROUP BY year
INSERT OVERWRITE TABLE records_by_year SELECT year, COUNT(1) GROUP BY year
INSERT OVERWRITE TABLE good_records_by_year SELECT year, COUNT(1) WHERE temperature != 9999 AND (quality = 0 OR quality = 1 OR quality = 4 OR quality = 5 OR quality = 9) GROUP BY year;

CREATE TABLE ... AS SELECT:新表表预先不存在
hive>CREATE TABLE target AS SELECT col1,col2 FROM source;

创建视图:
hive> CREATE VIEW valid_records AS SELECT * FROM records2 WHERE temperature !=9999;

查看视图详细信息:
hive> DESCRIBE EXTENDED valid_records;

HIVE.png

相关文章

  • Hive基本命令整理

    创建表:Hive> CREATE TABLE pokes (foo INT, bar STRING);Create...

  • Hive运行方式

    1.最基本的hive命令行; Linux命令行直接hive 进入hive 命令行; 2.脚本运行方式(适用于生产环...

  • Hive 基本命令

    进入Hive 打开终端: 创建表 向表里插入数据 检查文件内容 将文件内容导入到对应的表a. 在该文件的目录下,进...

  • hive基本操作整理

    1.hive模糊搜索表 show tables like '*name*'; 2.查看表结构信息 desc for...

  • Hive常用的几种交互操作

    查看hive下的交互命令方式 -help(hive 外) 命令:bin/hive -helpusage: hive...

  • 大数据开发之Hive优化篇2-Hive的explain命令

    备注:Hive 版本 2.1.1 一.Hive explain命令概述 Hive的explain命令用来看Hive...

  • HiveQL快速使用

    hive命令包括Hive cli 和 hiveQL命令 Hive cli cli 就是命令行界面,可以通过cli创...

  • Hive进阶

    hive配置,命令 hive查询显示列名 hive默认分隔符 \001 hive命令行中查看当前hive环境变量 ...

  • hive shell基本命令

    查看表操作 内部表 创建内部表CREATE TABLE t1 (id int,ms string)ROW FORM...

  • HIVE

    基础命令 基本DDL 内部表与外部表的区别 Hive 创建内部表时,会将数据移动到数据仓库指向的路径; Hive ...

网友评论

      本文标题:Hive基本命令整理

      本文链接:https://www.haomeiwen.com/subject/gpjpvttx.html