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 2019/12/19 03:26:26 UTC

[GitHub] [incubator-hudi] hddong opened a new pull request #1114: [HUDI-438] Merge duplicated code fragment

hddong opened a new pull request #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114
 
 
   Merge duplicated code fragment
   
   ## Brief change log
   
   *(for example:)*
     - *Merge duplicated code fragment in HoodieSparkSqlWriter.scala *
   
   ## Verify this pull request
   
   This pull request is a trivial rework / code cleanup without any test coverage.
   
   ## 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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] hddong commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
hddong commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#discussion_r360700084
 
 

 ##########
 File path: hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
 ##########
 @@ -225,52 +179,7 @@ private[hudi] object HoodieSparkSqlWriter {
       // Issue deletes
       commitTime = client.startCommit()
       writeStatuses = DataSourceUtils.doDeleteOperation(client, hoodieKeysToDelete, commitTime)
-      val errorCount = writeStatuses.rdd.filter(ws => ws.hasErrors).count()
-      writeSuccessful =
-        if (errorCount == 0) {
-          log.info("No errors. Proceeding to commit the write.")
-          val metaMap = parameters.filter(kv =>
-            kv._1.startsWith(parameters(COMMIT_METADATA_KEYPREFIX_OPT_KEY)))
-          val commitSuccess = if (metaMap.isEmpty) {
-            client.commit(commitTime, writeStatuses)
-          } else {
-            client.commit(commitTime, writeStatuses,
-              common.util.Option.of(new util.HashMap[String, String](mapAsJavaMap(metaMap))))
-          }
-
-          if (commitSuccess) {
-            log.info("Commit " + commitTime + " successful!")
-          }
-          else {
-            log.info("Commit " + commitTime + " failed!")
-          }
-
-          val hiveSyncEnabled = parameters.get(HIVE_SYNC_ENABLED_OPT_KEY).exists(r => r.toBoolean)
-          val syncHiveSucess = if (hiveSyncEnabled) {
-            log.info("Syncing to Hive Metastore (URL: " + parameters(HIVE_URL_OPT_KEY) + ")")
-            val fs = FSUtils.getFs(basePath.toString, jsc.hadoopConfiguration)
-            syncHive(basePath, fs, parameters)
-          } else {
-            true
-          }
-          client.close()
-          commitSuccess && syncHiveSucess
-        } else {
-          log.error(s"$operation failed with ${errorCount} errors :");
-          if (log.isTraceEnabled) {
-            log.trace("Printing out the top 100 errors")
-            writeStatuses.rdd.filter(ws => ws.hasErrors)
-              .take(100)
-              .foreach(ws => {
-                log.trace("Global error :", ws.getGlobalError)
-                if (ws.getErrors.size() > 0) {
-                  ws.getErrors.foreach(kt =>
-                    log.trace(s"Error for key: ${kt._1}", kt._2))
-                }
-              })
-          }
-          false
-        }
+      checkWriteStatus(writeStatuses, parameters, client, commitTime, basePath, operation, jsc)
 
 Review comment:
   > this is good enough. But did you get a chance to try to get checkWriteStatus(writeStatuses, parameters, client, commitTime, basePath, operation, jsc) outside the if else block. in other words, instead of calling both inside if and else, can we call it after if else block. If thats doable.
   
   I had attempt to, but found it's hard to call it after if else block because of genericity. Maybe we can move it out later when we find a good solution.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] leesf merged pull request #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
leesf merged pull request #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114
 
 
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] vinothchandar commented on issue #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
vinothchandar commented on issue #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#issuecomment-568223973
 
 
   @leesf and @nsivabalan leave it to you both to decide and merge. 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] hddong commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
hddong commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#discussion_r361399105
 
 

 ##########
 File path: hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
 ##########
 @@ -225,52 +179,7 @@ private[hudi] object HoodieSparkSqlWriter {
       // Issue deletes
       commitTime = client.startCommit()
       writeStatuses = DataSourceUtils.doDeleteOperation(client, hoodieKeysToDelete, commitTime)
-      val errorCount = writeStatuses.rdd.filter(ws => ws.hasErrors).count()
-      writeSuccessful =
-        if (errorCount == 0) {
-          log.info("No errors. Proceeding to commit the write.")
-          val metaMap = parameters.filter(kv =>
-            kv._1.startsWith(parameters(COMMIT_METADATA_KEYPREFIX_OPT_KEY)))
-          val commitSuccess = if (metaMap.isEmpty) {
-            client.commit(commitTime, writeStatuses)
-          } else {
-            client.commit(commitTime, writeStatuses,
-              common.util.Option.of(new util.HashMap[String, String](mapAsJavaMap(metaMap))))
-          }
-
-          if (commitSuccess) {
-            log.info("Commit " + commitTime + " successful!")
-          }
-          else {
-            log.info("Commit " + commitTime + " failed!")
-          }
-
-          val hiveSyncEnabled = parameters.get(HIVE_SYNC_ENABLED_OPT_KEY).exists(r => r.toBoolean)
-          val syncHiveSucess = if (hiveSyncEnabled) {
-            log.info("Syncing to Hive Metastore (URL: " + parameters(HIVE_URL_OPT_KEY) + ")")
-            val fs = FSUtils.getFs(basePath.toString, jsc.hadoopConfiguration)
-            syncHive(basePath, fs, parameters)
-          } else {
-            true
-          }
-          client.close()
-          commitSuccess && syncHiveSucess
-        } else {
-          log.error(s"$operation failed with ${errorCount} errors :");
-          if (log.isTraceEnabled) {
-            log.trace("Printing out the top 100 errors")
-            writeStatuses.rdd.filter(ws => ws.hasErrors)
-              .take(100)
-              .foreach(ws => {
-                log.trace("Global error :", ws.getGlobalError)
-                if (ws.getErrors.size() > 0) {
-                  ws.getErrors.foreach(kt =>
-                    log.trace(s"Error for key: ${kt._1}", kt._2))
-                }
-              })
-          }
-          false
-        }
+      checkWriteStatus(writeStatuses, parameters, client, commitTime, basePath, operation, jsc)
 
 Review comment:
   > this is good enough. But did you get a chance to try to get checkWriteStatus(writeStatuses, parameters, client, commitTime, basePath, operation, jsc) outside the if else block. in other words, instead of calling both inside if and else, can we call it after if else block. If thats doable.
   
   @nsivabalan After some try, it was move out to the outside of if else block.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] leesf commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
leesf commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#discussion_r363036834
 
 

 ##########
 File path: hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
 ##########
 @@ -340,4 +247,72 @@ private[hudi] object HoodieSparkSqlWriter {
     hiveSyncConfig.partitionValueExtractorClass = parameters(HIVE_PARTITION_EXTRACTOR_CLASS_OPT_KEY)
     hiveSyncConfig
   }
+
+  /**
+   * Running into issues wrt generic type conversion from Java to Scala.  Couldn't make common code paths for
+   * write and deletes. Specifically, instantiating client of type HoodieWriteClient<T extends HoodieRecordPayload>
+   * is having issues. Hence some codes blocks are same in both if and else blocks.
 
 Review comment:
   Is this comment needed? could we remove 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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] nsivabalan commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
nsivabalan commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#discussion_r360439969
 
 

 ##########
 File path: hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
 ##########
 @@ -225,52 +179,7 @@ private[hudi] object HoodieSparkSqlWriter {
       // Issue deletes
       commitTime = client.startCommit()
       writeStatuses = DataSourceUtils.doDeleteOperation(client, hoodieKeysToDelete, commitTime)
-      val errorCount = writeStatuses.rdd.filter(ws => ws.hasErrors).count()
-      writeSuccessful =
-        if (errorCount == 0) {
-          log.info("No errors. Proceeding to commit the write.")
-          val metaMap = parameters.filter(kv =>
-            kv._1.startsWith(parameters(COMMIT_METADATA_KEYPREFIX_OPT_KEY)))
-          val commitSuccess = if (metaMap.isEmpty) {
-            client.commit(commitTime, writeStatuses)
-          } else {
-            client.commit(commitTime, writeStatuses,
-              common.util.Option.of(new util.HashMap[String, String](mapAsJavaMap(metaMap))))
-          }
-
-          if (commitSuccess) {
-            log.info("Commit " + commitTime + " successful!")
-          }
-          else {
-            log.info("Commit " + commitTime + " failed!")
-          }
-
-          val hiveSyncEnabled = parameters.get(HIVE_SYNC_ENABLED_OPT_KEY).exists(r => r.toBoolean)
-          val syncHiveSucess = if (hiveSyncEnabled) {
-            log.info("Syncing to Hive Metastore (URL: " + parameters(HIVE_URL_OPT_KEY) + ")")
-            val fs = FSUtils.getFs(basePath.toString, jsc.hadoopConfiguration)
-            syncHive(basePath, fs, parameters)
-          } else {
-            true
-          }
-          client.close()
-          commitSuccess && syncHiveSucess
-        } else {
-          log.error(s"$operation failed with ${errorCount} errors :");
-          if (log.isTraceEnabled) {
-            log.trace("Printing out the top 100 errors")
-            writeStatuses.rdd.filter(ws => ws.hasErrors)
-              .take(100)
-              .foreach(ws => {
-                log.trace("Global error :", ws.getGlobalError)
-                if (ws.getErrors.size() > 0) {
-                  ws.getErrors.foreach(kt =>
-                    log.trace(s"Error for key: ${kt._1}", kt._2))
-                }
-              })
-          }
-          false
-        }
+      checkWriteStatus(writeStatuses, parameters, client, commitTime, basePath, operation, jsc)
 
 Review comment:
   this is good enough. But did you get a chance to try to get checkWriteStatus(writeStatuses, parameters, client, commitTime, basePath, operation, jsc) outside the if else block. in other words, instead of calling both inside if and else, can we call it after if else block. If thats doable. 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] nsivabalan commented on issue #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
nsivabalan commented on issue #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#issuecomment-567979175
 
 
   and close Hudi-439 (ticket I created for the same purpose)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] hddong commented on issue #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
hddong commented on issue #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#issuecomment-569010457
 
 
   @nsivabalan @vinothchandar @leesf pls review again.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] leesf commented on issue #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
leesf commented on issue #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#issuecomment-570787718
 
 
   @hddong Sorry for lately reply, would you please rebase to lastest master branch and fix scala checkstyle error?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] hddong commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
hddong commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#discussion_r360699643
 
 

 ##########
 File path: hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
 ##########
 @@ -85,7 +84,7 @@ private[hudi] object HoodieSparkSqlWriter {
     // Running into issues wrt generic type conversion from Java to Scala.  Couldn't make common code paths for
     // write and deletes. Specifically, instantiating client of type HoodieWriteClient<T extends HoodieRecordPayload>
     // is having issues. Hence some codes blocks are same in both if and else blocks.
-    if (!operation.equalsIgnoreCase(DELETE_OPERATION_OPT_VAL)) {
+    val writeSuccessful = if (!operation.equalsIgnoreCase(DELETE_OPERATION_OPT_VAL)) {
 
 Review comment:
   > can you remove the above comment
   
   Move to checkWriteStatus's javadoc.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] hddong commented on issue #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
hddong commented on issue #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#issuecomment-571518957
 
 
   @leesf @nsivabalan thanks for your review.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] nsivabalan commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
nsivabalan commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#discussion_r360439059
 
 

 ##########
 File path: hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
 ##########
 @@ -85,7 +84,7 @@ private[hudi] object HoodieSparkSqlWriter {
     // Running into issues wrt generic type conversion from Java to Scala.  Couldn't make common code paths for
     // write and deletes. Specifically, instantiating client of type HoodieWriteClient<T extends HoodieRecordPayload>
     // is having issues. Hence some codes blocks are same in both if and else blocks.
-    if (!operation.equalsIgnoreCase(DELETE_OPERATION_OPT_VAL)) {
+    val writeSuccessful = if (!operation.equalsIgnoreCase(DELETE_OPERATION_OPT_VAL)) {
 
 Review comment:
   can you remove the above comment

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-hudi] hddong commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment

Posted by GitBox <gi...@apache.org>.
hddong commented on a change in pull request #1114: [HUDI-438] Merge duplicated code fragment
URL: https://github.com/apache/incubator-hudi/pull/1114#discussion_r360700084
 
 

 ##########
 File path: hudi-spark/src/main/scala/org/apache/hudi/HoodieSparkSqlWriter.scala
 ##########
 @@ -225,52 +179,7 @@ private[hudi] object HoodieSparkSqlWriter {
       // Issue deletes
       commitTime = client.startCommit()
       writeStatuses = DataSourceUtils.doDeleteOperation(client, hoodieKeysToDelete, commitTime)
-      val errorCount = writeStatuses.rdd.filter(ws => ws.hasErrors).count()
-      writeSuccessful =
-        if (errorCount == 0) {
-          log.info("No errors. Proceeding to commit the write.")
-          val metaMap = parameters.filter(kv =>
-            kv._1.startsWith(parameters(COMMIT_METADATA_KEYPREFIX_OPT_KEY)))
-          val commitSuccess = if (metaMap.isEmpty) {
-            client.commit(commitTime, writeStatuses)
-          } else {
-            client.commit(commitTime, writeStatuses,
-              common.util.Option.of(new util.HashMap[String, String](mapAsJavaMap(metaMap))))
-          }
-
-          if (commitSuccess) {
-            log.info("Commit " + commitTime + " successful!")
-          }
-          else {
-            log.info("Commit " + commitTime + " failed!")
-          }
-
-          val hiveSyncEnabled = parameters.get(HIVE_SYNC_ENABLED_OPT_KEY).exists(r => r.toBoolean)
-          val syncHiveSucess = if (hiveSyncEnabled) {
-            log.info("Syncing to Hive Metastore (URL: " + parameters(HIVE_URL_OPT_KEY) + ")")
-            val fs = FSUtils.getFs(basePath.toString, jsc.hadoopConfiguration)
-            syncHive(basePath, fs, parameters)
-          } else {
-            true
-          }
-          client.close()
-          commitSuccess && syncHiveSucess
-        } else {
-          log.error(s"$operation failed with ${errorCount} errors :");
-          if (log.isTraceEnabled) {
-            log.trace("Printing out the top 100 errors")
-            writeStatuses.rdd.filter(ws => ws.hasErrors)
-              .take(100)
-              .foreach(ws => {
-                log.trace("Global error :", ws.getGlobalError)
-                if (ws.getErrors.size() > 0) {
-                  ws.getErrors.foreach(kt =>
-                    log.trace(s"Error for key: ${kt._1}", kt._2))
-                }
-              })
-          }
-          false
-        }
+      checkWriteStatus(writeStatuses, parameters, client, commitTime, basePath, operation, jsc)
 
 Review comment:
   > this is good enough. But did you get a chance to try to get checkWriteStatus(writeStatuses, parameters, client, commitTime, basePath, operation, jsc) outside the if else block. in other words, instead of calling both inside if and else, can we call it after if else block. If thats doable.
   
   I had attempt to, but found it's hard to call it after if else block because of genericity. Maybe we can move it out later when we find a good solution.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services