书本第二章的一些知识点,在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》阅读笔记-第二章的更多相关文章

  1. 深入理解 C 指针阅读笔记 -- 第二章

    Chapter2.h #ifndef __CHAPTER_2_ #define __CHAPTER_2_ /*<深入理解C指针>学习笔记 -- 第二章*/ /* 内存泄露的两种形式 1.忘 ...

  2. 《图解HTTP》阅读笔记--第二章 简单的HTTP协议--第三章 HTTP报文信息

     第二章.简单的HTTP协议HTTP协议:HTTP协议用于客户端(请求资源的一端)和服务器端(响应回复提供资源的一端)的通信,是一种无状态协议HTTP1.1默认TCP持久连接,管线化发送(并行发送多个 ...

  3. 《Interest Rate Risk Modeling》阅读笔记——第二章:债券价格、久期与凸性

    目录 第二章:债券价格.久期与凸性 思维导图 瞬时回报率-收益率的例子 第二章:债券价格.久期与凸性 思维导图 瞬时回报率-收益率的例子

  4. Redis实战阅读笔记——第二章

    在性能的要求下,如何获取重构之前的构件

  5. Redis实战阅读笔记——第二章(redis重构web)

    在性能的要求下,如何用redis重构已有的已有的部分,其实整个例子背后的思路挺好的.在应用缓存的过程中,还有一指标个需要考虑,读写比.

  6. Android群英传笔记——第二章:Android开发工具新接触

    Android群英传笔记--第二章:Android开发工具新接触 其实这一章并没什么可讲的,前面的安装Android studio的我们可以直接跳过,如果有兴趣的,可以去看看Google主推-Andr ...

  7. 《DOM Scripting》学习笔记-——第二章 js语法

    <Dom Scripting>学习笔记 第二章 Javascript语法 本章内容: 1.语句. 2.变量和数组. 3.运算符. 4.条件语句和循环语句. 5.函数和对象. 语句(stat ...

  8. The Road to learn React书籍学习笔记(第二章)

    The Road to learn React书籍学习笔记(第二章) 组件的内部状态 组件的内部状态也称为局部状态,允许保存.修改和删除在组件内部的属性,使用ES6类组件可以在构造函数中初始化组件的状 ...

  9. [HeadFrist-HTMLCSS学习笔记]第二章深入了解超文本:认识HTML中的“HT”

    [HeadFrist-HTMLCSS学习笔记]第二章深入了解超文本:认识HTML中的"HT" 敲黑板!!! 创建HTML超链接 <a>链接文本(此处会有下划线,可以单击 ...

随机推荐

  1. ELK(ElasticSearch+Logstash+ Kibana)搭建实时日志分析平台

    一.简介 ELK 由三部分组成elasticsearch.logstash.kibana,elasticsearch是一个近似实时的搜索平台,它让你以前所未有的速度处理大数据成为可能. Elastic ...

  2. D2欧拉路,拓扑排序,和差分约束

    第一题:太鼓达人:BZOJ3033 题意:给出k,求一个最长的M位01串,使其从每一个位置向后走k个得到 的M个k位01串互不相同(最后一个和第一个相邻,即是一个环).输出 字典序最小的答案. 2 ≤ ...

  3. JS设计模式(12)装饰者模式

    什么是装饰者模式? 定义:动态地给一个对象添加一些额外的职责.就增加功能来说,装饰器模式相比生成子类更为灵活. 主要解决:一般的,我们为了扩展一个类经常使用继承方式实现,由于继承为类引入静态特征,并且 ...

  4. Injection的简单辨析

    依赖注入(injection)是一种对任何编程语言都有效的概念.依赖注入背后的一般概念称为控制反转.根据这个概念,类不应该静态配置其依赖项,而应该从外部配置. 如果Java类使用此类的实例,则Java ...

  5. MyBatis进阶(三)

    MyBatis批量新增数据 1. 传统的JDBC批量插入数据 使用for循环 创建连接 获取连接 创建sql语句,交给连接 使用for循环新增数据 提交连接 使用批处理 两者都存在严重的效率问题,代码 ...

  6. Linux系统初始配置标准化

    Inux系统标准化 配置环境:4台Centos7.6版本的虚拟机,刚刚最小化安装完成,未作任何操作,分别是node1.node2.node3.node4 本文打算利用ansible工具对这四台虚拟机进 ...

  7. Kotlin 条件控制

    IF 表达式 一个 if 语句包含一个布尔表达式和一条或多条语句. // 传统用法 var max = a if (a < b) max = b // 使用 else var max: Int ...

  8. 机器学习 之KNN近邻法

    目录 1.KNN近邻法 1.KNN近邻法 KNN模型由三个基本要素决定: 距离度量:其中欧式距离一般误差最小,\(x_{i} 和 x_{j}\)为两个样本点:\[L_{2}(x_{i}, x_{j}) ...

  9. 【JS】【5】request.getHeader("referer")的作用

    正文: request.getHeader("referer"):获取来访者地址 注意:只有通过链接访问当前页的时候,才能获取上一页的地址,以下情况是获取不到值的: 只有通过链接访 ...

  10. vue中动态加载组件+开发者模式+JS参数值传递和引用传递

    今天写vue里面通过接口反参动态加载组件时候 跟着同学...学习到了 一.先说说vue 内置组件 component 的用法 component组件可以来专门用来进行组件的切换,使用is来绑定你的组件 ...