理解Iceberg核心概念可以閱讀博主下面這篇技術(shù)博客:
- Iceberg從入門(mén)到精通系列之一:Iceberg核心概念理解
一、Hive引入Iceberg的jar包
拷貝Iceberg的jar包到Hive的auxlib目錄中
mkdir auxlib
cp iceberg-hive-runtime-1.1.0.jar /opt/module/hive/auxlib
cp libfb303-0.9.3.jar /opt/module/hive/auxlib
二、修改hive-site.xml
<property>
<name>iceberg.engine.hive.enable</name>
<value>true</value>
<property>
<property>
<name>hive.aux.jars.path</name>
<value>/opt/module/hive/auxlib</value>
</property>
三、啟動(dòng)hadoop集群
- 啟動(dòng)hdfs
- 啟動(dòng)yarn
- 啟動(dòng)historyserver
四、啟動(dòng)hive元數(shù)據(jù)服務(wù)
Hive的元數(shù)據(jù)服務(wù)是一種存儲(chǔ)和管理Hive表格和數(shù)據(jù)定義的中央服務(wù),它允許用戶定義表格、分區(qū)和桶等元數(shù)據(jù)信息,并將其存儲(chǔ)在Hive元數(shù)據(jù)存儲(chǔ)庫(kù)中。Hive元數(shù)據(jù)服務(wù)還提供了一個(gè)API,允許用戶檢索、查詢和修改這些元數(shù)據(jù)信息。Hive元數(shù)據(jù)服務(wù)是Hive的重要組成部分,使用戶能夠輕松地管理和使用大規(guī)模數(shù)據(jù)集。它還提供了豐富的元數(shù)據(jù)信息,可以幫助用戶優(yōu)化查詢性能,如使用分區(qū)和桶來(lái)對(duì)數(shù)據(jù)進(jìn)行分組和排序等。
hive --service metastore
更詳細(xì)的步驟如下所示:
在啟動(dòng)Hive之前,需要先啟動(dòng)Hadoop的NameNode和DataNode服務(wù)。然后,可以通過(guò)以下步驟啟動(dòng)Hive元數(shù)據(jù)服務(wù):
- 配置hive-site.xml文件,指定Hive元數(shù)據(jù)存儲(chǔ)庫(kù)的類(lèi)型和連接信息。例如,可以使用MySQL數(shù)據(jù)庫(kù)作為Hive元數(shù)據(jù)存儲(chǔ)庫(kù),需要設(shè)置如下屬性:
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.cj.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive123</value>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
- 啟動(dòng)HiveServer2服務(wù),以提供對(duì)Hive的客戶端連接,并將Hive元數(shù)據(jù)服務(wù)連接到指定的數(shù)據(jù)庫(kù)中??梢允褂靡韵旅顔?dòng)HiveServer2服務(wù):
hive --service hiveserver2
- 啟動(dòng)Hive元數(shù)據(jù)服務(wù),以提供對(duì)Hive元數(shù)據(jù)存儲(chǔ)庫(kù)的訪問(wèn)??梢允褂靡韵旅顔?dòng)Hive元數(shù)據(jù)服務(wù):
hive --service metastore
啟動(dòng)完成后,可以使用Beeline或其他Hive客戶端工具連接到HiveServer2服務(wù),并使用Hive元數(shù)據(jù)服務(wù)來(lái)管理和查詢Hive表格和數(shù)據(jù)。
五、進(jìn)入Hive數(shù)據(jù)庫(kù)
方式一:直接進(jìn)入Hive數(shù)據(jù)庫(kù)
hive
方式二:
使用Beeline連接到HiveServer2服務(wù),可以使用以下命令:
beeline -u jdbc:hive2://:/dbname -n -p
其中,是HiveServer2服務(wù)所在的主機(jī)名,是HiveServer2服務(wù)監(jiān)聽(tīng)的端口號(hào),是連接的Hive數(shù)據(jù)庫(kù)名,是連接的用戶名,是連接的密碼。
例如,連接到HiveServer2服務(wù)所在的主機(jī)名為localhost,端口號(hào)為10000,數(shù)據(jù)庫(kù)名為default,用戶名為hive,密碼為hive123的Hive數(shù)據(jù)庫(kù),可以使用以下命令:
beeline -u jdbc:hive2://localhost:10000/default -n hive -p hive123
六、創(chuàng)建和管理Catalog
- Iceberg支持多種不同的Catalog類(lèi)型,例如:Hive、Hadoop、亞馬遜的AWS Glue和自定義的Catalog
根據(jù)不同配置,分為三種情況:
- 沒(méi)有設(shè)置iceberg.catalog,默認(rèn)使用HiveCatalog
- 設(shè)置了iceberg.catalog的類(lèi)型,使用指定的Catalog類(lèi)型
配置項(xiàng) | 說(shuō)明 |
---|---|
iceberg.catalog.<catalog_name>.type | Catalog的類(lèi)型:hive,hadoop,如果使用自定義Catalog,則不設(shè)置 |
iceberg.catalog.<catalog_name>.catalog-impl | Catalog的實(shí)現(xiàn)類(lèi),如果上面的type沒(méi)有設(shè)置,則此參數(shù)必須設(shè)置 |
iceberg.catalog.<catalog_name>. | Catalog的其他配置項(xiàng) |
- 設(shè)置iceberg.catalog=location_based_table,直接通過(guò)指定的根路徑來(lái)加載Iceberg表
七、使用HiveCatalog
創(chuàng)建表
CREATE TABLE iceberg_test (i int)
STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler';
插入數(shù)據(jù)
INSERT INTO iceberg_test values(1);
查看HDFS可以發(fā)現(xiàn),表目錄在默認(rèn)的hive倉(cāng)庫(kù)路徑下
查看表
describe iceberg_test1;
查看表的詳細(xì)信息:
describe formatted iceberg_test1;
創(chuàng)建的表會(huì)在hive默認(rèn)的路徑下
<!-- Hive默認(rèn)在HDFS的工作目錄 -->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
插入數(shù)據(jù)
insert into iceberg_test1 values(1);
八、指定Catalog類(lèi)型HiveCatalog
set iceberg.catalog.iceberg_hive.type=hive;
set iceberg.catalog.iceberg_hive.url=thrift://hadoop1:9083;
set iceberg.catalog.iceberg_hive.clients=10;
set iceberg.catalog.iceberg_hive.warehouse=hdfs://hadoop1:8020/warehouse/iceberg-hive;
創(chuàng)建表
CREATE TABLE iceberg_test2 (i int)
STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler'
TBLPROPERTIES('iceberg.catalog'='iceberg_hive');
INSERT INTO iceberg_test2 values(1);
查看表的詳細(xì)信息:
describe formatted iceberg_test1;
九、指定Catalog類(lèi)型HadoopCatalog
set iceberg.catalog.iceberg_hadoop.type=hadoop;
set iceberg.catalog.iceberg_hadoop.warehouse=hdfs://hadoop1:8020/warehouse/iceberg-hadoop
創(chuàng)建表
CREATE TABLE iceberg_test3 (i int)
STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler'
LOCATION 'hdfs://hadoop1:8020/warehouse/iceberg-hadoop/default/iceberg_test3'
TBLPROPERTIES('iceberg.catalog'='iceberg_hadoop');
插入數(shù)據(jù)
INSERT INTO iceberg_test3 values(1);
十、指定路徑加載
如果HDFS中已經(jīng)存在iceberg格式表,可以通過(guò)在Hive中創(chuàng)建iceberg格式表指定對(duì)應(yīng)的location路徑映射數(shù)據(jù)。
CREATE EXTERNAL TABLE iceberg_test4(i int)
STORED BY 'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler'
LOCATION 'hdfs://hadoop1:8020/warehouse/iceberg-hadoop/default/iceberg_test3'
TBLPROPERTIES ('iceberg.catalog'='location_based_table');
- 加載已經(jīng)存在的iceberg表iceberg_test3的數(shù)據(jù),要求表結(jié)構(gòu)相同,路徑定位到表iceberg_test3
- TBLPROPERTIES (‘iceberg.catalog’=‘location_based_table’);默認(rèn)值
查詢數(shù)據(jù)
select * from iceberg_test4;
- 如果創(chuàng)建的表是內(nèi)部表iceberg_test4,刪除表iceberg_test4,會(huì)導(dǎo)致iceberg_test3表的數(shù)據(jù)被刪除。
- 如果創(chuàng)建的表是外部表,刪除表iceberg_test4,不會(huì)影響表iceberg_test3表的數(shù)據(jù)。
十一、Hive內(nèi)部表和外部表的區(qū)別
補(bǔ)充Hive內(nèi)部表和外部表的區(qū)別:
在Hive中,內(nèi)部表和外部表是兩種不同的表格類(lèi)型。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-653132.html
- 內(nèi)部表是通過(guò)Hive自己的存儲(chǔ)格式存儲(chǔ)在Hive倉(cāng)庫(kù)目錄下的表格,其數(shù)據(jù)和元數(shù)據(jù)都由Hive管理。數(shù)據(jù)和表格的定義存儲(chǔ)在Hive倉(cāng)庫(kù)的目錄結(jié)構(gòu)中。內(nèi)部表有一個(gè)默認(rèn)的存儲(chǔ)位置,當(dāng)用戶刪除表格時(shí),Hive會(huì)刪除表格的數(shù)據(jù)和元數(shù)據(jù)。
- 外部表是基于現(xiàn)有數(shù)據(jù)文件或表格的定義創(chuàng)建的Hive表格。外部表的數(shù)據(jù)和元數(shù)據(jù)都保存在外部數(shù)據(jù)源中,Hive只是指向這些數(shù)據(jù)源,并提供表格的結(jié)構(gòu),作為對(duì)數(shù)據(jù)源的抽象表示。當(dāng)用戶刪除外部表時(shí),只有元數(shù)據(jù)被刪除,而不會(huì)刪除實(shí)際的存儲(chǔ)數(shù)據(jù)。
因此,內(nèi)部表和外部表的主要區(qū)別在于數(shù)據(jù)和元數(shù)據(jù)的存儲(chǔ)位置和管理方式。內(nèi)部表由Hive管理數(shù)據(jù)和元數(shù)據(jù),而外部表只由Hive管理元數(shù)據(jù),實(shí)際的存儲(chǔ)數(shù)據(jù)由外部數(shù)據(jù)源維護(hù)。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-653132.html
到了這里,關(guān)于Iceberg從入門(mén)到精通系列之二:Iceberg集成Hive的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!