前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >spark submit读写hudi

spark submit读写hudi

作者头像
yiduwangkai
发布2021-09-10 10:58:32
1.1K0
发布2021-09-10 10:58:32
举报
文章被收录于专栏:大数据进阶大数据进阶

测试数据:hudi官方自带的batch_1.json

环境准备:

  1. mysql
  2. kafka:kafka_2.13-2.7.0
  3. hadoop:hadoop-2.10.1
  4. hive:hive-2.3.8 4.1.metastore 4.2hiveserver2

导入工具kafkacat

数据导入:cat batch_1.json | kafkacat -b localhost:9092 -t stock_ticks -P

topic查看:kafkacat -L -b localhost:9092 -t stock_tick

元数据查看:kafkacat -b localhost:9092 -L -J | jq

schema准备:hudi官方自带的schema.avsc

spark这里我们用的是spark-2.4.8-bin-hadoop2.7

执行命令:

1. 非自动同步

代码语言:javascript
复制
bin/spark-submit \
--master yarn \
--class org.apache.hudi.utilities.deltastreamer.HoodieDeltaStreamer /Users/wangkai/apps/install/hudi/hudi-utilities-bundle_2.11-0.9.0-SNAPSHOT.jar \
--table-type COPY_ON_WRITE \
--source-class org.apache.hudi.utilities.sources.JsonKafkaSource \
--source-ordering-field ts \
--target-base-path hdfs:///user/hive/warehouse/stock_ticks_cow \
--target-table stock_ticks_cow \
--props file:///Users/wangkai/apps/install/hudi/kafka-source_1.properties \
--schemaprovider-class org.apache.hudi.utilities.schema.FilebasedSchemaProvider

上述命令执行完,我们分别去hdfs和hive中进行查看

hive中空也

执行同步脚本

代码语言:javascript
复制
./run_sync_tool.sh \
--jdbc-url "jdbc:hive2://localhost:10000" \
--user "xxxx" \
--pass "xxxx" \
--partitioned-by dt \
--base-path hdfs:///user/hive/warehouse/stock_ticks_cow \
--database hudi_stock \
--table stock_ticks_cow

执行完去hive中查看

2.自动同步

代码语言:javascript
复制
bin/spark-submit \
--master yarn \
--class org.apache.hudi.utilities.deltastreamer.HoodieDeltaStreamer /Users/wangkai/apps/install/hudi/hudi-utilities-bundle_2.11-0.9.0-SNAPSHOT.jar \
--table-type COPY_ON_WRITE \
--source-class org.apache.hudi.utilities.sources.JsonKafkaSource \
--source-ordering-field ts \
--target-base-path hdfs:///user/hive/warehouse/stock_ticks_cow \
--target-table stock_ticks_cow \
--props file:///Users/wangkai/apps/install/hudi/kafka-source_1.properties \
--schemaprovider-class org.apache.hudi.utilities.schema.FilebasedSchemaProvider
--disable-compaction --enable-hive-sync

这里主要就最后一句:--enable-hive-sync

执行完上述命令hive中就能看到期望中的表

上诉都是针对的copy on write

下面我们同样的步骤描述一下merge on read

1.非自动同步

代码语言:javascript
复制
bin/spark-submit \
--master yarn \
--class org.apache.hudi.utilities.deltastreamer.HoodieDeltaStreamer /Users/wangkai/apps/install/hudi/hudi-utilities-bundle_2.11-0.9.0-SNAPSHOT.jar \
--table-type MERGE_ON_READ \
--source-class org.apache.hudi.utilities.sources.JsonKafkaSource \
--source-ordering-field ts \
--target-base-path hdfs:///user/hive/warehouse/stock_ticks_test_a \
--target-table stock_ticks_test_a \
--props file:///Users/wangkai/apps/install/hudi/kafka-source_1.properties \
--schemaprovider-class org.apache.hudi.utilities.schema.FilebasedSchemaProvider \

同步脚步

代码语言:javascript
复制
./run_sync_tool.sh \
--jdbc-url "jdbc:hive2://localhost:10000" \
--user "xxx" \
--pass "xxx" \
--partitioned-by dt \
--base-path hdfs:///user/hive/warehouse/stock_ticks_mor \
--database hudi_stock \
--table stock_ticks_mor

hive中查看:

2.自动同步

代码语言:javascript
复制
bin/spark-submit \
--master yarn \
--class org.apache.hudi.utilities.deltastreamer.HoodieDeltaStreamer /Users/wangkai/apps/install/hudi/hudi-utilities-bundle_2.11-0.9.0-SNAPSHOT.jar \
--table-type MERGE_ON_READ \
--source-class org.apache.hudi.utilities.sources.JsonKafkaSource \
--source-ordering-field ts \
--target-base-path hdfs:///user/hive/warehouse/stock_ticks_test_a \
--target-table stock_ticks_test_a \
--props file:///Users/wangkai/apps/install/hudi/kafka-source_1.properties \
--schemaprovider-class org.apache.hudi.utilities.schema.FilebasedSchemaProvider \
--disable-compaction --enable-hive-sync
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档