[
https://issues.apache.org/jira/browse/HUDI-2225?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17388726#comment-17388726
]
ASF GitHub Bot commented on HUDI-2225:
--------------------------------------
yanghua commented on a change in pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#discussion_r678227520
##########
File path:
hudi-examples/src/main/scala/org/apache/hudi/examples/spark/HoodieMorCompactionJob.scala
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hudi.examples.spark
+
+import org.apache.hudi.DataSourceWriteOptions.{PARTITIONPATH_FIELD_OPT_KEY,
PRECOMBINE_FIELD_OPT_KEY, RECORDKEY_FIELD_OPT_KEY, TABLE_TYPE_OPT_KEY}
+import org.apache.hudi.QuickstartUtils.getQuickstartWriteConfigs
+import org.apache.hudi.client.SparkRDDWriteClient
+import org.apache.hudi.client.common.HoodieSparkEngineContext
+import org.apache.hudi.common.model.{HoodieAvroPayload, HoodieRecordPayload,
HoodieTableType}
+import org.apache.hudi.common.util.Option
+import org.apache.hudi.config.HoodieWriteConfig.TABLE_NAME
+import org.apache.hudi.config.{HoodieCompactionConfig, HoodieWriteConfig}
+import org.apache.hudi.examples.common.{HoodieExampleDataGenerator,
HoodieExampleSparkUtils}
+import org.apache.spark.sql.SaveMode.{Append, Overwrite}
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.JavaConverters._
+
+/**
+ * Simple example to run a compaction job for MOR table.
+ * To run this example, you should:
+ * 1. For running in IDE, set VM options `-Dspark.master=local[2]`
+ * 2. For running in shell, using `spark-submit`
+ *
+ * Usage: HoodieMorCompactionJob <tablePath> <tableName>.
+ * <tablePath> and <tableName> describe root path of hudi and table name
+ * for example, `HoodieMorCompactionJob file:///tmp/hoodie/hudi_mor_table
hudi_mor_table`
+ */
+object HoodieMorCompactionJob {
+
+ def main(args: Array[String]): Unit = {
+ if (args.length < 2) {
+ System.err.println("Usage: HoodieMorCompactionJob <tablePath>
<tableName>")
+ System.exit(1)
+ }
+
+ val spark = HoodieExampleSparkUtils.defaultSparkSession("Hudi Spark
compaction example")
Review comment:
`"Hudi Spark compaction example"` -> `"Hudi MOR table compaction via
Spark example"`?
##########
File path:
hudi-examples/src/main/scala/org/apache/hudi/examples/spark/HoodieMorCompactionJob.scala
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hudi.examples.spark
+
+import org.apache.hudi.DataSourceWriteOptions.{PARTITIONPATH_FIELD_OPT_KEY,
PRECOMBINE_FIELD_OPT_KEY, RECORDKEY_FIELD_OPT_KEY, TABLE_TYPE_OPT_KEY}
+import org.apache.hudi.QuickstartUtils.getQuickstartWriteConfigs
+import org.apache.hudi.client.SparkRDDWriteClient
+import org.apache.hudi.client.common.HoodieSparkEngineContext
+import org.apache.hudi.common.model.{HoodieAvroPayload, HoodieRecordPayload,
HoodieTableType}
+import org.apache.hudi.common.util.Option
+import org.apache.hudi.config.HoodieWriteConfig.TABLE_NAME
+import org.apache.hudi.config.{HoodieCompactionConfig, HoodieWriteConfig}
+import org.apache.hudi.examples.common.{HoodieExampleDataGenerator,
HoodieExampleSparkUtils}
+import org.apache.spark.sql.SaveMode.{Append, Overwrite}
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.JavaConverters._
+
+/**
+ * Simple example to run a compaction job for MOR table.
+ * To run this example, you should:
+ * 1. For running in IDE, set VM options `-Dspark.master=local[2]`
+ * 2. For running in shell, using `spark-submit`
+ *
+ * Usage: HoodieMorCompactionJob <tablePath> <tableName>.
+ * <tablePath> and <tableName> describe root path of hudi and table name
+ * for example, `HoodieMorCompactionJob file:///tmp/hoodie/hudi_mor_table
hudi_mor_table`
+ */
+object HoodieMorCompactionJob {
+
+ def main(args: Array[String]): Unit = {
+ if (args.length < 2) {
+ System.err.println("Usage: HoodieMorCompactionJob <tablePath>
<tableName>")
+ System.exit(1)
+ }
+
+ val spark = HoodieExampleSparkUtils.defaultSparkSession("Hudi Spark
compaction example")
+ val dataGen = new HoodieExampleDataGenerator[HoodieAvroPayload]
+ val tablePath = args(0)
+ val tableName = args(1)
+ insertData(spark, tablePath, tableName, dataGen,
HoodieTableType.MERGE_ON_READ.name())
+ updateData(spark, tablePath, tableName, dataGen,
HoodieTableType.MERGE_ON_READ.name())
+ val cfg = HoodieWriteConfig.newBuilder()
+ .withPath(tablePath)
+ .withSchema(HoodieExampleDataGenerator.TRIP_EXAMPLE_SCHEMA)
+ .withParallelism(2, 2)
+ .forTable(tableName)
+ .withCompactionConfig(HoodieCompactionConfig.newBuilder()
+ .withInlineCompaction(true)
+ .withMaxNumDeltaCommitsBeforeCompaction(1).build())
+ .build()
+ val client = new SparkRDDWriteClient[HoodieRecordPayload[Nothing]](new
HoodieSparkEngineContext(spark.sparkContext), cfg)
+ val instant = client.scheduleCompaction(Option.empty())
+ val writeStatues = client.compact(instant.get())
+ client.commitCompaction(instant.get(), writeStatues, Option.empty())
+ client.clean()
+ client.close()
+ spark.stop()
+ }
+
+ def insertData(spark: SparkSession, tablePath: String, tableName: String,
+ dataGen: HoodieExampleDataGenerator[HoodieAvroPayload],
tableType: String): Unit = {
+ val commitTime: String = System.currentTimeMillis().toString
+ val inserts =
dataGen.convertToStringList(dataGen.generateInserts(commitTime, 20))
+ spark.sparkContext.parallelize(inserts.asScala, 2)
+ val df = spark.read.json(spark.sparkContext.parallelize(inserts.asScala,
1))
Review comment:
About line No. 82, is it necessary?
##########
File path:
hudi-examples/src/main/scala/org/apache/hudi/examples/spark/HoodieMorCompactionJob.scala
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hudi.examples.spark
+
+import org.apache.hudi.DataSourceWriteOptions.{PARTITIONPATH_FIELD_OPT_KEY,
PRECOMBINE_FIELD_OPT_KEY, RECORDKEY_FIELD_OPT_KEY, TABLE_TYPE_OPT_KEY}
+import org.apache.hudi.QuickstartUtils.getQuickstartWriteConfigs
+import org.apache.hudi.client.SparkRDDWriteClient
+import org.apache.hudi.client.common.HoodieSparkEngineContext
+import org.apache.hudi.common.model.{HoodieAvroPayload, HoodieRecordPayload,
HoodieTableType}
+import org.apache.hudi.common.util.Option
+import org.apache.hudi.config.HoodieWriteConfig.TABLE_NAME
+import org.apache.hudi.config.{HoodieCompactionConfig, HoodieWriteConfig}
+import org.apache.hudi.examples.common.{HoodieExampleDataGenerator,
HoodieExampleSparkUtils}
+import org.apache.spark.sql.SaveMode.{Append, Overwrite}
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.JavaConverters._
+
+/**
+ * Simple example to run a compaction job for MOR table.
+ * To run this example, you should:
+ * 1. For running in IDE, set VM options `-Dspark.master=local[2]`
+ * 2. For running in shell, using `spark-submit`
+ *
+ * Usage: HoodieMorCompactionJob <tablePath> <tableName>.
+ * <tablePath> and <tableName> describe root path of hudi and table name
+ * for example, `HoodieMorCompactionJob file:///tmp/hoodie/hudi_mor_table
hudi_mor_table`
+ */
+object HoodieMorCompactionJob {
+
+ def main(args: Array[String]): Unit = {
+ if (args.length < 2) {
+ System.err.println("Usage: HoodieMorCompactionJob <tablePath>
<tableName>")
+ System.exit(1)
+ }
+
+ val spark = HoodieExampleSparkUtils.defaultSparkSession("Hudi Spark
compaction example")
+ val dataGen = new HoodieExampleDataGenerator[HoodieAvroPayload]
+ val tablePath = args(0)
+ val tableName = args(1)
+ insertData(spark, tablePath, tableName, dataGen,
HoodieTableType.MERGE_ON_READ.name())
+ updateData(spark, tablePath, tableName, dataGen,
HoodieTableType.MERGE_ON_READ.name())
+ val cfg = HoodieWriteConfig.newBuilder()
+ .withPath(tablePath)
+ .withSchema(HoodieExampleDataGenerator.TRIP_EXAMPLE_SCHEMA)
+ .withParallelism(2, 2)
+ .forTable(tableName)
+ .withCompactionConfig(HoodieCompactionConfig.newBuilder()
+ .withInlineCompaction(true)
+ .withMaxNumDeltaCommitsBeforeCompaction(1).build())
+ .build()
+ val client = new SparkRDDWriteClient[HoodieRecordPayload[Nothing]](new
HoodieSparkEngineContext(spark.sparkContext), cfg)
+ val instant = client.scheduleCompaction(Option.empty())
+ val writeStatues = client.compact(instant.get())
+ client.commitCompaction(instant.get(), writeStatues, Option.empty())
+ client.clean()
+ client.close()
Review comment:
use `try-with-resources` to make sure the client object must be closed
finally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
> Add compaction example
> ----------------------
>
> Key: HUDI-2225
> URL: https://issues.apache.org/jira/browse/HUDI-2225
> Project: Apache Hudi
> Issue Type: Sub-task
> Reporter: Sagar Sumit
> Assignee: Sagar Sumit
> Priority: Major
> Labels: pull-request-available
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)