测试数据:hudi官方自带的batch_1.json
环境准备:
- mysql
- kafka:kafka_2.13-2.7.0
- hadoop:hadoop-2.10.1
- 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