创建表:

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;

Hive基本命令整理的更多相关文章

  1. hive问题整理(待续)

    本人对hadoop生态系统的环境搭建.配置相关再熟悉不过了,周末刚测试过oozie相关的 今早使用hive,报错: Exception in thread "main" java. ...

  2. Linux基本命令整理_sheng

    Linux版本 Linux系统是一个多用户.多任务的分时操作系统. Linux版本分为内核版本和发行版本. 常见的Linux发行版有: RedHat(分为用于企业的Red Hat Enterprise ...

  3. linux常用基本命令整理小结

    linux系统遵循的基本原则 由目标单一的小程序组成,组合小程序完成复杂任务: 一切皆文件: 尽量避免捕捉用户接口: 配置文件保存为纯文本文件: Linux命令行常识 命令格式 命令+选项+参数 选项 ...

  4. Hive基本命令解析

    1. Hive的分区作用 命令:创建分区 create table t_sz_part(id int, name string) partitioned by (country string) row ...

  5. [Link]Hive资料整理

    Hive SQL的编译过程 Hive学习分享 IBM Hive

  6. mysql基本命令整理

    1.replace into(insert into 的增强版) replace into tbl_name(col_name, ...) values(...)replace into tbl_na ...

  7. Redis常用的基本命令整理

    SET key value [EX seconds] [PX milliseconds] [NX|XX] 设置缓存 K-V,如果 key 已经存在,则重写 EX seconds -- 设置过期时间, ...

  8. Git基本命令整理

    git help <command> # 显示command的help git show # 显示某次提交的内容 git show $id git co -- <file> # ...

  9. 【OS_Linux】Linux 基本命令整理

    1. 查看目录文件:ls2. 打印当前工作目录:pwd3. 查看文件内容:cat 文件名4. 打开编辑器:vim 文件名 1 2 3 4 5 修改:按Insert键 退出修改模式:按Esc 键 进入输 ...

随机推荐

  1. 存储过程 <3> 和函数的区别

    二.函数和存储过程的优点: 1.共同使用的代码可以只需要被编写一次,而被需要该代码的任何应用程序调用(.net,c++,java,也可以使DLL库). 2.这种几种编写.几种维护更新.大家共享的方法, ...

  2. Linux常用命令之sed

    标题:sed命令的使用 作用:sed(stream editer)是以行为单位处理文本数据,可以对数据按行进行选取(显示打印).替换.删除和新增等功能. 工作流程:sed是一个流编辑器,它可以对从标准 ...

  3. 原生js显示分页效果

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  4. Hibernate学习小结

    之前从事.net开发的三年经验里,我是用过EF.Microsoft Dynamic crm中集成的ORM以及上一家公司自主开发的ORM. 再接触Hibernate后,上手比较简单,但其提供了大量的接口 ...

  5. 【转】jmeter 进行java request测试

    本周使用jmeter进行一个远程dubbo接口的性能测试,因为没有访问页面,本来开发可以写一个页面,进行http请求的调用,不过已经看到jmeter可以直接对java request进行测试,所以尝试 ...

  6. 关于server的一些小记

    一. 批量创建用户 1. Import-Module ActiveDirectory 2. import-csv e:\users\newusers.csv | 3. New-ADUser -path ...

  7. Xcode中如何更改Bundle identifier

    1.如图所示,更改Info.plist 中的Bundle identifier

  8. iOS中—触摸事件详解及使用

    iOS中--触摸事件详解及使用 (一)初识 要想学好触摸事件,这第一部分的基础理论是必须要学会的,希望大家可以耐心看完. 1.基本概念: 触摸事件 是iOS事件中的一种事件类型,在iOS中按照事件划分 ...

  9. 后台获取ajax发送过来的值

    user.CityId = int.Parse(HttpContext.Request[ "bindArea"]); 以上为获取方法:

  10. 【ASP.NET】DataContract序列化,反序列化对象中包含用接口声明的属性时的处理方法

    为此对象添加KnownType属性(Attribute).类型为用接口声明的属性(Property)的所有可能类型.  示例如下: public interface IKey { [DataMembe ...