• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Apache Hudi数据湖hudi-cli客户端使用

武飞扬头像
Bulut0907
帮助1

1. 开启hudi-cli

[root@bigdata001 hudi-cli]# 
[root@bigdata001 hudi-cli]# pwd
/opt/hudi/hudi-master/hudi-cli
[root@bigdata001 hudi-cli]# 
[root@bigdata001 hudi-cli]# sh hudi-cli.sh 
Client jar location not set, please set it in conf/hudi-env.sh
Running : java -cp /opt/hadoop-3.3.1/etc/hadoop:......省略部分......
......省略部分......
===================================================================
*         ___                          ___                        *
*        /\__\          ___           /\  \           ___         *
*       / /  /         /\__\         /  \  \         /\  \        *
*      / /__/         / /  /        / /\ \  \        \ \  \       *
*     /  \  \ ___    / /  /        / /  \ \__\       /  \__\      *
*    / /\ \  /\__\  / /__/  ___   / /__/ \ |__|     / /\/__/      *
*    \/  \ \/ /  /  \ \  \ /\__\  \ \  \ / /  /  /\/ /  /         *
*         \  /  /    \ \  / /  /   \ \  / /  /   \  /__/          *
*         / /  /      \ \/ /  /     \ \/ /  /     \ \__\          *
*        / /  /        \  /  /       \  /  /       \/__/          *
*        \/__/          \/__/         \/__/    Apache Hudi CLI    *
*                                                                 *
===================================================================

Welcome to Apache Hudi CLI. Please type help if you are looking for help. 
hudi->
hudi->help
......省略部分......
hudi->
学新通

2. 创建表

语法如下

hudi->
hudi->create --path hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb --tableName test_tb --tableType COPY_ON_WRITE
2022-03-31 07:50:19,220 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
2022-03-31 07:50:20,657 INFO table.HoodieTableMetaClient: Loading HoodieTableMetaClient from hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb
2022-03-31 07:50:22,221 INFO table.HoodieTableMetaClient: Initializing hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb as hoodie table hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb
2022-03-31 07:50:22,757 INFO table.HoodieTableMetaClient: Loading HoodieTableMetaClient from hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb
2022-03-31 07:50:22,764 INFO table.HoodieTableConfig: Loading table properties from hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb/.hoodie/hoodie.properties
2022-03-31 07:50:22,864 INFO table.HoodieTableMetaClient: Finished Loading Table of type COPY_ON_WRITE(version=1, baseFileFormat=PARQUET) from hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb
2022-03-31 07:50:22,864 INFO table.HoodieTableMetaClient: Finished initializing Table of type COPY_ON_WRITE from hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb
2022-03-31 07:50:22,865 INFO table.HoodieTableMetaClient: Loading HoodieTableMetaClient from hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb
2022-03-31 07:50:22,872 INFO table.HoodieTableConfig: Loading table properties from hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb/.hoodie/hoodie.properties
2022-03-31 07:50:22,881 INFO table.HoodieTableMetaClient: Finished Loading Table of type COPY_ON_WRITE(version=1, baseFileFormat=PARQUET) from hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb
Metadata for table test_tb loaded
hudi:test_tb->

此时HDFS上的目录结构为

hudi_db/test_tb
				|---.hoodie
							|---.aux
									|---.bootstrap
												|---.fileids(目录)
												|---.partitions(目录)
							|---.temp(目录)
							|---archived(目录)
							|---hoodie.properties

3. desc

hudi:test_tb->desc
╔════════════════════════════════╤═════════════════════════════════════════════════════════╗
║ Property                       │ Value                                                   ║
╠════════════════════════════════╪═════════════════════════════════════════════════════════╣
║ basePath                       │ hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb         ║
╟────────────────────────────────┼─────────────────────────────────────────────────────────╢
║ metaPath                       │ hdfs://nnha/user/hudi/warehouse/hudi_db/test_tb/.hoodie ║
╟────────────────────────────────┼─────────────────────────────────────────────────────────╢
║ fileSystem                     │ hdfs                                                    ║
╟────────────────────────────────┼─────────────────────────────────────────────────────────╢
║ hoodie.table.name              │ test_tb                                                 ║
╟────────────────────────────────┼─────────────────────────────────────────────────────────╢
║ hoodie.table.type              │ COPY_ON_WRITE                                           ║
╟────────────────────────────────┼─────────────────────────────────────────────────────────╢
║ hoodie.archivelog.folder       │ archived                                                ║
╟────────────────────────────────┼─────────────────────────────────────────────────────────╢
║ hoodie.timeline.layout.version │ 1                                                       ║
╟────────────────────────────────┼─────────────────────────────────────────────────────────╢
║ hoodie.table.checksum          │ 484490499                                               ║
╟────────────────────────────────┼─────────────────────────────────────────────────────────╢
║ hoodie.table.version           │ 4                                                       ║
╚════════════════════════════════╧═════════════════════════════════════════════════════════╝

hudi:test_tb->
学新通

4. connect表

hudi->connect --path hdfs://nnha/user/hudi/warehouse/hudi_db/my_user
2022-03-31 07:47:08,229 INFO table.HoodieTableMetaClient: Loading HoodieTableMetaClient from hdfs://nnha/user/hudi/warehouse/hudi_db/my_user
2022-03-31 07:47:08,618 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
2022-03-31 07:47:11,361 INFO table.HoodieTableConfig: Loading table properties from hdfs://nnha/user/hudi/warehouse/hudi_db/my_user/.hoodie/hoodie.properties
2022-03-31 07:47:11,662 INFO table.HoodieTableMetaClient: Finished Loading Table of type MERGE_ON_READ(version=1, baseFileFormat=PARQUET) from hdfs://nnha/user/hudi/warehouse/hudi_db/my_user
Metadata for table my_user loaded
hudi:my_user->

5. 查看commit信息

5.1 commits show

hudi:my_user->
hudi:my_user->commits show --sortBy "Total Bytes Written" --desc true --limit 3
2022-03-31 08:07:30,834 INFO timeline.HoodieActiveTimeline: Loaded instants upto : Option{val=[20220326234620162__deltacommit__COMPLETED]}
╔═══════════════════╤═════════════════════╤═══════════════════╤═════════════════════╤══════════════════════════╤═══════════════════════╤══════════════════════════════╤══════════════╗
║ CommitTime        │ Total Bytes Written │ Total Files Added │ Total Files Updated │ Total Partitions Written │ Total Records Written │ Total Update Records Written │ Total Errors ║
╠═══════════════════╪═════════════════════╪═══════════════════╪═════════════════════╪══════════════════════════╪═══════════════════════╪══════════════════════════════╪══════════════╣
║ 20220326233339019 │ 1.8 KB              │ 0                 │ 2                   │ 2                        │ 2                     │ 0                            │ 0            ║
╟───────────────────┼─────────────────────┼───────────────────┼─────────────────────┼──────────────────────────┼───────────────────────┼──────────────────────────────┼──────────────╢
║ 20220326234620162 │ 906.0 B             │ 0                 │ 1                   │ 1                        │ 1                     │ 1                            │ 0            ║
╚═══════════════════╧═════════════════════╧═══════════════════╧═════════════════════╧══════════════════════════╧═══════════════════════╧══════════════════════════════╧══════════════╝

hudi:my_user->

5.2 commit showpartitions

hudi:my_user->commit showpartitions --commit 20220326234620162 --sortBy "Total Bytes Written" --desc true --limit 3
╔═════════════╤══════════════════╤═══════════════════╤═════════════════════╤════════════════════════╤═══════════════════════╤═════════════════════╤══════════════╗
║ Action      │ Partition Path   │ Total Files Added │ Total Files Updated │ Total Records Inserted │ Total Records Updated │ Total Bytes Written │ Total Errors ║
╠═════════════╪══════════════════╪═══════════════════╪═════════════════════╪════════════════════════╪═══════════════════════╪═════════════════════╪══════════════╣
║ deltacommit │ 2022-02-02/japan │ 0                 │ 1                   │ 0                      │ 1                     │ 906.0 B             │ 0            ║
╚═════════════╧══════════════════╧═══════════════════╧═════════════════════╧════════════════════════╧═══════════════════════╧═════════════════════╧══════════════╝

hudi:my_user->

5.3 commit showfiles

hudi:my_user->commit showfiles --commit 20220326234620162 --sortBy "Partition Path"
╔═════════════╤══════════════════╤══════════════════════════════════════╤═══════════════════╤═══════════════════════╤═══════════════════════╤═════════════════════╤══════════════╤═══════════╗
║ Action      │ Partition Path   │ FileId                               │ Previous Commit   │ Total Records Updated │ Total Records Written │ Total Bytes Written │ Total Errors │ File Size ║
╠═════════════╪══════════════════╪══════════════════════════════════════╪═══════════════════╪═══════════════════════╪═══════════════════════╪═════════════════════╪══════════════╪═══════════╣
║ deltacommit │ 2022-02-02/japan │ 8ffd5d1e-abd4-4ad7-ae43-c3c9aa34a859 │ 20220326233339019 │ 1                     │ 1                     │ 906                 │ 0            │ 1810      ║
╚═════════════╧══════════════════╧══════════════════════════════════════╧═══════════════════╧═══════════════════════╧═══════════════════════╧═════════════════════╧══════════════╧═══════════╝

hudi:my_user->

6. 查看FileSystem信息: show fsview

hudi:my_user->show fsview all
2022-03-31 09:29:31,282 INFO table.HoodieTableMetaClient: Loading HoodieTableMetaClient from hdfs://nnha/user/hudi/warehouse/hudi_db/my_user
2022-03-31 09:29:31,319 INFO table.HoodieTableConfig: Loading table properties from hdfs://nnha/user/hudi/warehouse/hudi_db/my_user/.hoodie/hoodie.properties
2022-03-31 09:29:31,329 INFO table.HoodieTableMetaClient: Finished Loading Table of type MERGE_ON_READ(version=1, baseFileFormat=PARQUET) from hdfs://nnha/user/hudi/warehouse/hudi_db/my_user
2022-03-31 09:29:31,329 INFO table.HoodieTableMetaClient: Loading Active commit timeline for hdfs://nnha/user/hudi/warehouse/hudi_db/my_user
2022-03-31 09:29:31,333 INFO timeline.HoodieActiveTimeline: Loaded instants upto : Option{val=[20220326234620162__deltacommit__COMPLETED]}
2022-03-31 09:29:31,426 INFO view.AbstractTableFileSystemView: Took 3 ms to read  0 instants, 0 replaced file groups
2022-03-31 09:29:31,566 INFO util.ClusteringUtils: Found 0 files in pending clustering operations
2022-03-31 09:29:31,574 INFO view.AbstractTableFileSystemView: addFilesToView: NumFiles=0, NumFileGroups=0, FileGroupsCreationTime=6, StoreTimeTaken=1
╔═══════════╤════════╤══════════════╤═══════════╤════════════════╤═════════════════╤═══════════════════════╤═════════════╗
║ Partition │ FileId │ Base-Instant │ Data-File │ Data-File Size │ Num Delta Files │ Total Delta File Size │ Delta Files ║
╠═══════════╧════════╧══════════════╧═══════════╧════════════════╧═════════════════╧═══════════════════════╧═════════════╣
║ (empty)                                                                                                                ║
╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝

hudi:my_user->
hudi:my_user->show fsview latest --partitionPath "2022-02-02/japan"
2022-03-31 09:35:58,118 INFO table.HoodieTableMetaClient: Loading HoodieTableMetaClient from hdfs://nnha/user/hudi/warehouse/hudi_db/my_user
2022-03-31 09:35:58,124 INFO table.HoodieTableConfig: Loading table properties from hdfs://nnha/user/hudi/warehouse/hudi_db/my_user/.hoodie/hoodie.properties
2022-03-31 09:35:58,133 INFO table.HoodieTableMetaClient: Finished Loading Table of type MERGE_ON_READ(version=1, baseFileFormat=PARQUET) from hdfs://nnha/user/hudi/warehouse/hudi_db/my_user
2022-03-31 09:35:58,133 INFO table.HoodieTableMetaClient: Loading Active commit timeline for hdfs://nnha/user/hudi/warehouse/hudi_db/my_user
2022-03-31 09:35:58,138 INFO timeline.HoodieActiveTimeline: Loaded instants upto : Option{val=[20220326234620162__deltacommit__COMPLETED]}
2022-03-31 09:35:58,145 INFO view.AbstractTableFileSystemView: Took 1 ms to read  0 instants, 0 replaced file groups
2022-03-31 09:35:58,149 INFO util.ClusteringUtils: Found 0 files in pending clustering operations
2022-03-31 09:35:58,154 INFO view.AbstractTableFileSystemView: addFilesToView: NumFiles=1, NumFileGroups=1, FileGroupsCreationTime=5, StoreTimeTaken=0
╔══════════════════╤══════════════════════════════════════╤═══════════════════╤═══════════╤════════════════╤═════════════════╤══════════════════╤═══════════════════════════════════╤═════════════════════════════════════╤════════════════════════════════════════════╤══════════════════════════════════════════════╤═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╤══════════════════════════════════════╗
║ Partition        │ FileId                               │ Base-Instant      │ Data-File │ Data-File Size │ Num Delta Files │ Total Delta Size │ Delta Size - compaction scheduled │ Delta Size - compaction unscheduled │ Delta To Base Ratio - compaction scheduled │ Delta To Base Ratio - compaction unscheduled │ Delta Files - compaction scheduled                                                                                                                                            │ Delta Files - compaction unscheduled ║
╠══════════════════╪══════════════════════════════════════╪═══════════════════╪═══════════╪════════════════╪═════════════════╪══════════════════╪═══════════════════════════════════╪═════════════════════════════════════╪════════════════════════════════════════════╪══════════════════════════════════════════════╪═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╪══════════════════════════════════════╣
║ 2022-02-02/japan │ 8ffd5d1e-abd4-4ad7-ae43-c3c9aa34a859 │ 20220326233339019 │           │ -1.0 B         │ 1               │ 1.8 KB           │ 1.8 KB                            │ 0.0 B                               │ -1.0                                       │ -1.0                                         │ [HoodieLogFile{pathStr='hdfs://nnha/user/hudi/warehouse/hudi_db/my_user/2022-02-02/japan/.8ffd5d1e-abd4-4ad7-ae43-c3c9aa34a859_20220326233339019.log.1_0-4-0', fileLen=1810}] │ []                                   ║
╚══════════════════╧══════════════════════════════════════╧═══════════════════╧═══════════╧════════════════╧═════════════════╧══════════════════╧═══════════════════════════════════╧═════════════════════════════════════╧════════════════════════════════════════════╧══════════════════════════════════════════════╧═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╧══════════════════════════════════════╝

hudi:my_user->
学新通

show fsview all查询的结果为empty,可能是因为表有两层partition

7. 文件大小Statistics

hudi:my_user->stats filesizes --partitionPath 2022-02-02/japan --sortBy "95th" --desc true --limit 3
╔═══════════════════╤════════╤════════╤════════╤════════╤════════╤════════╤══════════╤════════╗
║ CommitTime        │ Min    │ 10th   │ 50th   │ avg    │ 95th   │ Max    │ NumFiles │ StdDev ║
╠═══════════════════╪════════╪════════╪════════╪════════╪════════╪════════╪══════════╪════════╣
║ 20220326233339019 │ 1.8 KB │ 1.8 KB │ 1.8 KB │ 1.8 KB │ 1.8 KB │ 1.8 KB │ 1        │ 0.0 B  ║
╟───────────────────┼────────┼────────┼────────┼────────┼────────┼────────┼──────────┼────────╢
║ ALL               │ 1.8 KB │ 1.8 KB │ 1.8 KB │ 1.8 KB │ 1.8 KB │ 1.8 KB │ 1        │ 0.0 B  ║
╚═══════════════════╧════════╧════════╧════════╧════════╧════════╧════════╧══════════╧════════╝

hudi:my_user->

当write时间特别长,可以通过下面的命令查看write amplification写放大

hudi:my_user->stats wa
╔════════════╤════════════════╤═══════════════╤════════════════════════════╗
║ CommitTime │ Total Upserted │ Total Written │ Write Amplification Factor ║
╠════════════╪════════════════╪═══════════════╪════════════════════════════╣
║ Total      │ 0              │ 0             │ 0                          ║
╚════════════╧════════════════╧═══════════════╧════════════════════════════╝

hudi:my_user->

8. Compactions

8.1 查看compaction

hudi:my_user->compactions show all
╔═════════════════════════╤═══════╤═══════════════════════════════╗
║ Compaction Instant Time │ State │ Total FileIds to be Compacted ║
╠═════════════════════════╧═══════╧═══════════════════════════════╣
║ (empty)                                                         ║
╚═════════════════════════════════════════════════════════════════╝

hudi:my_user->
hudi:my_user->
hudi:my_user->compaction show --instant compaction_instant_time
hudi:my_user->

如果compaction_instant_time不存在,会抛异常

8.2 schedule或run compaction

手动schedule或run一个compaction,使用下面的命令,底层是使用spark

hudi:my_user->
hudi:my_user->help compaction schedule
Keyword:                   compaction schedule
Description:               Schedule Compaction
 Keyword:                  sparkMemory
   Help:                   Spark executor memory
   Mandatory:              false
   Default if specified:   '__NULL__'
   Default if unspecified: '1G'

 Keyword:                  propsFilePath
   Help:                   path to properties file on localfs or dfs with configurations for hoodie client for compacting
   Mandatory:              false
   Default if specified:   '__NULL__'
   Default if unspecified: ''

 Keyword:                  hoodieConfigs
   Help:                   Any configuration that can be set in the properties file can be passed here in the form of an array
   Mandatory:              false
   Default if specified:   '__NULL__'
   Default if unspecified: ''

 Keyword:                  sparkMaster
   Help:                   Spark Master
   Mandatory:              false
   Default if specified:   '__NULL__'
   Default if unspecified: 'local'

* compaction schedule - Schedule Compaction

hudi:my_user->
学新通
hudi:my_user->
hudi:my_user->help compaction run
Keyword:                   compaction run
Description:               Run Compaction for given instant time
 Keyword:                  parallelism
   Help:                   Parallelism for hoodie compaction
   Mandatory:              true
   Default if specified:   '__NULL__'
   Default if unspecified: '__NULL__'

 Keyword:                  schemaFilePath
   Help:                   Path for Avro schema file
   Mandatory:              true
   Default if specified:   '__NULL__'
   Default if unspecified: '__NULL__'

 Keyword:                  sparkMaster
   Help:                   Spark Master
   Mandatory:              false
   Default if specified:   '__NULL__'
   Default if unspecified: 'local'

 Keyword:                  sparkMemory
   Help:                   Spark executor memory
   Mandatory:              false
   Default if specified:   '__NULL__'
   Default if unspecified: '4G'

 Keyword:                  retry
   Help:                   Number of retries
   Mandatory:              false
   Default if specified:   '__NULL__'
   Default if unspecified: '1'

 Keyword:                  compactionInstant
   Help:                   Base path for the target hoodie table
   Mandatory:              false
   Default if specified:   '__NULL__'
   Default if unspecified: '__NULL__'

 Keyword:                  propsFilePath
   Help:                   path to properties file on localfs or dfs with configurations for hoodie client for compacting
   Mandatory:              false
   Default if specified:   '__NULL__'
   Default if unspecified: ''

 Keyword:                  hoodieConfigs
   Help:                   Any configuration that can be set in the properties file can be passed here in the form of an array
   Mandatory:              false
   Default if specified:   '__NULL__'
   Default if unspecified: ''

* compaction run - Run Compaction for given instant time

hudi:my_user->
学新通

8.3 验证compaction

验证compaction plan,检测compaction的file是否存在且有效

hudi:my_user->
hudi:my_user->compaction validate --instant compaction_instant_time
hudi:my_user->

8.4 Unscheduling Compaction

取消一个file ID的compaction plan

hudi:my_user->
hudi:my_user->compaction unscheduleFileId --fileId fileID
hudi:my_user->

取消一个compaction plan

hudi:my_user->
hudi:my_user->compaction unschedule --compactionInstant compaction_instant_time
hudi:my_user->

8.5 Repair Compaction

有时Repair Compaction可能会失败,导致compaction operation和file slices的状态不一致。用compaction validate进行验证会失败。所以需要进行compaction repair

hudi:my_user->
hudi:my_user->compaction repair --instant 20181005222611
......省略部分......
Compaction successfully repaired
......省略部分......

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhihchbj
系列文章
更多 icon
同类精品
更多 icon
继续加载