第四章: HQl的数据定义

1:创建数据库

  create database financials;

  create database  if not exists financials;





2: 查看数据库

  show databases;

   模糊查询数据库

  show databases like 'h.*' ;





3:创建数据库改动数据库的默认位置

   create database financials localtion '/my/preferred/directory'





4:添加数据库的描写叙述信息

   create database financials comment 'holds all financials tables'

5: 显示数据库的描写叙述的信息

  describe database financials;

6: 添加一些和相关属性的键-值对属性信息

  create database financials

  with dbproperties ('create'= 'Mark Moneybags', 'data'='2012-12-12');

  describe database  extended  financials;

  

7:没有命令提示让用户查看当前所在的是那个数据库。能够反复使用use

  use financials。

  能够通过设置一个属性值来在提示符里面显示当前所在的数据库

  set hive.cli.print.current.db = true;

  set hive.cli.print.current.db= false;

  

8:删除数据库

 drop database if exists financials;

 Hive是不同意删除一个包括表的数据库。

 当时假设加上keyword: cascade。就能够了,hive自己主动删除数据库中的表

  drop database if exists financials  cascade; 

 

9:改动数据库,设置dbproperties键值对属性值

 alert database financials set  dbproperties('edited-by'='joe dba');

 

10:创建表:

 create table if not  exists employees (

  name string comment 'employee name',

  salary float comment 'employee salary ',

  subordinates array<string> comment 'employee name of subordinates ' ,

  deductions Map<string,FLOAT>,

  address struct<street:string,city:string,state:String,zip:int>

  )

  comment ' description  of the table ' 

  tblproperties ('creater'= 'me', 'created_at'='2012-12-12');

  location '/user/hive/warehouse/mydb.db/employees'

  

  -- tblproperties 的主要作用是:按键-值对的格式为表添加额外的文档说明

  

11: 列举某个表的tblproperties 属性信息

  show  tblproperties employees;

 

12: 拷贝表

create table if not exists mydb.employees2 like mydb.employees2  





13:选择数据库

    use mydb

   显示表

show tables;

show tables  IN  mydb;

14: 查看这个表的具体结果信息

describe extended mydb.employees

    使用formatted keyword取代 extended

describe formatted mydb.employees



15: 管理表:内部表:删除表时,会删除这个表的数据

   创建一个外部表:其能够读取全部位于/data/stocks文件夹下的以逗号切割的数据

   create external table if not exists stocks(

   exchange string,

   symbol string,

   ymd String,

   price_open float,

   price_hight float,

   price_low float,

   price_close float,

   volume int,price_adj_close float)

   row  format delimited fields terminated by ','

   location '/data/stocks'



16: 查看表是否是管理表还是外部表

 describe extended tablename

   输出信息:

   tableType.managed_table--管理表

   tableType.external_table--外部表

   

   -- 复制表但不会复制数据

create table if not exists mydb.employees3(新表)

like mydb.employees2(原表)    location '/data/stocks'

   



17: 创建分区表

  create table employees (

  name string,

  salary float,

  subordinates array<string>,

  deductions Map<string,FLOAT>,

  address struct<street:string,city:string,state:String,zip:int>

  )

  partitioned by (country String,state string);



  分区自段:

  country String,state string 和普通字段一样。相当于索引字段。

  依据分区字段查询,提交效率。提高查询性能

  

18: set hive.mapred.mode=strict;

   假设对分区表进行查询而where子句没有加分区过滤的话,

   将会禁止提交这个任务。

   能够设置为:nostrict

  

19: 查看表中存在的全部分区

   show partitions employees;

   

20: 查看是否存储某个特定分区键的分区的话

show partitions employees   partition(country='US');

     describe extended employees 命令也会显示分区键





  管理大型生产数据集最常见的情况:使用外部分区表

21:在管理表中用户能够通过加载数据的方式创建分区:

   load data local inpath '/home/hive/California-employees'


   INTO table employees

   partition(country='US',state='CA');





   hive 将会创建这个分区相应的文件夹..../employees/country=US/state=CA





22:创建外部分区表

   

   create table  if not exists log_messages (

hms  int,

severity string,

server string,

process_id  int,

message  string

 

  )

  partitioned by (year int,month int,day int) 

  row  format delimited fields terminated by '\t'











1:order by  会对输入做全局排序



2: sort能够控制每一个reduce产生的文件都是排序。再对多个排序的好的文件做二次归并排序。



sort by 特点例如以下:

 1) . sort by 基本受hive.mapred.mode是否为strict、nonstrict的影响,但若有分区须要指定分区。

 2). sort by 的数据在同一个reduce中数据是按指定字段排序。

 3). sort by 能够指定运行的reduce个数,如:set mapred.reduce.tasks=5 ,对输出的数据再运行归并排序。即能够得到所有结果。

结果说明:严格模式下,sort by 不指定limit 数,能够正常运行。

sort by 受hive.mapred.mode=sctrict 的影响较小。




3:distribute by 

distribute by 是控制在map端怎样拆分给reduce端。

依据distribute by 后面的列及reduce个数进行数据分发,默认採用hash算法。distribute能够使用length方法会依据string类型的长度划分到不同的reduce中。终于输出到不同的文件里。 length 是内建函数,也能够指定其它的函数或这使用自己定义函数。




4:    cluster by 



cluster by 除了distribute by 的功能外,还会对该字段进行排序,所以cluster by = distribute by +sort by

Hive编程指南_学习笔记01的更多相关文章

  1. 《高质量C++&C 编程指南》学习笔记

    这本电子书是在国科大上课时候,老师在课件资源里边提供的.之所以会重视这个文件,是因为本科时候,有个老师提到过:那个学生遍的代码很整齐,看起来让人舒服,我就知道工大留不下他.因此,我就格外注意这件事,但 ...

  2. 《Hive编程指南》读书笔记 | 一文看懂Hive的数据类型和文件格式

    Hive支持关系型数据库中的大多数基本数据类型,同时也支持关系型数据库中很少出现的3种集合数据类型. 和大多数数据库相比,Hive具有一个独特的功能,那就是其对于数据在文件中的编码方式具有非常大的灵活 ...

  3. javascriptDOM编程艺术_学习笔记_知识点 动态创建标记

    传统技术:document.write 和 innerHTML 深入剖析DOM方法:createElement.createTextNode.appendChild 和 insertBefore   ...

  4. javascriptDOM编程艺术_学习笔记_知识点 DOM

    第三章   getElementById    返回一个与那个有着给定id属性值的元素节点对应的对象. document.getElementById(id) 下面一个例子: document.get ...

  5. 软件测试之loadrunner学习笔记-01事务

    loadrunner学习笔记-01事务<转载至网络> 事务又称为Transaction,事务是一个点为了衡量某个action的性能,需要在开始和结束位置插入一个范围,定义这样一个事务. 作 ...

  6. SaToken学习笔记-01

    SaToken学习笔记-01 SaToken版本为1.18 如果有排版方面的错误,请查看:传送门 springboot集成 根据官网步骤maven导入依赖 <dependency> < ...

  7. hive编程指南--employees表数据定义

    hive编程指南中有个employees表,默认的分隔符比較繁杂,编辑起来不太方便(普通编辑器编辑的控制字符^A等被当成字符串处理了,没有起到分隔符的作用). 收集的解决方式例如以下: http:// ...

  8. 《jQuery权威指南》学习笔记之第2章 jQuery选择器

    2.1 jQuery选择器概述 2.1.1 什么使选择器 2.1.2 选择器的优势: 代码更简单,完善的检测机制  1.代码更简单   示例2-1     使用javascript实现隔行变色 < ...

  9. 《JavaScript面向对象编程指南》读书笔记②

    概述 <JavaScript面向对象编程指南>读书笔记① 这里只记录一下我看JavaScript面向对象编程指南记录下的一些东西.那些简单的知识我没有记录,我只记录几个容易遗漏的或者精彩的 ...

随机推荐

  1. 南邮JAVA程序设计实验1 综合图形界面程序设计

    南邮JAVA程序设计实验1  综合图形界面程序设计 实验目的: 学习和理解JAVA SWING中的容器,部件,布局管理器和部件事件处理方法.通过编写和调试程序,掌握JAVA图形界面程序设计的基本方法. ...

  2. XCODE插件 之 Code Pilot 无鼠标化

    什么是Code Pilot? Code Pilot 是一个 Xcode 5 插件.同意你不许使用鼠标就能高速地查找项目内的文件.方法和标识符. 它使用模糊查询匹配(fuzzy query matchi ...

  3. 【Dubbo实战】基础学习篇(一)

    Dubbo的简单介绍 是什么? Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000多个服务提供30多亿次訪问量支持.并被广泛应用于阿里巴巴集团的各成员网站. Dubbo是一个分布式服 ...

  4. NSAttributedString编程

    - (void)viewDidLoad {     [super viewDidLoad];          NSMutableAttributedString *attributedString ...

  5. kentico中的page template的使用

    父页面使用自己的template 子页面,也使用自己的template. 然后父页面中需要添加一个place holder. 子页面的继承,选择inherit only master page. 这样 ...

  6. nyoj--95--众数问题(水题)

    众数问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 所谓众数,就是对于给定的含有N个元素的多重集合,每个元素在S中出现次数最多的成为该元素的重数, 多重集合S重的重 ...

  7. input file上传文件

    如何使用input[type='file']来上传文件呢? html: //angular<input type="file" (change)="fileChan ...

  8. Codeforces 232E - Quick Tortoise bitset+分治

    题意: 思路: //By SiriusRen #include <cstdio> #include <bitset> #include <vector> using ...

  9. pyspider architecture--官方文档

    原文地址:http://docs.pyspider.org/en/latest/Architecture/ Architecture This document describes the reaso ...

  10. web.config配置文件使用总结

    我们在开发web系统的时候,使用web.config进行配置是司空见惯的,那么web.confg到底是什么呢?什么时候使用web.config呢?有几种使用web.config方式呢? 如果不太明白的 ...