《Programming Hive》读书笔记(二)Hive基础知识,programminghive



《Programming Hive》读书笔记(二)Hive基础知识

阅读方法:第一遍读是浏览,建立知识索引,因为有些知识不一定能用到,知道就好。感兴趣的部分可以多研究。

以后用的时候再详细看,并结合其他资料一起。



Chapter 3.Data Types and File Formats

原始数据类型和集合数据类型

Select出来的数据,列与列之间的分隔符可以指定


Chapter 4.HiveQL:Data Definition

创建数据库,创建和改动表,分区的操作


Chapter 5.HiveQL:Data Manipulation

1 加载数据和导出数据,应该从本地和HDFS都可以。

2 创建表和将查询结果插入到表中

 

 

Chapter 6.HiveQL:Queries select的各种语法,join,cluster by等

Where支持正则表达式like,rlike

 

JOIN:On条件不支持不等号,不支持OR

1 先join再where,会根据join过滤一批数据,然后根据where过滤一批

2 The partition filters are ignored for OUTER JOINTS. However, usingsuch filter predicates in ON clauses for inner joins does work! 

在outer join中,在on里面写分区条件是没用的。如果想通过分区条件加快速度,可以通过子查询再join的方法。

 

Inner join,left outer join,right outerjoin,left semi join(in的作用,但貌似高版本的hive支持in子查询)

 

hive >SELECT *FROM stocksJOIN dividends

> WHEREstock.symbol= dividends.symboland stock.symbol='AAPL';

Hive里面,这条sql会先算笛卡尔积的再根据where过滤。

In Hive,this query computes the full Cartesianproduct before applying the WHERE

clause. Itcould take a very long time to finish. When the property hive.mapred.modeis

set to strict, Hive prevents users from inadvertentlyissuing a Cartesian product query.

 

两个表join,如果其中一个较小,可以通过map-side-join的方法加快速度。

不过这种优化不支持right-join和full-join。

Hive does not support theoptimization for right- and full-outer joins.

 

优化:满足一定条件,设置对应的参数开启。

 

The ORDER BY clause is familiar from other SQL dialects. It performs atotal orderingof

the query result set.This means that all the data is passed through a single reducer,

which may take an unacceptablylong time to execute for larger data sets.

Order by的排序是全局的,最后全部数据通过一个reducer来排序。

 

Because ORDER BY can result in excessively long run times, Hive willrequire a LIMIT

clause with ORDER BY if the property hive.mapred.mode is set to strict. Bydefault, it is

set to nonstrict.(注意事项)

 

sort by的排序是局部的

 

DISTRIBUTEBY controls how map output isdivided among reducers.

DISTRIBUTEBY可以指定map输出之后如何分配到各个reducer中。

通常是某个字段相同放在同一个reducer中,有点像groupby的思想。

经常跟sort by一起用(DISTRIBUTEBY放前面),达到先分组再内部排序的效果。

 

Cluster by相等于distribute by加上sort by的效果。

 

额外资料:

http://www.cnblogs.com/ggjucheng/archive/2013/01/03/2843243.html

 

cast(valueAS TYPE)

强制性转换时,得注意转换后的值,看看是否达到你所需要的效果。

 

Queries from sample data

随机抽取数据

 

部分未不懂,先不管。

BlockSampling

Input Pruningfor Bucket Tables

 

Union all合并两个表



本文作者:linger

本文链接:http://blog.csdn.net/lingerlanlan/article/details/41153799


相关内容