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,这个文件每天都会生成,存放到 ...
随机推荐
- 怎样创建.NET Web Service http://blog.csdn.net/xiaoxiaohai123/article/details/1546941
为什么需要Web Service 在通过internet网购买商品后,你可能对配送方式感到迷惑不解.经常的情况是因配送问题找配送公司而消耗你的大量时间,对于配送公司而言这也不是一项增值服务. 为了解决 ...
- 基于multiprocessing和threading实现非阻塞的GUI界面显示
========================================================= 环境:python2.7.pyqt4.eric16.11 热点:multiproce ...
- g++ 6.4编译opencv-2.4.10报错记录
fetch公司的项目进行编译,此项目依赖opencv库.由于本人一直比较偏爱fedora,但也因此给我带来了许多"乐趣"(麻烦).fedora一直走得比较前沿,g++ 6.3了 ...
- C++算法之 一句话推断一个整数是不是2 的整数次方
思路:一个整数假设是2的整数次方,那么它的二进制表示中有且仅仅有一位是1,而其它全部位都是0.把这个整数与这个整数减去1之后进行与运算.那么这个整数其中唯一的 1会变为0,这个整数也变为0: 代码: ...
- IOS8 通知中心(Notification Center)新特性
本文转载至 http://blog.csdn.net/jinkaiouyang/article/details/30029441 ios手机apple通知中心notificationCenter ...
- wince c# 创建桌面快捷方式 .
static void Create() { string PathGPRS = System.IO.Path.GetDirectoryName(System.Reflection.Assembly. ...
- [Phoenix] 七、如何使用自增ID
摘要: 在传统关系型数据库中设计主键时,自增ID经常被使用.不仅能够保证主键的唯一,同时也能简化业务层实现.Phoenix怎么使用自增ID,是我们这篇文章的重点. 在传统关系型数据库中设计主键时,自增 ...
- 6.5.1.3 Caching SHA-2 Pluggable Authentication
MySQL :: MySQL 8.0 Reference Manual :: 6.5.1.3 Caching SHA-2 Pluggable Authentication https://dev.my ...
- 【Effective C++】构造/析构/赋值运算
条款05:了解C++默默编写并调用哪些函数 默认构造函数.拷贝构造函数.拷贝赋值函数.析构函数构成了一个类的脊梁,只有良好的处理这些函数的定义才能保证类的设计良好性. 当我们没有人为的定义上面的几个函 ...
- linux EXT文件系统
将一个硬盘分区之后如何创建文件系统(windows来讲就是如何针对分区来进行格式化,是采用FAT32的文件系统来格式化,还是采用NTFS的文件系统来格式化).Linux主要采用EXT2,EXT3分区格 ...