hive的常用命令
#从hive中直接进入hdfs的daas/bstl/term/userinfo目录下
hive> !hadoop fs -ls /daas/bstl/term/userinfo;
查看hive表结构以及对应的hdfs的路径
hive> desc formatted 表名;
1.
Hive的几种常见的数据导入方式
这里介绍四种:
(1)、从本地文件系统中导入数据到Hive表;
(2)、从HDFS上导入数据到Hive表;
(3)、从别的表中查询出相应的数据并导入到Hive表中;
(4)、在创建表的时候通过从别的表中查询出相应的记录并插入到所创建的表中
1.从本地文件系统中导入数据到Hive表
1.1
[hadoop@h91 hive-0.9.0-bin]$ bin/hive
创建ha表
hive> create table ha(id int,name string)
> row format delimited
> fields terminated by '\t'
> stored as textfile;
[ROW FORMAT DELIMITED]关键字,是用来设置创建的表在加载数据的时候,支持的列分隔符。
[STORED AS file_format]关键字是用来设置加载数据的数据类型,默认是TEXTFILE,如果文件数据是纯文本,就是使用 [STORED AS TEXTFILE],然后从本地直接拷贝到HDFS上,hive直接可以识别数据。
1.2
操作系统中的文本
[hadoop@h91 ~]$ cat haha.txt
101 zs
102 ls
103 ww
1.3导入数据
hive> load data local inpath '/home/hadoop/haha.txt' into table ha;
hive> select * from ha;
*****
和我们熟悉的关系型数据库不一样,Hive现在还不支持在insert语句里面直接给出一组记录的文字形式,也就是说,Hive并不支持INSERT INTO …. VALUES形式的语句。
*****
--------------------------------------------------
2.
从HDFS上导入数据到Hive表;
2.1
[hadoop@h91 hadoop-0.20.2-cdh3u5]$ bin/hadoop fs -mkdir abc
[hadoop@h91 ~]$ cat hehe.txt
1001 aa
1002 bb
1003 cc
[hadoop@h91 hadoop-0.20.2-cdh3u5]$ bin/hadoop fs -put /home/hadoop/hehe.txt abc/.
(上传到 hdfs中)
2.2
hive> create table he(id int,name string)
> row format delimited
> fields terminated by '\t'
> stored as textfile;
导入
hive> load data inpath '/user/hadoop/abc/hehe.txt' into table he;
---------------------------------------------------------
3.从别的表中查询出相应的数据并导入到Hive表中
3.1
hive> select * from he;
OK
1001 aa
1002 bb
1003 cc
hive> create table heihei(id int,name string)
> row format delimited
> fields terminated by '\t'
> stored as textfile;
3.2
hive> insert into table heihei select * from he;
或
hive> insert overwrite table heihei select * from ha;
(insert overwrite 会覆盖数据)
--------------------------------------------------
4.在创建表的时候通过从别的表中查询出相应的记录并插入到所创建的表中
hive> create table gaga as select * from he;
================================================================
导出数据
(1)、导出到本地文件系统;
(2)、导出到HDFS中;
(3)、导出到Hive的另一个表中。
1.导出到本地文件系统;
hive> insert overwrite local directory '/home/hadoop/he1' select * from he;
[hadoop@h91 ~]$ cd he1(he1为目录,目录下有000000_0文件 )
[hadoop@h91 he1]$ cat 000000_0
(发现 列之间没有分割 )
可以下面的方式增加分割
hive> insert overwrite local directory '/home/hadoop/he1' select id,concat('\t',name) from he;
******
和导入数据到Hive不一样,不能用insert into来将数据导出
******
---------------------------------------------------------
2.导出到HDFS中。
hive> insert overwrite directory '/user/hadoop/abc' select * from he;
(/user/hadoop/abc 为hdfs下目录)
[hadoop@h91 hadoop-0.20.2-cdh3u5]$ bin/hadoop fs -ls abc
[hadoop@h91 hadoop-0.20.2-cdh3u5]$ bin/hadoop fs -cat abc/000000_0
-------------------------------------------------------------
3.导出到Hive的另一个表中
hive> insert into table he12 select * from he;
hive的常用命令的更多相关文章
- 二、hive shell常用命令
在使用hive shell之前我们需要先安装hive,并启动hdfs 请参考:https://www.cnblogs.com/lay2017/p/9973298.html hive shell 我们先 ...
- hive\hadoop 常用命令
—1—————— 后台跑程序语句: 在shell下输入: nohup hive -f aaa.sql >bbb.log 2>&1 & 然后把sql 的脚本导入服务器上:T ...
- Hive记录-impala常用命令
1.impala是什么 Impala是Cloudera公司主导开发的新型查询系统,它提供SQL语义,能查询存储在Hadoop的HDFS和HBase中的PB级大数据.已有的Hive系统虽然也提供了SQL ...
- Hive记录-Sqoop常用命令
1.sqoop是什么 Sqoop是一款开源的数据迁移工具,主要用于Hadoop(Hive)与传统的关系型数据库(mysql...)相互之间的数据迁移. 2.sqoop的特点 sqoop的底层实现是ma ...
- Hive 常用命令和语句
示例数据库为 db_hive 1. 创建表 create-table.sql create table if not exists db_hive.tb_user ( id int, username ...
- Hive的基本概念和常用命令
原文链接: https://www.toutiao.com/i6766571623727235595/?group_id=6766571623727235595 一.概念: 1.结构化和非结构化数据 ...
- Hive 常用命令
1.hive模糊搜索表 show tables like '*name*'; 2.查看表结构信息 desc formatted table_name; desc table_name; 3.查看分 ...
- 大数据每日干货第四天(linux基础之一目录结构与常用命令)
为了和qq空间同步,也写的第四天,前面几天明天会发布,本来打算把每天学的东西记录下来,通过朋友给的建议要发的话稍微系统化下,从大数据需要的linux基础,到离线数据分析包括hadoop. ...
- (转)Hbase shell 常用命令(1)
Hbase shell 常用命令(1) link:http://blog.csdn.net/scutshuxue/article/details/6988348 下面我们看看HBase Shell的一 ...
随机推荐
- UnityShader快速上手指南(四)
简介 由于其他项目中断了几天更新,继续~~ 这一篇主要是讲光照的(包含漫反射和高光以及多光源的处理) 还是先来看看具体效果(多光源后面单独展示) 有了基本的光照处理之后越来越有立体感了有不有 ╮(╯▽ ...
- 【.NET框架】Dapper ORM 用法—Net下无敌的ORM
假如你喜欢原生的Sql语句,又喜欢ORM的简单,那你一定会喜欢上Dapper这款ROM.点击下载 Dapper的优势: 1,Dapper是一个轻型的ORM类.代码就一个SqlMapper.cs文件,编 ...
- sencha combobox下拉框不用jsonstore,直接使用字符串数组做数据源
combobox下拉框的store除了可以选择一个jsonstore来加载数据,还可以直接使用符串Array做数据源. { xtype: 'combobox', fieldLabel: 'Label' ...
- sql server2008中sql server身份能登录,window身份登录不了
用sql server身份的sa登录成功进入,一切正常,用window身份登录不了,问题如下
- 几个gcc的扩展功能
-finstrument-functions constructor destructor __builtin_return_address http://linuxgazette.net/15 ...
- 51Node 1035----最长的循环节
51Node 1035----最长的循环节 正整数k的倒数1/k,写为10进制的小数如果为无限循环小数,则存在一个循环节,求<=n的数中,倒数循环节长度最长的那个数. 1/6= 0.1 ...
- Ahjesus获取自定义属性Attribute或属性的名称
1:设置自己的自定义属性 public class NameAttribute:Attribute { private string _description; public NameAttribut ...
- 微软发布ASP.NET 5路线图
这次随 Visual Studio 2015 发布的 ASP.NET 版本是 ASP.NET 4.6 与 ASP.NET 5 beta5.在 VS2015 发布的同时,微软也发布了 ASP.NET 5 ...
- Picasso
1.简介 Picasso是Square公司出品的一个强大的图片下载和缓存图片库1)在adapter中需要取消已经不在视野范围的ImageView图片资源的加载,否则会导致图片错位,Picasso已经解 ...
- 写给java程序员的c++与java实现的一些重要细微差别
0.其实常规的逻辑判断结构.工具类.文件读写.控制台读写这些的关系都不大,熟悉之后,这些都是灵活运用的问题. 学习c/c++需要预先知道的一个前提就是,虽然有ANSI C标准,但是每个c/c++编译器 ...