1.7 hive基本操作
一、基本命令和设置
1、命令
[root@hadoop-senior hive-0.13.1]# bin/hive
Logging initialized using configuration in jar:file:/opt/modules/hive-0.13.1/lib/hive-common-0.13.1.jar!/hive-log4j.properties
hive> show databases;
OK
default
Time taken: 0.367 seconds, Fetched: 1 row(s)
hive> show databases;
OK
default
Time taken: 0.013 seconds, Fetched: 1 row(s)
hive> create database db_hive;
OK
Time taken: 0.155 seconds
hive> show databases;
OK
db_hive
default
Time taken: 0.011 seconds, Fetched: 2 row(s)
hive> use db_hive;
OK
Time taken: 0.017 seconds
hive> create table student(id int,name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
OK
Time taken: 0.108 seconds
hive> show tables;
OK
student
Time taken: 0.016 seconds, Fetched: 1 row(s)
hive> desc student;
OK
id int
name string
Time taken: 0.098 seconds, Fetched: 2 row(s) hive> desc formatted student; #查看表结构详细信息
OK
# col_name data_type comment id int
name string # Detailed Table Information
Database: db_hive
Owner: root
CreateTime: Fri Apr 19 10:44:19 CST 2019
LastAccessTime: UNKNOWN
Protect Mode: None
Retention: 0
Location: hdfs://hadoop-senior.ibeifeng.com:8020/user/hive/warehouse/db_hive.db/student #此表在HDFS上的存储位置
#在HDFS上分层存储的,数据库名/表名
Table Type: MANAGED_TABLE #表类型
Table Parameters:
transient_lastDdlTime 1555641859 # Storage Information
SerDe Library: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
InputFormat: org.apache.hadoop.mapred.TextInputFormat
OutputFormat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
Compressed: No
Num Buckets: -1
Bucket Columns: []
Sort Columns: []
Storage Desc Params:
field.delim \t
serialization.format \t
Time taken: 0.074 seconds, Fetched: 28 row(s)
2、命令
#加载数据到hive表中
hive> load data local inpath '/opt/datas/student.txt' into table db_hive.student;
Copying data from file:/opt/datas/student.txt
Copying file: file:/opt/datas/student.txt
Loading data to table db_hive.student
Table db_hive.student stats: [numFiles=1, numRows=0, totalSize=36, rawDataSize=0]
OK
Time taken: 0.36 seconds hive> select * from student;
OK
1001 zhangsan
1002 lisi
1003 wangwu
Time taken: 0.16 seconds, Fetched: 3 row(s) #######函数#######
#查看自带的函数
hive> show functions; #查看一个函数的使用方法
hive> desc function 函数名; #查看一个函数的详细使用方法
hive> desc function extended 函数名; #upper函数的用法
hive> select id,upper(name) uname from db_hive.student;
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1554717689707_0004, Tracking URL = http://hadoop-senior.ibeifeng.com:8088/proxy/application_1554717689707_0004/
Kill Command = /opt/modules/hadoop-2.5.0/bin/hadoop job -kill job_1554717689707_0004
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2019-04-19 11:09:47,786 Stage-1 map = 0%, reduce = 0%
2019-04-19 11:09:51,931 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 1.29 sec
MapReduce Total cumulative CPU time: 1 seconds 290 msec
Ended Job = job_1554717689707_0004
MapReduce Jobs Launched:
Job 0: Map: 1 Cumulative CPU: 1.29 sec HDFS Read: 279 HDFS Write: 36 SUCCESS
Total MapReduce CPU Time Spent: 1 seconds 290 msec
OK
1001 ZHANGSAN
1002 LISI
1003 WANGWU
Time taken: 10.298 seconds, Fetched: 3 row(s)
3、让hive命令行能显示前使用的库和查询时显示字段名
#修改配置文件
<property>
<name>hive.cli.print.header</name>
<value>true</value>
<description>Whether to print the names of the columns in query output.</description>
</property> <property>
<name>hive.cli.print.current.db</name>
<value>true</value>
<description>Whether to include the current database in the Hive prompt.</description>
</property> #退出hive命令行,重新进入查看
hive (default)> #已经显示当前使用的库了 hive (default)> use db_hive;
OK
Time taken: 0.303 seconds
hive (db_hive)> hive (db_hive)> select * from student;
OK
student.id student.name #这里也显示字段名了
1001 zhangsan
1002 lisi
1003 wangwu
Time taken: 0.035 seconds, Fetched: 3 row(s)
1.7 hive基本操作的更多相关文章
- hive学习3(hive基本操作)
hive基本操作 hive的数据类型 1)基本数据类型 TINYINT,SMALLINT,INT,BIGINT FLOAT/DOUBLE BOOLEAN STRING 2)复合类型 ARRAY:一组有 ...
- 第2节 hive基本操作:6、7、8
第1节 hive安装:6.hive的基本操作:7.创建数据库的语法:8.hive当中创建内部表的语法. hive的基本操作: 创建数据库与创建数据库表操作 创建数据库操作:create databas ...
- 【hive】——Hive基本操作
阅读本文章可以带着下面问题:1.与传统数据库对比,找出他们的区别2.熟练写出增删改查(面试必备) 创建表:hive> CREATE TABLE pokes (foo INT, bar STRIN ...
- hive基本操作
hive级联删除数据库和表 drop database t1 cascade; hive创建临时表和插入 create table t1 as select * from achi; insert i ...
- hive基本操作与应用
通过hadoop上的hive完成WordCount 启动hadoop Hdfs上创建文件夹 上传文件至hdfs 启动Hive 创建原始文档表 导入文件内容到表docs并查看 用HQL进行词频统计,结果 ...
- 大数据学习——hive基本操作
1 建表 create table student(id int,name string ,age int) row format delimitedfields terminated by ','; ...
- 第2节 hive基本操作:12、hive当中的hql语法
3.2. hive查询语法 3.2.1.SELECT https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Select 基本 ...
- 第2节 hive基本操作:11、hive当中的分桶表以及修改表删除表数据加载数据导出等
分桶表 将数据按照指定的字段进行分成多个桶中去,说白了就是将数据按照字段进行划分,可以将数据按照字段划分到多个文件当中去 开启hive的桶表功能 set hive.enforce.bucketing= ...
- 第2节 hive基本操作:10、外部分区表综合练习
外部分区表综合练习: 需求描述:现在有一个文件score.csv文件,存放在集群的这个目录下/export/servers/scoredatas/month=201806,这个文件每天都会生成,存放到 ...
随机推荐
- iOS移动开发周报-第20期
iOS移动开发周报-第20期iOS移动开发周报-第20期 [摘要]:本期iOS移动开发周报带来如下内容:iOS 通知中心扩展制作入门,iOS APP可执行文件的组成,objc非主流代码技巧等. 教程 ...
- Android开发之裁切(拍照+相冊)图像并设置头像小结
先看效果: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5 ...
- mnesia练习及基本操作
Mnesia基本用法 查看表结构 查看mnesia表的结构: mnesia:info(). 查看此表的基本信息: mnesia:table_info(<tableName>, all). ...
- FFmpeg编码详细流程
FFmpeg在编码一个视频的时候的函数调用流程.为了保证结构清晰,其中仅列出了最关键的函数,剔除了其它不是特别重要的函数. 函数背景色 函数在图中以方框的形式表现出来.不同的背景色标志了该函数不同的作 ...
- cocos2d-x lua 中使用protobuf并对http进行处理
cocos2d-x lua 中使用protobuf并对http进行处理 本文介绍 cocos2d-x lua 中使用http 和 基于cocos2d-x 对lua http的封装(部分ok) 本博客链 ...
- 【iOS开发】---- UIView动画
iOS 动画UIView动画 原文:http://www.cocoachina.com/bbs/read.php?tid=110168 1.概述 UIKit直接将动画集成到UIView类中,实现简 ...
- 【BZOJ2339】[HNOI2011]卡农 组合数+容斥
[BZOJ2339][HNOI2011]卡农 题解:虽然集合具有无序性,但是为了方便,我们先考虑有序的情况,最后将答案除以m!即可. 考虑DP.如果我们已经知道了前m-1个集合,那么第m个集合已经是确 ...
- Interface AutoCloseable
https://docs.oracle.com/javase/tutorial/essential/exceptions/try.html https://docs.oracle.com/javase ...
- FICO credit score
http://www.bankrate.com/finance/credit/what-is-a-fico-score.aspx Anyone who’s ever thought about loo ...
- DuiLib笔记之CDuiString的bug
在C/C++中,当使用==比较两个对象时,推荐的风格是将常量置前 例如 if (0 == variable) { ... } 但在DuiLib中,CDuiString存在一个bug:在用==进行比较时 ...