hadoop學習筆記之HiveSQL 資料查詢

2021-07-04 13:12:39 字數 1460 閱讀 4591

資料查詢

select [all | distinct] select_expr, ...

from table_reference

[where where_condition]

[group by col_list]

[cluster by col_list] | [distribute by col_list] [sort by col_list]

[limit number]

查詢正規表示式的列:

select '(ds|dh)? +.+' from sales

多路group by 

from pv_users

insert overwrite table pr_gender_sum

select pv_users.gender, count(distinct pv_users.userid)

group by pv_users.gender

insert overwrite directory '/路徑'

select pv_users.age, count(distinct pv_users.userid)

group by pv_users.age

區別order by全域性排序

sort by 保證reducer輸出有序

distribute by 將資料分到同個reducer

cluster by = distribute by+ sort by

join

內關聯:select a.* from a join b on (a.id=b.id)

外關聯:select a.val, b.val  from a left[right|full] outer join b on (a.key=b.key)

where寫法:select * from table1 t1, talbe2 t2, table3 t3 where t1.id=t2.id and t2.id=t3.id and t1.zipcode='0000';

改寫in語句

select a.key, a.val from a left semi join b on (a.key=b.key)

注意:/* + streamtable(a) */ 指定大表為a 防止這個表放入記憶體

/* + mapjoin(a) */ 指定小表,放入記憶體做mapjoin

union all

虛擬列:

input_file_name

block_offset_inside_file

子查詢subqueries in the from clause

subqueries in the where clause

函式udf,udaf,udtf

詳見技術文件

附:floor, round和ceil是會將double轉換為bigint

時間處理函式要傳入integer或string作為引數

Hadoop學習之Hive簡介

1.hive的基本架構 2.hive的資料儲存 例如 tbl pv 表中包含 ds 和 city 兩個 partition,則對應於 ds 20090801,ctry us 的 hdfs 子目錄為 wh tbl pv ds 20090801 ctry us 對應於 ds 20090801,ctry ...

Hadoop學習筆記之Hadoop簡介

apache hadoop 是乙個開源的 可靠的 靈活的 分布式的計算系統 來自官網 主要受google 三篇 的啟發 gfs mapreduce bigtable hadoop 海量資料的儲存 hdfs hadoop distributed file system 海量資料的分析 mapreduc...

Hadoop學習之HBase和Hive的區別

hive是為簡化編寫mapreduce程式而生的,使用mapreduce做過資料分析的人都知道,很多分析程式除業務邏輯不同外,程式流程基本一樣。在這種情況下,就需要hive這樣的使用者程式設計介面。hive本身不儲存和計算資料,它完全依賴於hdfs和mapreduce,hive中的表純邏輯表,就是些...