自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Apache Hive:基于Hadoop的分布式數(shù)據(jù)倉(cāng)庫(kù)

數(shù)據(jù)庫(kù) Hadoop
Apache Hive 是一個(gè)基于 Apache Hadoop 構(gòu)建的開(kāi)源分布式數(shù)據(jù)倉(cāng)庫(kù)系統(tǒng),支持使用 SQL 執(zhí)行 PB 級(jí)大規(guī)模數(shù)據(jù)分析與查詢。

Apache Hive 是一個(gè)基于 Apache Hadoop 構(gòu)建的開(kāi)源分布式數(shù)據(jù)倉(cāng)庫(kù)系統(tǒng),支持使用 SQL 執(zhí)行 PB 級(jí)大規(guī)模數(shù)據(jù)分析與查詢。

主要功能

Apache Hive 提供的主要功能如下。

HiveServer2

HiveServer2 服務(wù)用于支持接收客戶端連接和查詢請(qǐng)求。

HiveServer2 支持多客戶端并發(fā)和身份驗(yàn)證,基于 Thrift RPC 實(shí)現(xiàn),允許客戶端使用 JDBC、ODBC 等連接方式。以下是一個(gè)使用 Beeline 客戶端工具連接 Apache Hive 的示例:

beeline -u "jdbc:hive2://host:10001/default"
Connected to: Apache Hive

jdbc:hive2://host:10001/>select count(*) from test_t1;

HiveServer2 服務(wù)同時(shí)還包含了一個(gè)基于 Jetty 的網(wǎng)站服務(wù),用于提供 Web 瀏覽器訪問(wèn)方式。

Hive Metastore

Hive Metastore(HMS)提供了一個(gè)管理元數(shù)據(jù)的集中式資料庫(kù),并且通過(guò) API 服務(wù)提供客戶端查詢。

Hive Metastore 已經(jīng)成為了構(gòu)建數(shù)據(jù)湖的核心基礎(chǔ)模塊,這些數(shù)據(jù)湖充分融合了包括 Apache Spark 和 Presto 在內(nèi)的多樣化開(kāi)源生態(tài)系統(tǒng)。

ACID

對(duì)于 Apache ORC 格式的數(shù)據(jù)表,Apache Hive 提供了完整的 ACID 事務(wù)支持;對(duì)其他所有數(shù)據(jù)格式,僅支持追加(Insert-Only)操作。

數(shù)據(jù)壓縮

Apache Hive 的數(shù)據(jù)壓縮(Data Compaction)是針對(duì)支持 ACID 事務(wù)的表(通常是 ORC 格式表)的優(yōu)化機(jī)制,用于提高查詢性能并減少存儲(chǔ)開(kāi)銷。例如:

jdbc:hive2://> alter table test_t1 compact "MAJOR";
Done!

jdbc:hive2://> alter table test_t1 compact "MINOR";
Done!

jdbc:hive2://> show compactions;

Iceberg集成

Apache Hive 提供了 Apache Iceberg 數(shù)據(jù)表的原生支持,用戶可以直接通過(guò) Hive 的 SQL 接口創(chuàng)建、管理和查詢 Iceberg 表,而無(wú)需依賴外部工具或復(fù)雜配置。

低延遲分析處理

Apache Hive 通過(guò)低延遲分析處理(LLAP,Low Latency Analytical Processing)實(shí)現(xiàn)交互式與亞秒級(jí) SQL 查詢。

Apache Hive LLAP 通過(guò)持久化服務(wù)與智能緩存填補(bǔ)了傳統(tǒng) Hive 在實(shí)時(shí)分析場(chǎng)景的短板,使其能夠兼顧高吞吐批處理與低延遲交互查詢。

查詢優(yōu)化

Apache Hive 利用 Apache Calcite 框架提供的基于成本優(yōu)化(CBO)方式實(shí)現(xiàn) SQL 查詢的性能優(yōu)化。

以下是一個(gè)使用 EXPLAIN 命令獲取執(zhí)行計(jì)劃的示例:

jdbc:hive2://> explain cbo select ss.ss_net_profit, sr.sr_net_loss from store_sales ss join store_returns sr on (ss.ss_item_sk=sr.sr_item_sk) limit 5;
+---------------------------------------------+
 Explain
+---------------------------------------------+
 CBO PLAN:
 HiveSortLimit(fetch=[5])
 HiveProject(ss_net_profit=[$1], sr_net_loss=[$3])
 ??HiveJoin(condition=[=($0, $2)], joinType=[inner])
 ????HiveProject(ss_item_sk=[$2], ss_net_profit=[$22])
 ????HiveFilter(condition=[IS NOT NULL($2)])
 ??????HiveTableScan(table=[[tpcds_text_10, store_sales]], table:alias=[ss])
 ????HiveProject(sr_item_sk=[$2], sr_net_loss=[$19])
 ????HiveFilter(condition=[IS NOT NULL($2)])
 ??????HiveTableScan(table=[[tpcds_text_10, store_returns]], table:alias=[sr])
+---------------------------------------------+

數(shù)據(jù)復(fù)制

Apache Hive 的引導(dǎo)式復(fù)制(Bootstrap Replication)和增量復(fù)制(Incremental Replication)實(shí)現(xiàn)了高效數(shù)據(jù)備份與恢復(fù)。

jdbc:hive2://> repl dump src with (
.. .>'hive.repl.dump.version'='2',
.. .>'hive.repl.rootdir'='hdfs://<host>:<port>/user/replDir/d1'
.. .>);
Done!

jdbc:hive2://> repl load src into tgt with (
.. .>'hive.repl.rootdir'='hdfs://<host>:<port>/user/replDir/d1'
.. .>);
Done!

快速試用

接下來(lái)我們使用 Docker 快速體驗(yàn) Apache Hive。

首先,獲取最新的鏡像:

docker pull apache/hive:4.0.1

然后設(shè)置版本變量:

export HIVE_VERSION=4.0.1

啟動(dòng) HiveServer2 服務(wù),使用嵌入式 Derby 數(shù)據(jù)庫(kù)作為元數(shù)據(jù)存儲(chǔ):

docker run -d -p 10000:10000 -p 10002:10002 --env SERVICE_NAME=hiveserver2 --name hive4 apache/hive:${HIVE_VERSION}

注意,這種方式在服務(wù)關(guān)閉時(shí)會(huì)丟棄所有的數(shù)據(jù);如果想要持久存儲(chǔ)數(shù)據(jù)表,可以使用外部數(shù)據(jù)庫(kù)和存儲(chǔ)。

接下來(lái)利用 Beeline 客戶端連接數(shù)據(jù)庫(kù):

docker exec -it hive4 beeline -u 'jdbc:hive2://localhost:10000/'

或者也可以通過(guò)瀏覽器進(jìn)行訪問(wèn):http://localhost:10002/

在 Beeline 客戶端中執(zhí)行以下 SQL 語(yǔ)句:

show tables;
createtable hive_example(a string, b int) partitioned by(c int);
altertable hive_example addpartition(c=1);
insertinto hive_example partition(c=1)values('a',1),('a',2),('b',3);
selectcount(distinct a)from hive_example;
selectsum(b)from hive_example;


責(zé)任編輯:華軒 來(lái)源: SQL編程思想
相關(guān)推薦

2017-02-28 09:21:56

HadoopHive數(shù)據(jù)倉(cāng)庫(kù)

2016-01-06 10:22:18

開(kāi)源eBayHadoop

2015-07-29 10:36:05

hadoop數(shù)據(jù)挖掘

2014-07-26 15:22:31

趙修湘關(guān)系型數(shù)據(jù)庫(kù)Hive數(shù)據(jù)倉(cāng)庫(kù)

2012-09-19 14:09:20

Hadoop開(kāi)源

2021-04-15 07:40:44

數(shù)據(jù)倉(cāng)庫(kù)Hive環(huán)境搭建

2015-04-21 09:39:03

javajava分布式爬蟲

2017-10-24 11:28:23

Zookeeper分布式鎖架構(gòu)

2014-07-15 11:15:44

hadoop分布式部署

2018-04-26 18:23:37

華為

2017-08-10 10:17:32

Hadoop分布式搭建

2019-09-26 15:43:52

Hadoop集群防火墻

2011-12-22 09:21:04

云計(jì)算Hadoop大數(shù)據(jù)

2016-09-01 13:48:18

2020-04-03 15:22:49

Hadoop數(shù)據(jù)倉(cāng)庫(kù)數(shù)據(jù)庫(kù)

2022-03-08 15:24:23

BitMapRedis數(shù)據(jù)

2017-04-13 10:51:09

Consul分布式

2009-01-19 13:54:58

ERP數(shù)據(jù)倉(cāng)庫(kù)應(yīng)用研究

2020-04-06 13:52:45

數(shù)據(jù)倉(cāng)庫(kù)大數(shù)據(jù)平臺(tái)Hadoop

2016-12-21 12:46:47

數(shù)據(jù)倉(cāng)庫(kù)SQLHive
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)