You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2021/07/26 14:46:11 UTC

[GitHub] [hudi] codope opened a new pull request #3347: [MINOR] Add a compaction job in hudi-examples

codope opened a new pull request #3347:
URL: https://github.com/apache/hudi/pull/3347


   ## What is the purpose of the pull request
   
   This diff adds a scala example of a compaction job, in request of https://apache-hudi.slack.com/archives/C4D716NPQ/p1626912143349100
   
   ## Brief change log
   
   Based on compaction in `HoodieWriteClientExample`.
   
   ## Verify this pull request
   
   Manually verified the change locally.
   
   ## Committer checklist
   
    - [ ] Has a corresponding JIRA in PR title & commit
    
    - [ ] Commit message is descriptive of the change
    
    - [ ] CI is green
   
    - [ ] Necessary doc changes done or have another open PR
          
    - [ ] For large changes, please consider breaking it into sub-tasks under an umbrella JIRA.


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] hudi-bot edited a comment on pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#issuecomment-886770307


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164",
       "triggerID" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1178",
       "triggerID" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "triggerType" : "PUSH"
     }, {
       "hash" : "fcc75ae4f240ce22e5020b10a5c05896b0cbabec",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "fcc75ae4f240ce22e5020b10a5c05896b0cbabec",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 344f6ce74d64cb939c507857c3db10b6b9b56dd4 Azure: [FAILURE](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1178) 
   * fcc75ae4f240ce22e5020b10a5c05896b0cbabec UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run travis` re-run the last Travis build
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] yanghua merged pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
yanghua merged pull request #3347:
URL: https://github.com/apache/hudi/pull/3347


   


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] yanghua commented on a change in pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] hudi-bot edited a comment on pull request #3347: [MINOR] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#issuecomment-886770307


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164",
       "triggerID" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * e46cb2465a28120f3161ea285b666cb67d4c2eb0 Azure: [FAILURE](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run travis` re-run the last Travis build
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] codope commented on pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
codope commented on pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#issuecomment-887191766


   > Hi @codope Thanks for your contribution. Based on the official contribution guide, this PR is not suitable for the "MINOR" category. You should file a Jira ticket then change the title of the PR.
   
   Thanks @yanghua for reviewing. I have edited the title and created an umbrella jira for adding more examples: https://issues.apache.org/jira/browse/HUDI-2224


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] hudi-bot edited a comment on pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#issuecomment-886770307


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164",
       "triggerID" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * e46cb2465a28120f3161ea285b666cb67d4c2eb0 Azure: [FAILURE](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164) 
   * 344f6ce74d64cb939c507857c3db10b6b9b56dd4 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run travis` re-run the last Travis build
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] hudi-bot commented on pull request #3347: [MINOR] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
hudi-bot commented on pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#issuecomment-886770307


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * e46cb2465a28120f3161ea285b666cb67d4c2eb0 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run travis` re-run the last Travis build
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] hudi-bot edited a comment on pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#issuecomment-886770307


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164",
       "triggerID" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1178",
       "triggerID" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "triggerType" : "PUSH"
     }, {
       "hash" : "fcc75ae4f240ce22e5020b10a5c05896b0cbabec",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1265",
       "triggerID" : "fcc75ae4f240ce22e5020b10a5c05896b0cbabec",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * fcc75ae4f240ce22e5020b10a5c05896b0cbabec Azure: [FAILURE](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1265) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run travis` re-run the last Travis build
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] hudi-bot edited a comment on pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#issuecomment-886770307


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164",
       "triggerID" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1178",
       "triggerID" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "triggerType" : "PUSH"
     }, {
       "hash" : "fcc75ae4f240ce22e5020b10a5c05896b0cbabec",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1265",
       "triggerID" : "fcc75ae4f240ce22e5020b10a5c05896b0cbabec",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 344f6ce74d64cb939c507857c3db10b6b9b56dd4 Azure: [FAILURE](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1178) 
   * fcc75ae4f240ce22e5020b10a5c05896b0cbabec Azure: [PENDING](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1265) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run travis` re-run the last Travis build
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] codope commented on a change in pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
codope commented on a change in pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#discussion_r679712827



##########
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:
       Added try-catch-finally. Looks like try-with-resources is not readily available in scala versions earlier than 2.13




-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] hudi-bot edited a comment on pull request #3347: [MINOR] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#issuecomment-886770307


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164",
       "triggerID" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * e46cb2465a28120f3161ea285b666cb67d4c2eb0 Azure: [PENDING](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run travis` re-run the last Travis build
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] codope commented on a change in pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
codope commented on a change in pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#discussion_r679712956



##########
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:
       Good suggestion. Done.




-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] yanghua commented on pull request #3347: [MINOR] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
yanghua commented on pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#issuecomment-887127059


   Hi @codope Thanks for your contribution. Based on the official contribution guide, this PR is not suitable for the "MINOR" category. You should file a Jira ticket then change the title of the PR. 


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] hudi-bot edited a comment on pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#issuecomment-886770307


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164",
       "triggerID" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1178",
       "triggerID" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * e46cb2465a28120f3161ea285b666cb67d4c2eb0 Azure: [FAILURE](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164) 
   * 344f6ce74d64cb939c507857c3db10b6b9b56dd4 Azure: [PENDING](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1178) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run travis` re-run the last Travis build
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] hudi-bot edited a comment on pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
hudi-bot edited a comment on pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#issuecomment-886770307


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1164",
       "triggerID" : "e46cb2465a28120f3161ea285b666cb67d4c2eb0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1178",
       "triggerID" : "344f6ce74d64cb939c507857c3db10b6b9b56dd4",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 344f6ce74d64cb939c507857c3db10b6b9b56dd4 Azure: [FAILURE](https://dev.azure.com/apache-hudi-ci-org/785b6ef4-2f42-4a89-8f0e-5f0d7039a0cc/_build/results?buildId=1178) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run travis` re-run the last Travis build
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [hudi] codope commented on a change in pull request #3347: [HUDI-2225] Add a compaction job in hudi-examples

Posted by GitBox <gi...@apache.org>.
codope commented on a change in pull request #3347:
URL: https://github.com/apache/hudi/pull/3347#discussion_r679712316



##########
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:
       Good catch! Removed it. 




-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org