创建表:

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. springmvc(1)--配置

    最近把spring的使用整理下,版本4.1.1.RELEASE SpringMVC是一个基于DispatcherServlet的MVC框架,每一个请求先访问的都是DispatcherServlet,D ...

  2. 给VPS装桌面

    转自:百度经验  致谢! 1.首先我们要先升级一下软件源给安装桌面环境做准备. 执行命令:apt-get update   2.安装桌面环境或窗口管理器: apt-get install xubunt ...

  3. C# struct

    很困惑,为什么C#会有struct 这样一个关键字.虽然我用C#几年了,但绝少用到此关键字.我在相关书籍上学习C#的时候,看到过struct内容——但C#并不是我的第一入门语言,所以没有那么细致的学习 ...

  4. C# 文件相关操作

    百度搜的,下面这个写的挺全的.   FROM Pegasus923 http://www.cnblogs.com/pegasus923/archive/2011/01/26/1944838.html ...

  5. 深入浅出ExtJS 第五章 树形结构

    5.1 TreePanel的基本使用 //树是一种非常典型的数据结构; 5.1.1 创建一棵树 //树控件有Ext.tree.TreePanel类定义,控件的名称为TreePanel;TreePane ...

  6. EL表达式隐含对象

    EL表达式语言中定义了11个隐含对象,使用这些隐含对象可以很方便地获取web开发中的一些常见对象,并读取这些对象的数据. 语法:${隐式对象名称}  :获得对象的引用 <%@ page lang ...

  7. Centos6的VSFTP服务器配置使用教程

    Centos 6 的VSFTP 关闭SELinux,在终端机输入 vi /etc/selinux/config SELINUX=enforcing 改成 SELINUX=disabled 关闭seli ...

  8. Apache2.4 与 PHP 5.5 64位版的安装配置

    我的环境:windows7 旗舰版 64位 首先下载相关文件: php 5.5.0 windows 64版 http://windows.php.net/download/#php-5.5 (选择 6 ...

  9. (转)如何构建高性能,稳定SOA应用之-负载均衡-Decoupled Invocation(一)

    当我们在为一个软件设计架构的时候,我们不仅仅要确保所做出来的架构要满足系统的业务需求,更加要确保做出来的架构要满足可维护性,安全,稳定性的非业务行的需求. 另外一个非常重要的非功能性需求就是性能.性能 ...

  10. jquery页面滚动,菜单固定到顶部

    // 菜单固定 $(function(){ //获取要定位元素距离浏览器顶部的距离 var navH = $("#topp").offset().top; //滚动条事件 $(wi ...