Hudi 0.10.1 编译使用

第一章 Hudi 框架之 0.10.1 编译

第一章 Hudi框架之 0.10.1 编译



前言

使用hudi前需进行编译,但是不同版本的编译有坑,这里介绍hudi 0.10.1版本的编译使用

主要问题:

  1. 按照文档编译的包,flink使用hudi无法同步hive!
  2. 和Flink sql on Phoenix 无法同时使用
    我们自己编译解决。

一、Hudi源码下载

1.官网下载

https://hudi.apache.org/cn/releases/download
选择0.10.1最新版本

2.github获取源码

https://github.com/apache/hudi
导入idea中,切换至0.10.1分支

二、编译步骤

参考:
https://www.yuque.com/docs/share/01c98494-a980-414c-9c45-152023bf3c17?#

主要介绍 在参考上述文档编译遇到的几个坑

1.下载Kafka相关依赖

Maven无法自动下载以下依赖需要手动去官网下载。

   confluent-5.3.4\share\java\confluent-control-center\kafka-avro-serializer-5.3.4.jar
   confluent-5.3.4\share\java\confluent-control-center\kafka-schema-registry-client-5.3.4.jar
   confluent-5.3.4\share\java\confluent-common\common-config-5.3.4.jar
   confluent-5.3.4\share\java\confluent-common\common-utils-5.3.4.jar

confluent官网地址:https://www.confluent.io/download
1.填写邮件地址,并且勾选两个条约
2.点击右侧 DOWNLOAD Version 5.3.4(版本号,我下载的是这个版本)
4.稍等一会,压缩包便会下载好,然后解压
5.找出4个jar包目录分别在(下载与pom.xml中confluent对应的版本):

   confluent-5.3.4\share\java\confluent-control-center\kafka-avro-serializer-5.3.4.jar
   confluent-5.3.4\share\java\confluent-control-center\kafka-schema-registry-client-5.3.4.jar
   confluent-5.3.4\share\java\confluent-common\common-config-5.3.4.jar
   confluent-5.3.4\share\java\confluent-common\common-utils-5.3.4.jar
 
6.安装这些jar包到本地仓库
   mvn install:install-file -DgroupId=io.confluent -DartifactId=common-config -Dversion=5.3.4 -Dpackaging=jar -Dfile=./common-config-5.3.4.jar
   mvn install:install-file -DgroupId=io.confluent -DartifactId=common-utils -Dversion=5.3.4 -Dpackaging=jar -Dfile=./common-utils-5.3.4.jar
   mvn install:install-file -DgroupId=io.confluent -DartifactId=kafka-avro-serializer -Dversion=5.3.4 -Dpackaging=jar -Dfile=./kafka-avro-serializer-5.3.4.jar
   mvn install:install-file -DgroupId=io.confluent -DartifactId=kafka-schema-registry-client -Dversion=5.3.4 -Dpackaging=jar -Dfile=./kafka-schema-registry-client-5.3.4.jar

2.根目录打包

先在 $HUDI_HOME 目录下执行命令

 mvn clean install -DskipTests

3.修改Pom.xml文件

由于使用的是hive3.1.2版本,进入 packaging/hudi-flink-bundle 目录,修改pom.xml。

3.1在 include位置 添加

<include>org.apache.hive:hive-standalone-metastore</include>

3.2 在profile位置修改flink-bundle-shade-hive3添加hive-standalone-metastore 依赖

<profile>
  <id>flink-bundle-shade-hive3</id>
  <properties>
    <hive.version>3.1.2</hive.version>
    <flink.bundle.hive.scope>compile</flink.bundle.hive.scope>
  </properties>
  <dependencies>
    <dependency>
      <groupId>${hive.groupid}</groupId>
      <artifactId>hive-service-rpc</artifactId>
      <version>${hive.version}</version>
      <scope>${flink.bundle.hive.scope}</scope>
    </dependency>
    <dependency>
      <groupId>${hive.groupid}</groupId>
      <artifactId>hive-standalone-metastore</artifactId>
      <version>${hive.version}</version>
      <scope>${flink.bundle.hive.scope}</scope>
    </dependency>
  </dependencies>
</profile>

4.打包 bundle jar

在 packaging/hudi-flink-bundle 目录,按照如下操作打 bundle jar:

打包 bundle jar
hudi-flink-bundle_2.11 module pom.xml 默认将 Hive 相关的依赖 scope 设置为 provided,如果想打入 Hive 的依赖,需要显示指定 profile 为 flink-bundle-shade-hive 。执行以下命令打入 Hive 依赖:

mvn install -DskipTests -Drat.skip=true -Pflink-bundle-shade-hive2
# 如果是 hive3 需要使用 profile -Pflink-bundle-shade-hive3
# 如果是 hive1 需要使用 profile -Pflink-bundle-shade-hive1

#注意1:hive1.x现在只能实现同步metadata到hive,而无法使用hive查询,如需查询可使用spark查询hive外表的方法查询。
#注意2: 使用-Pflink-bundle-shade-hive x,需要修改profile中hive的版本为集群对应版本(只需修改profile里的hive版本)。修改位置为packaging/hudi-flink-bundle/pom.xml最下面的对应profile段,找到后修改profile中的hive版本为对应版本即可。

指定 flink 版本
0.11.0 默认的 Flink 适配版本为 Flink 1.14.x,如果想适配 Flink 1.13.x,打包时需加上 profile
-Pflink1.13

编译命令
我们使用的是hive 3.1.2版本 flink为1.13.5版本
这里使用如下命令:

mvn install -DskipTests -Drat.skip=true -Pflink-bundle-shade-hive3 -Pflink1.13

二、如果要适配Flink sql on phoenix 要解决依赖冲突问题

进入 packaging/hudi-flink-bundle 目录 pom文件
1.在 relocations 标签下 添加如下:

        <relocation>
          <pattern>org.apache.hadoop.hbase.</pattern>
          <shadedPattern>${flink.bundle.shade.prefix}org.apache.hadoop.hbase.</shadedPattern>
        </relocation>

2.删除hudi-flink-bundle jar包里的:
hbase-default.xml

否则报错:

Caused by: java.lang.RuntimeException: hbase-default.xml file seems to be for an older version of HBase (1.2.3), this version is 1.4.6

3.当flink on hudi 运行时 ,如果Hive表已经同步 在创建会抛以下错误

2022-04-21 14:03:12,628 INFO  org.apache.hudi.org.apache.hadoop.hive.metastore.HiveMetaStoreClient [] - Closed a connection to metastore, current connections: 0
2022-04-21 14:03:12,628 ERROR org.apache.hudi.sink.StreamWriteOperatorCoordinator          [] - Executor executes action [sync hive metadata for instant 20220421140236703] error
java.lang.NoSuchMethodError: org.apache.hadoop.hive.serde2.thrift.Type.getType(Lorg/apache/hudi/org/apache/hive/service/rpc/thrift/TTypeId;)Lorg/apache/hadoop/hive/serde2/thrift/Type;
	at org.apache.hudi.org.apache.hive.service.cli.TypeDescriptor.<init>(TypeDescriptor.java:47) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.org.apache.hive.service.cli.ColumnDescriptor.<init>(ColumnDescriptor.java:46) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.org.apache.hive.service.cli.TableSchema.<init>(TableSchema.java:46) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.org.apache.hive.jdbc.HiveQueryResultSet.retrieveSchema(HiveQueryResultSet.java:264) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.org.apache.hive.jdbc.HiveQueryResultSet.<init>(HiveQueryResultSet.java:198) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.org.apache.hive.jdbc.HiveQueryResultSet$Builder.build(HiveQueryResultSet.java:179) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.org.apache.hive.jdbc.HiveDatabaseMetaData.getColumns(HiveDatabaseMetaData.java:278) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.hive.ddl.JDBCExecutor.getTableSchema(JDBCExecutor.java:129) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.hive.HoodieHiveClient.getTableSchema(HoodieHiveClient.java:225) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.hive.HiveSyncTool.syncSchema(HiveSyncTool.java:248) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.hive.HiveSyncTool.syncHoodieTable(HiveSyncTool.java:184) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.hive.HiveSyncTool.doSync(HiveSyncTool.java:129) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.hive.HiveSyncTool.syncHoodieTable(HiveSyncTool.java:115) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.sink.StreamWriteOperatorCoordinator.syncHive(StreamWriteOperatorCoordinator.java:302) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at org.apache.hudi.sink.utils.NonThrownExecutor.lambda$execute$0(NonThrownExecutor.java:93) ~[hudi-flink-bundle_2.11-0.10.1.jar:0.10.1]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_202]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_202]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_202]
2022-04-21 14:03:12,629 INFO  org.apache.hudi.client.AbstractHoodieClient                  [] - Stopping Timeline service !!
2022-04-21 14:03:12,629 INFO  org.apache.hudi.client.embedded.EmbeddedTimelineService      [] - Closing Timeline server
2022-04-21 14:03:12,630 INFO  org.apache.hudi.timeline.service.TimelineService             [] - Closing Timeline Service

解决方式:
进入 packaging/hudi-flink-bundle 目录
在pom.xml中relocations 标签中添加以下依赖进行规避解决

        <relocation>
          <pattern>org.apache.hadoop.hive.serde2.</pattern>
          <shadedPattern>${flink.bundle.shade.prefix}org.apache.hadoop.hive.serde2.</shadedPattern>
        </relocation>

重新编译打包,并把jar包中的hbase-default.xml文件删除

总结

编译完成后即可在flink中使用hudi并且可以同步Hive

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值