Hudi對接OBS文件系統
更新時間 2023-06-28 23:46:51
最近更新時間: 2023-06-28 23:46:51
分享文章
本章節主要介紹Hudi對接OBS文件系統。
Hudi對接OBS文件系統
- 使用安裝客戶端用戶登錄客戶端安裝節點。
- 配置環境變量。
source ${client_home}/bigdata_env
source ${client_home}/Hudi/component_env
- 修改配置文件:
vim ${client_home}/Hudi/hudi/conf/hdfs-site.xml
<property>
<name>dfs.namenode.acls.enabled</name>
<value>false</value>
</property>
- 如果是安全集群,使用以下命令用戶進行用戶認證,如果當前集群未啟用Kerberos認證,則無需執行此命令。
kinit 用戶名
- 啟動spark-shell,執行下面的命令創建COW表存儲到OBS中:
importorg.apache.hudi.QuickstartUtils._
importscala.collection.JavaConversions._
importorg.apache.spark.sql.SaveMode._
importorg.apache.hudi.DataSourceReadOptions._
importorg.apache.hudi.DataSourceWriteOptions._
importorg.apache.hudi.config.HoodieWriteConfig._
valtableName = "hudi_cow_table"
valbasePath = "obs://testhudi/cow_table/"
valdataGen = new DataGenerator
valinserts = convertToStringList(dataGen.generateInserts(10))
valdf = spark.read.json(spark.sparkContext.parallelize(inserts, 2))
df.write.format("org.apache.hudi").
options(getQuickstartWriteConfigs).
option(PRECOMBINE_FIELD_OPT_KEY,"ts").
option(RECORDKEY_FIELD_OPT_KEY,"uuid").
option(PARTITIONPATH_FIELD_OPT_KEY,"partitionpath").
option(TABLE_NAME,tableName).
mode(Overwrite).
save(basePath);
- 使用datasource查看表建立成功,數據正常。
valroViewDF = spark.
read.
format("org.apache.hudi").
load(basePath·"/ */* / */* ")
roViewDF.createOrReplaceTempView("hudi_ro_table")
spark.sql("select·from hudi_ro_table").show()
- 執行:q退出spark-shell命令行。