hive 語句總結 HiveQL查詢語句總結

2021-10-13 08:47:44 字數 1754 閱讀 4981

本文寫作目的是整理出乙份帶注釋的cheatsheet。內容組織形式為查詢語句,例項,原理**。

基本查詢語句

show databases;

create database retail;

use retail;

create table id (val type)

row format delimited

fields terminated by ','

stored as textfile;用textfile的格式儲存**檔案

describe id;

alter table id rename to id_new;

alter table add columns (col_name type);

drop table id;

show tables;

load data inpath "/path" overwrite into table id;

select column_name from id;

設定屬性語句:

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

高階查詢語句

group by:

select column1,sum(column2) from table_1 group by column1;

order by:

略case&creating indexes:

create index rec_index on table records_big(category) as 'compact' with deferred rebuild;

alter index rec_index on records_big rebuild;

show(formatted) index on records_big;

using arrays and maps:

create table cust_info (language array,country_year map)

row format delimited fields terminated by ','

collection items terminated by '#'

map keys terminated by '|';

load data ...;

select language[0] from cust_info;

external tables:

預設internal table

create external table ***();

注意external table和internal table在刪除時的不同表現。

partitioning&bucketing:

join:  convert join mapjoin

select columns from table_a join table_b on condition;

檔案:orcfile

create table *** () row format delimited fields terminated by  ',' stored as orc;

(需要相應設定:set hive.exec.compress.output=true;set mapred.output.compression.type=block;)

通過對比壓縮和非壓縮的方式得出的查詢執行時間以及儲存的檔案大小的差異,得出這種檔案格式的益處在**。

實用函式:

concat

Hive學習 HiveQL 資料定義

hiveql可能和mysql語句接近,但是兩者還是存在顯著差異。hive不支援行級插入操作 更新操作和刪除操作。hive也不支援事務。建立資料庫 create database financials 檢視hive中包含的資料庫 show databases 使用正則匹配篩選出需要的資料庫 show ...

Hive 5 HiveQL 資料操作

5.1 向管理表中裝載資料 hive 沒有行級別的資料插入更新和刪除操作,那麼往表中裝載資料的唯一途徑就是使用一種 大量 的資料裝載操作,或者通過其他方式僅僅將檔案寫入到正確的目錄下 load data local inpath califonia employees overwrite inot ...

Hive(三)常用語法(Hive QL)

1.hive建立資料庫 create database schema if notexists 2.hive建立表 hive裡一般有兩種表的結構,表和外部表,以下分別是兩種表的建立 create table phone info id int,name string,storage string,p...