《ProgrammingHive》阅读笔记-第二章
书本第二章的一些知识点,在cloudera-quickstart-vm-5.8.0-0上进行操作。
- 配置文件
配置在/etc/hive/conf/hive-site.xml文件里面,采用mysql作为metastore。"hive.metastore.warehouse.dir"这个属性没有在文件中进行配置,因此采用默认值/user/hive/warehouse作为Hive的默认路径。
[cloudera@quickstart ~]$ hdfs dfs -ls /user/hive/warehouse
Found 9 items
drwxrwxrwx - cloudera supergroup 0 2016-08-27 02:34 /user/hive/warehouse/categories
drwxrwxrwx - cloudera supergroup 0 2016-08-27 02:37 /user/hive/warehouse/customers
drwxrwxrwx - cloudera supergroup 0 2016-08-27 02:39 /user/hive/warehouse/departments
drwxrwxrwx - cloudera supergroup 0 2016-08-27 02:42 /user/hive/warehouse/order_items
drwxrwxrwx - cloudera supergroup 0 2016-08-27 02:44 /user/hive/warehouse/orders
drwxr-xr-x - hdfs supergroup 0 2016-12-27 00:34 /user/hive/warehouse/original_access_logs
drwxrwxrwx - cloudera supergroup 0 2016-08-27 02:46 /user/hive/warehouse/products
drwxrwxrwx - cloudera supergroup 0 2016-12-27 05:52 /user/hive/warehouse/tokenized_access_logs
drwxrwxrwx - cloudera supergroup 0 2016-09-04 02:09 /user/hive/warehouse/userinfo
进入CLI
$ hive
使用set可以查看配置信息hive> set;临时变量赋值和查看
hive> set foo;
foo=bar
hive> set hivevar:foo
> ;
hivevar:foo=bar
define的变量只在当前会话有效,define中赋值的变量在hivevar命名空间。
- hiveconf命名空间变量
[cloudera@quickstart ~]$ hive --hiveconf hive.cli.print.current.db=true
Logging initialized using configuration in file:/etc/hive/conf.dist/hive-log4j.properties
WARNING: Hive CLI is deprecated and migration to Beeline is recommended.
hive (default)> set hiveconf:hive.cli.print.current.db=false;
hive> set hiveconf:hive.cli.print.current.db=true;
hive (default)>
同时,我们也可以在hiveconf中增加新的变量。
[cloudera@quickstart ~]$ hive --hiveconf y=5
Logging initialized using configuration in file:/etc/hive/conf.dist/hive-log4j.properties
WARNING: Hive CLI is deprecated and migration to Beeline is recommended.
hive> set y;
y=5
- system命名空间
用于访问Java系统属性,system命名空间下的变量也可以读写。
hive> set system:user.name;
system:user.name=cloudera
hive> set system:user.name=camash
> ;
hive> set system:user.name;
system:user.name=camash
hive> set env:HOMJE;
env:HOME=/home/cloudera
- 获得所有定义的表
hive> show tables like '*';
OK
categories
customers
departments
intermediate_access_logs
order_items
orders
products
tokenized_access_logs
userinfo
Time taken: 0.065 seconds, Fetched: 9 row(s)
- 单次执行hive命令
在shell中单次执行,打印结果在shell窗口。
[cloudera@quickstart ~]$ hive -e "select * from userinfo limit 3";
Logging initialized using configuration in file:/etc/hive/conf.dist/hive-log4j.properties
OK
root x 0 0 root /root /bin/bash
bin x 1 1 bin /bin /sbin/nologin
daemon x 2 2 daemon /sbin /sbin/nologin
Time taken: 2.049 seconds, Fetched: 3 row(s)
使用-S命令减少查询过程信息,从而可以将查询结果放至文件。
[cloudera@quickstart ~]$ hive -S -e "select * from userinfo limit 3"; > /tmp/myquery
[cloudera@quickstart ~]$ cat /tmp/myquery
同时方便执行set命令
[cloudera@quickstart ~]$ hive -S -e "set" | grep warehouse
hive.metastore.warehouse.dir=/user/hive/warehouse
hive.warehouse.subdir.inherit.perms=true
- 从文件中执行
第一种方式使用hive -f命令,第二种方式hive对话框中使用source命令。
[cloudera@quickstart ~]$ hive -f filequery.hql
Logging initialized using configuration in file:/etc/hive/conf.dist/hive-log4j.properties
OK
root x 0 0 root /root /bin/bash
bin x 1 1 bin /bin /sbin/nologin
daemon x 2 2 daemon /sbin /sbin/nologin
Time taken: 2.504 seconds, Fetched: 3 row(s)
[cloudera@quickstart ~]$ cat filequery.hql
select * from userinfo limit 3;
hive> source /home/cloudera/filequery.shql
> ;
OK
root x 0 0 root /root /bin/bash
bin x 1 1 bin /bin /sbin/nologin
daemon x 2 2 daemon /sbin /sbin/nologin
Time taken: 1.648 seconds, Fetched: 3 row(s)
- 在hive会话中执行shell命令
hive> ! pwd
> ;
/home/cloudera
《ProgrammingHive》阅读笔记-第二章的更多相关文章
- 深入理解 C 指针阅读笔记 -- 第二章
Chapter2.h #ifndef __CHAPTER_2_ #define __CHAPTER_2_ /*<深入理解C指针>学习笔记 -- 第二章*/ /* 内存泄露的两种形式 1.忘 ...
- 《图解HTTP》阅读笔记--第二章 简单的HTTP协议--第三章 HTTP报文信息
第二章.简单的HTTP协议HTTP协议:HTTP协议用于客户端(请求资源的一端)和服务器端(响应回复提供资源的一端)的通信,是一种无状态协议HTTP1.1默认TCP持久连接,管线化发送(并行发送多个 ...
- 《Interest Rate Risk Modeling》阅读笔记——第二章:债券价格、久期与凸性
目录 第二章:债券价格.久期与凸性 思维导图 瞬时回报率-收益率的例子 第二章:债券价格.久期与凸性 思维导图 瞬时回报率-收益率的例子
- Redis实战阅读笔记——第二章
在性能的要求下,如何获取重构之前的构件
- Redis实战阅读笔记——第二章(redis重构web)
在性能的要求下,如何用redis重构已有的已有的部分,其实整个例子背后的思路挺好的.在应用缓存的过程中,还有一指标个需要考虑,读写比.
- Android群英传笔记——第二章:Android开发工具新接触
Android群英传笔记--第二章:Android开发工具新接触 其实这一章并没什么可讲的,前面的安装Android studio的我们可以直接跳过,如果有兴趣的,可以去看看Google主推-Andr ...
- 《DOM Scripting》学习笔记-——第二章 js语法
<Dom Scripting>学习笔记 第二章 Javascript语法 本章内容: 1.语句. 2.变量和数组. 3.运算符. 4.条件语句和循环语句. 5.函数和对象. 语句(stat ...
- The Road to learn React书籍学习笔记(第二章)
The Road to learn React书籍学习笔记(第二章) 组件的内部状态 组件的内部状态也称为局部状态,允许保存.修改和删除在组件内部的属性,使用ES6类组件可以在构造函数中初始化组件的状 ...
- [HeadFrist-HTMLCSS学习笔记]第二章深入了解超文本:认识HTML中的“HT”
[HeadFrist-HTMLCSS学习笔记]第二章深入了解超文本:认识HTML中的"HT" 敲黑板!!! 创建HTML超链接 <a>链接文本(此处会有下划线,可以单击 ...
随机推荐
- hashmap相关面试题
- Mysql 数据类型、约束类型
mysql数据类型 MySQL中定义数据字段的类型对你数据库的优化是非常重要的. MySQL支持多种类型,大致可以分为三类:数值.日期/时间和字符串(字符)类型. 数值类型 MySQL支持所有标准 ...
- CentOS 6.5优化开机启动服务
使用chkconfig命令列举出所有服务,配合管道筛选出开机默认启动的服务,再去掉level0(关机).level4(无意义)和level6(重启)的显示,使结果更直观. chkconfig | gr ...
- MySQL教程 3.3
本实验是将数据加载到表中,具体步骤如下: 先创建数据库menagerie,再启用数据库,然后在库中创建表pet. 运行如下代码,将文本文件pet.txt加载到pet表中,但出现ERROR 1148.查 ...
- RPM 包的构建 - SPEC 基础知识
spec 文件 制作 rpm 软件包并不是一件复杂的工作,其中的关键在于编写软件包的 spec 描述文件. 要想制作一个 rpm 软件包就必须写一个软件包描述文件 spec.这个文件中包含了软件包的诸 ...
- HDU 6166 Senior Pan(k点中最小两点间距离)题解
题意:n个点,m条有向边,指定k个点,问你其中最近的两点距离为多少 思路:这题的思路很巧妙,如果我们直接枚举两点做最短路那就要做C(k,2)次.但是我们换个思路,我们把k个点按照二进制每一位的0和1分 ...
- jQuery validator plugin之Selector
原文 :unchecked Selector Selects all elements that are unchecked. jQuery( ":unchecked" ) Inv ...
- Go 使用 JSON
Encode 将一个对象编码成 JSON 数据,接受一个 interface{} 对象,返回 []byte 和 err func Marshal(v interface{}) {[]byte,err} ...
- 3分钟快速presentation
来自英语课的一个练习: https://www.youtube.com/watch?v=ePY3uY1L0X0 next up I'd like to welcome Joshua to ten he ...
- C#反射详解
http://blog.csdn.net/educast/article/details/2894892(转) 两个现实中的例子:1.B超:大家体检的时候大概都做过B超吧,B超可以透过肚皮探测到你内脏 ...