# Hive 101: Hive Query Language

• View
98

3

Embed Size (px)

DESCRIPTION

Hive 101: Hive Query Language. 2014-08-21. Jeff Clouse. Agenda. What is Hive HUE HQL Select Operators Functions Joins Sub Queries Union Hive best practices. What is Hive. High level implementation of MapReduce Language is Hive Query Language - HQL - PowerPoint PPT Presentation

### Text of Hive 101: Hive Query Language

Hive 101

A & BBitwise and of A and BA | BBitwise or of A and B A ^ BBitwise xor of A and B~ABitwise negation of A9 2014 Inmar, Inc. All Rights Reserved. 2013 Inmar, Inc. All Rights Reserved.HQL Logical OperatorsA and B, A && BBoolean and of A and BA or B, A || BBoolean or of A and BNOT A, !ABoolean negation of AA [NOT] IN (B,)A is in [or not] a set of values

Year(date)Month(date)Datediff(date1, date2)Date_add(startdate, days)11Length(A)Upper(A)Concat(A, B, )Substring(A, start ,len)Trim(A)

Sum(A)Count(*)Min(A)Max(A)

2014 Inmar, Inc. All Rights Reserved. 2013 Inmar, Inc. All Rights Reserved.HQL JoinsJoinSelect * from table1 t1 join table2 t2 on t1.key = t2.keyOnly returns records from both tablesOuter JoinsLeftSelect * from table1 t1 left join table2 t2 on t1.key = t2.keyReturns all rows from the left table, t1, and matching rows from the right table. Missing rows from the right table will be populated with NULLRight Select * from table1 t1 right join table2 t2 on t1.key = t2.keyReturns all rows from the right table, t2, and matching rows from the left table. Missing rows from the left table will be populated with NULLFull Select * from table1 t1 full outer join table2 t2 on t1.key = t2.keyReturns all rows from both tables. Missing rows from either table will be populated with NULL

PARTITION BY with two partitioning columns, no ORDER BY or window specificationSELECT a, COUNT(b) OVER (PARTITION BY c, d) FROM T;

PARTITION BY with one partitioning column, one ORDER BY column, and no window specificationSELECT a, SUM(b) OVER (PARTITION BY c ORDER BY d) FROM T;

PARTITION BY with two partitioning columns, two ORDER BY columns, and no window specificationSELECT a, SUM(b) OVER (PARTITION BY c, d ORDER BY e, f) FROM T;

PARTITION BY with partitioning, ORDER BY, and window specificationSELECT a, SUM(b) OVER (PARTITION BY c ORDER BY d ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM T;SELECT a, AVG(b) OVER (PARTITION BY c ORDER BY d ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) FROM T;SELECT a, AVG(b) OVER (PARTITION BY c ORDER BY d ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING) FROM T;SELECT a, AVG(b) OVER (PARTITION BY c ORDER BY d ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) FROM T;

LEAD using default 1 row lead and not specifying default valueSELECT a, LEAD(a) OVER (PARTITION BY b ORDER BY C ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) FROM T;

LAG specifying a lag of 3 rows and default value of 0SELECT a, LAG(a, 3, 0) OVER (PARTITION BY b ORDER BY C ROWS 3 PRECEDING) FROM T;

Recommended

Documents
Documents
Documents
Documents
Technology
Documents
Technology
Technology
Documents
Documents
Documents
Documents