Hive基本命令整理

news/2024/7/7 21:42:32

创建表:
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';

lists all the table that end with 's'. The pattern matching follows Java regular
expressions. Check out this link for documentationhttp://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html

显示表的结构信息
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;


http://www.niftyadmin.cn/n/3060761.html

相关文章

pnfs执行truncate失败的BUG解析

Bug 名称 Truncate操作失败 Bug 描述 使用fstest工具,先执行create再执行truncate后,服务器会返回EIO,而不是期望的0,过一段时间之后,重复执行truncate则成功。 这是导致truncate测试用例所有失败的唯一原因。具体测试脚本在fs…

nilsimsa的大概算法

1. 有一个5个字节的window,沿着文本向右滑动,每次滑动一个字节2. 每一个window里面的5个字节,分别可以N个组成3元组。 例如igram,可以分为:igr iga igm iga igm gra grm gam ram3. 每一个三元组通过一个hash函数,算出来…

do_generic_file_read()函数

这个函数完成了文件读的主要流程 核心在于操作页高速缓存,如缺页,失效,预读等操作。 函数中goto语句不计其数, static void do_generic_file_read(struct file *filp, loff_t *ppos, read_descriptor_t *desc, read_a…

ECLIPSE、INTELLIJ IDEA格式化统一ECLIPSE CODE FORMATTER

Eclipse、Intellij idea格式化结果不一样,导致长时间都是用两个开发工具,idea开发eclipse进行格式化。但是现在这个问题可以解决了。使用Eclipse Code Formatter。 具体的插件地址:http://plugins.jetbrains.com/plugin/6546?pridea&off…

文件读写流程

在《linux内核虚拟文件系统浅析》这篇文章中,我们看到文件是如何被打开、文件的读写是如何被触发的。 对一个已打开的文件fd进行read/write系统调用时,内核中该文件所对应的file结构的f_op->read/f_op->write被调用。 本文将顺着这条路走下去&…

网站无法显示logo?

那是因为你没有配置favicon.ico,每个网站根目录都会有一个favicon.ico,因为每个服务器都会请求根目录下的它。

改变图片尺寸

// 改变图片尺寸 -(UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize{UIImage *newimage;if (nil image) {newimage nil;}else{CGSize oldsize image.size;CGRect rect;if (asize.width/asize.height > oldsize.width/oldsize.height) {re…

Git建立远程/本地服务器和git命令的使用

Github 远程仓库 1、github.com 注册账户 2、在github上创建仓库 3、生成本地ssh key [rootlocalhost ~]# ssh-keygen -t rsa -C maiya163.com # 邮箱要与github上注册的相同 [rootlocalhost ~]# cat .ssh/id_rsa.pub ssh-rsaAAAAB3NzaC1yc2EAAAADAQABAAABAQDVThfq4brrlsPGtAkn…