Hive shell 基本命令
首先连接 hive shell
直接输入 hive启动, 使用--开头的字符串来表示注释
hive>quit; --退出hive
hive> exit; --exit会影响之前的使用,所以需要下一句kill掉hadoop的进程
hine>hadoop job -kill jobid
1、显示表
hive>create database database_name; 创建数据库
如果数据库已经存在就会抛出一个错误信息,使用如下语句可以避免抛出错误信息:
hive>creat database if not exists database_name;
hive> show databases; 查看数据库;
如果数据库比较多的话,也可以用正则表达式来查看:
hive> show databases like 'h.*';
hive> use default; --使用哪个数据库;
hive> show tables; 或者支持模糊查询:hive> show tables '*t*';
hive> describe tab_name; --查看表的结构及表的路径
hive> describe database database_name; --查看数据库的描述及路径
2、创建表
hive> create table test(key string);
OK
Time taken: 0.265 seconds
3、创建分区表:
hive> create table logs(ts bigint,line string) partitioned by (dt String,country String);
4、加载分区表数据:
hive> load data local inpath '/home/Hadoop/input/file1' into table logs partition (dt='2014-03-11',country='CN');
5、展示表中有多少分区:
hive> show partitions logs;
6、显示表的结构信息
hive> describe table_name;
hive> describe database database_name; --查看数据库的描述及路径
7、更新表名称:
hive>alter table table_name rename to another_name;
8、添加新一列:
hive> ALTER TABLE invites ADD COLUMNS (new_col2 INT COMMENT 'a comment');
9、删除表:
hive>drop table t1 ; --删除表t1 或者:hive> drop table if exists t1;
删除表中数据,但要保持表的结构定义:
hive> dfs -rmr /user/hive/warehouse/records;
10、可以用下面的命令来修改数据库的路径:
hive> creat database database_name location '路径';
hive> drop database if exists database_name; --删除空的数据库
hive> drop database if exists database_name cascade; --先删除数据库中的表再删除数据库;
11、hive不支持修改表中数据,但是可以修改表结构,而不影响数据
有local的速度明显比没有local慢:
hive>load data inpath '/root/inner_table.dat' into table t1; 移动hdfs中数据到t1表中
hive>load data local inpath '/root/inner_table.dat' into table t1; 上传本地数据到hdfs中
hive> !ls; 查询当前linux文件夹下的文件
hive> dfs -ls /; 查询当前hdfs文件系统下 '/'目录下的文件;
它不支持行级插入操作、更新操作和删除操作,也不支持事务,那么往表里面装数据的唯一的途径就是使用一种“大量”的数据装载操作,
或者仅仅将文件写入到正确的目录下面,即以load的方式加载到建立好的表中,且数据一旦导入就不可以修改,加载的目标可以是一个表
或者分区,如果表包含分区,必须指定每一个分区名:
hive>show functions;
hive>describe function fun_name;--查看函数的用法;
hive>select col1[0],col2['b'],col3.c from complex;--查看数组、map、结构;
13、内连接:
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);
14、外连接:
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);
15、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;
16、创建视图:
hive> CREATE VIEW valid_records AS SELECT * FROM records2 WHERE temperature !=9999;
17、查看视图详细信息:
hive> DESCRIBE EXTENDED valid_records;
18、从表中导出数据:
hadoop fs -cp source_path target_path
或者:用户可以使用 insert……directory……
insert overwrite local directory '/tmp/目录' 这里指定的路径也可以是全URL路径
19、hive中使用正则表达式
(1) hive> select 'price.*' from table_name;
选出所有列名以price作为前缀的列
(2) 用Like或者RLike
20、聚合函数
可以通过设置属性hive.map.aggr值为true来提高聚合的性能:
hive>hive.map.aggr=true;
21、什么情况下hive可以避免进行mapreduce?
在本地模式的时候可以避免触发一个mr的job,此外,如果属性hive.execmode.local.auto的值为true的话,hive还户尝试本地模式进行其他的操作。
set hive.execmode.local.auto=true;
说明:最好将 set hive.execmode.local.auto=true;这个设置增加到你的$HOME/.hiverc配置文件中去。
22、JOIN语句
hive支持通常的SQL JOIN语句,但是只支持等值连接。hive也不支持在on子句中用谓词OR
23、union all
将两个表或者多个表进行合并,每一个union all子查询都必须具有相同的列,而且对应每个字段的每个类型都必须一致。
Hive shell 基本命令的更多相关文章
- Hive Shell 命令详解
Hive服务介绍 Hive默认提供的cli(shell)服务,如果需要启动其他服务,那么需要service参数来启动其他服务,比如thrift服务.metastore服务等.可以通过命令hive -- ...
- shell基本命令
linux基本命令和shell基本命令,好多人傻傻分不清. linux基本命令积累如下: pwd:显示当前工作目录 cd:改变当前目录 ls:显示当前目录中所有目录文件和文本文件 ls -F:显示当前 ...
- shell 基本命令
Shell基本命令 前言 前面咱们已经成功安装了Linux系统--centos7,那么现在跟着超哥奔向Linux的大门. Linux命令行的组成结构 [root@oldboy_python ~]# ...
- Hive shell 命令
Hive shell 命令. 连接 hive shell 直接输入 hive 1.显示表 hive> show tables; OK test Time taken: 0.17 seconds, ...
- 二、hive shell常用命令
在使用hive shell之前我们需要先安装hive,并启动hdfs 请参考:https://www.cnblogs.com/lay2017/p/9973298.html hive shell 我们先 ...
- Hive(四)hive函数与hive shell
一.hive函数 1.hive内置函数 (1)内容较多,见< Hive 官方文档> https://cwiki.apache.org/confluence/displ ...
- Linux(2)- linux目录结构、shell基本命令
一.Linux之文档与目录结构 1.Linux文件系统结构 Linux目录结构的组织形式和Windows有很大的不同.Linux没有“盘(如C盘.D盘.E盘)”的概念,而是建立一个根"/&q ...
- Linux--2 Linux之文档与目录结构、shell基本命令
一.Linux之文档与目录结构 1.Linux之文档与目录结构 Linux目录结构的组织形式和Windows有很大的不同.Linux没有“盘(如C盘.D盘.E盘)”的概念,而是建立一个根"/ ...
- 运维 05 Shell基本命令
Shell基本命令 前言 前面咱们已经成功安装了Linux系统--centos7,那么现在跟着超哥奔向Linux的大门. Linux命令行的组成结构 [root@oldboy_python ~]# ...
随机推荐
- Linux之恢复误删的文件[针对丢弃到回收站]
1.丢弃到回收站(非RM)掉的文件一般在目录~/.local/share/Trash/files/下: 2.如何恢复呢? 原理很简单,既然它们还在,要么copy,要么移动到一个新的地方即可嘛. //以 ...
- Ubuntu、Windows输入命令appium-doctor提示未找到命令
输入命令:appium-doctor时,一直报错,提示“未找到命令”,但是输入命令:appium -v能够正确输出我安装版本,这是怎么回事呢? 原来appiu-doctor在1.5.3版本之后没有了需 ...
- jq的dom操作
代码可以在该网址测试:www.w3school.com.cn/tiy/t.asp?f=jquery_manipulation_detach_move attr 使用函数来设置属性/值:函数参数为选择器 ...
- Core Mvc传值ViewData、ViewBag和return view(model)
先定义一个Model类Student namespace Lession.Models { public class Student { public string Name { get; set; ...
- Nginx系列7:SSL证书的公信力是如何保证的?
1.PKI公钥基础设施 2.证书类型 参考链接:ssl证书类型区别 3.证书链
- oracle修改归档日志路径与格式
一.查询数据库是否开启归档模式: SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled ...
- centos安装fish shell
对于 CentOS 7,请以根用户 root 运行下面命令: cd /etc/yum.repos.d/ wget https://download.opensuse.org/repositories/ ...
- 用Tesseract训练验证码遇到的问题
1.准备验证码图片 import os from urllib.request import urlretrieve urlPath='http://www.189.cn/portal/captcha ...
- P3168 [CQOI2015]任务查询系统
题目地址:P3168 [CQOI2015]任务查询系统 主席树的模板题 更模板的在这儿:P3834 [模板]可持久化线段树 1(主席树) 形象的说,P3834是"单点修改,区间查询" ...
- dubbo的本地存根(Stub)
dubbo的本地存根的原理是:远程服务后,客户端通常只剩下接口,而实现全在服务器端,但提供方有些时候想在客户端也执行部分逻辑,那么就在服务消费者这一端提供了一个Stub类,然后当消费者调用provid ...