书本第二章的一些知识点,在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. Shell 脚本进阶2

    1.查询系统基础情况脚本 #!/bin/bash # 系统状态查询脚本 # 输出系统基本信息 # # 系统版本 SYSTEM_VERSION=`cat /etc/redhat-release` # 主 ...

  2. No executable found matching command "dotnet-aspnet-codegenerator"

    vs2017,mvc新建控制器报错. 右键项目,选择编辑工程文件(.csproj),加入以下节点 <ItemGroup> <DotNetCliToolReference Includ ...

  3. Github 最简单的认证方式 - Access Token

    Github 本身提供了多种认证方式,所有开发人员可以各取所需. SSH,这是最原始的方式,如果使用git bash只要按照官方文档一步一步配置就好了 小心坑:SSH有可能需要配置代理,否则无法解析服 ...

  4. 洛谷 P2915 【[USACO08NOV]奶牛混合起来Mixed Up Cows】

    类似于n皇后的思想,只要把dfs表示放置情况的数字压缩成一个整数,就能实现记忆化搜索了. 一些有关集合的操作: {i}在集合S内:S&(1<<i)==1: 将{i}加入集合S:S= ...

  5. sony Z5P 刷rec、root的方法

    想root需要刷第三方recovery,刷recovery需要先解锁.但如果直接解锁,会丧失相机算法.屏幕超逼真模式,所以不能直接来. 大体步骤就是解完锁后自己做个内核刷进去,欺骗系统让他觉得没解锁. ...

  6. Spring框架[一]——spring概念和ioc入门(ioc操作xml配置文件)

    Spring概念 spring是开源的轻量级框架(即不需要依赖其他东西,可用直接使用) spring核心主要两部分 aop:面向切面编程,扩展功能不是修改源代码来实现: ioc:控制反转,比如:有一个 ...

  7. Hbasewindows系统下启动报错及解决办法

    今天在本地windows电脑上,装pinpoint时,需要先安装一个Hbase数据库,按照教程下载启动Hbase数据库时,却启动报错:java.io.IOException: Could not lo ...

  8. 重写console.log的一些理解

    关于重写console.log的方式通常都是这样的: console.log = (function(oriLogFunc){ return function(str) { oriLogFunc.ca ...

  9. Sign Up Account In CloudAMQP

    CloudAMQP 有多种账号级别,请参考下面的链接的内容访问你可以注册的级别:https://www.cloudamqp.com/plans.html 作为测试来说,你可以注册免费的的消息. 你可以 ...

  10. Linux 安装 ffmpeg

    在安装ffmpeg之前,需要先安装一些必需组件.包括但不限于以下组件(有的系统里面可能已经安装过) 首先在根目录下创建:ffmpeg_sources 1.Yasm sudo apt-get insta ...