5、hive的基本操作
5.2 資料表相關操作
6、資料的匯入和匯出
1、hive簡介
2、hive與傳統關係型資料庫的比較
專案hive
rdbms
查詢語言
hqlsql
資料儲存
hdfs
raw device or local fs
執行mapreduce
excuter
執行延遲高低
處理資料大小
索引0.8版本後加入位圖索引
有複雜的索引
3、hive的優勢
4、hive的資料型別
4.1 基礎資料型別
資料型別
所佔位元組
開始支援版本
tinyint
1byte,-128 ~ 127
smallint
2byte,-32,768 ~ 32,767
int4byte,-2,147,483,648 ~ 2,147,483,647
bigint
8byte,-9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
boolean
float
4byte單精度
double
8byte雙精度
string
binary
從hive0.8.0開始支援
timestamp
從hive0.8.0開始支援
decimal
從hive0.11.0開始支援
char
從hive0.13.0開始支援
varchar
從hive0.12.0開始支援
date
從hive0.12.0開始支援
4.2 複雜資料型別
資料型別
描述舉例
array
array型別是由一系列相同資料型別的元素組成,這些元素可以通過下標來訪問。
mapmap包含key->value鍵值對,可以通過key來訪問元素。
比如」userlist」是乙個map型別,其中username是key,password是value;那麼我們可以通過userlist[『username』]來得到這個使用者對應的password。
struct
struct可以包含不同資料型別的元素。這些元素可以通過」點語法」的方式來得到所需要的元素。
比如user是乙個struct型別,那麼可以通過user.address得到這個使用者的位址。
建立乙個包含複製型別的**可以如下:
5、hive的基本操作create
table employees (
name string,
salary float
, subordinates array
, deductions mapfloat
>
, address struct>
) partitioned by
(country string, state string)
;
5.1 資料庫相關操作
5.1.1 建立資料庫
語法:
例子:create
(database
/schema)[
ifnot
exists
] database_name
[commit database_comment]
[location hdfs_path]
# 指定資料庫位置
[with dbproperties (property_name=property_value,..
.)];
5.1.2 檢視資料庫create
database db_hive_01 ;
create
database
ifnot
exists db_hive_02; 標準方式
create
database
ifnot
exists db_hive_03
location '/homw/centos/hive/warehouse/db_hive_03.db'
;
5.1.3 修改資料庫show
databases
;# 檢視所有資料庫
show
databases
like
'db_hive*'
;# 模糊查詢
use db_hive;
# 使用資料庫
desc
database db_hive_01;
# 檢視資料庫字段格式等資訊
desc
database
extended db_hive_01;
5.1.4 刪除資料庫alter
database db_hive_01 set
location '/homw/centos/hive/warehouse/db_hive_01.db'
;
5.2 資料表相關操作drop
(database
|schema)[
ifexists
] database_name [
restrict
|cascade];
drop
database db_hive_01;
drop
database db_hive_01 cascade
;# 強制刪除資料庫
drop
database
ifexists db_hive_03;
# 刪除非空的資料庫
5.2.1 建立資料表
方式一:普通建立表
方式二:子查詢方式建立表create
table
ifnot
exists
default
.user_info(
ip string comment
'remote ip address'
,user string
comment
'user_info'
row format delimited fields
terminated
by' '
stored as textfile;
方式三:like方式create
table
ifnot
exists
default
.user_info_a
asselect ip,req_url from
default
.user_info;
5.2.2 檢視資料表create
table stu_like like student;
desc formatted table_name;
5.2.3 修改資料表5.2.4 刪除表和清空表alter
table table_name rename
to new_name;
# 修改表名
alter
table table_name change column_name new_column_name new_type;
# 修改列名
alter
table table_name add
columns
(new_column_name string comment'')
;# 增加新的列
6、資料的匯入和匯出drop
table
ifexists student;
# 刪除表
truncate
table student;
# 清空表的內容,保留表的結構
6.1 資料的匯入
6.2 資料的匯出load
data
local inpath '本地路徑' overwrite into
table 表名;
# 從本地匯入到表中
load
data inpath 'hdfs上的路徑'
into
table 表名;
# 從hdfs匯入到表中
insert overwrite local directory '本地路徑' 查詢語句;
# 將查詢結果的資料匯出到本地
insert overwrite directory 'hdfs上的路徑' 查詢語句;
# 將查詢結果的資料匯出到hdfs
hive基礎知識
1.檢視hive版本號 hive version 1.2.1 2.group by 可以通過字段所在的位置進行groupby 對於1.2.1版本 set hive.groupby.orderby.position.alias true 沒有hive 287的版本,只能使用count 1 替代coun...
hive基礎知識
接觸hive也有一段時間了,一直把它當做傳統的資料庫使用的,沒有出現問題。昨天的時候遇到乙個問題,就是hive表中的資料有重複了,領導讓盡快出方案解決,我想都沒想,直接脫口就說 把重複的刪除 同事告訴我說,hive不支援刪除。當時尷尬到家啦。無知太可怕了,趕緊學習總結一下hive。補補這方面的欠缺。...
Hive基礎知識學習
日期 2012 09 25 字型 大 中 小 1 hive是什麼 按照我的理解,hive 是乙個中間工具。它的主要作用是將 hql hive query language 轉換為一系列的 mapreduce job 利用hadoop 框架對資料進行類 sql處理。他的主要功能是在 hadoop 框架...