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 2022/02/24 09:03:10 UTC

[GitHub] [hudi] xushiyan commented on a change in pull request #4535: [HUDI-3161] Add Call Produce Command for Spark SQL

xushiyan commented on a change in pull request #4535:
URL: https://github.com/apache/hudi/pull/4535#discussion_r813527294



##########
File path: hudi-cli/src/main/java/org/apache/hudi/cli/commands/CommitsCommand.java
##########
@@ -88,9 +87,8 @@ private String printCommits(HoodieDefaultTimeline timeline,
     }
 
     final Map<String, Function<Object, String>> fieldNameToConverterMap = new HashMap<>();
-    fieldNameToConverterMap.put(HoodieTableHeaderFields.HEADER_TOTAL_BYTES_WRITTEN, entry -> {
-      return NumericUtils.humanReadableByteCount((Double.valueOf(entry.toString())));
-    });
+    fieldNameToConverterMap.put(HoodieTableHeaderFields.HEADER_TOTAL_BYTES_WRITTEN,
+        entry -> NumericUtils.humanReadableByteCount((Double.parseDouble(entry.toString()))));

Review comment:
       ditto

##########
File path: hudi-cli/src/main/java/org/apache/hudi/cli/Table.java
##########
@@ -118,14 +118,12 @@ public Table flip() {
    * @return
    */
   private List<List<Comparable>> orderRows() {
-    return orderingFieldNameOptional.map(orderingColumnName -> {
-      return rawRows.stream().sorted((row1, row2) -> {
-        Comparable fieldForRow1 = row1.get(rowHeader.indexOf(orderingColumnName));
-        Comparable fieldForRow2 = row2.get(rowHeader.indexOf(orderingColumnName));
-        int cmpRawResult = fieldForRow1.compareTo(fieldForRow2);
-        return isDescendingOptional.map(isDescending -> isDescending ? -1 * cmpRawResult : cmpRawResult).orElse(cmpRawResult);
-      }).collect(Collectors.toList());
-    }).orElse(rawRows);
+    return orderingFieldNameOptional.map(orderingColumnName -> rawRows.stream().sorted((row1, row2) -> {

Review comment:
       @XuQianJin-Stars let's try to avoid style changes among other logic changes. it's hard for reviewers to tell if any logical change here, esp. when GH can't highlight the change like for indentation. We definitely want to tackle auto-formatting some time soon in this jira https://issues.apache.org/jira/browse/HUDI-1237 

##########
File path: hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/procedures/BaseProcedure.scala
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.spark.sql.hudi.command.procedures
+
+import org.apache.hudi.client.SparkRDDWriteClient
+import org.apache.hudi.client.common.HoodieSparkEngineContext
+import org.apache.hudi.common.model.HoodieRecordPayload
+import org.apache.hudi.config.{HoodieIndexConfig, HoodieWriteConfig}
+import org.apache.hudi.index.HoodieIndex.IndexType
+import org.apache.spark.api.java.JavaSparkContext
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.types._
+
+abstract class BaseProcedure extends Procedure {
+  val spark: SparkSession = SparkSession.active
+  val jsc = new JavaSparkContext(spark.sparkContext)
+
+  protected def sparkSession: SparkSession = spark
+
+  protected def createHoodieClient(jsc: JavaSparkContext, basePath: String): SparkRDDWriteClient[_ <: HoodieRecordPayload[_ <: AnyRef]] = {
+    val config = getWriteConfig(basePath)
+    new SparkRDDWriteClient(new HoodieSparkEngineContext(jsc), config)
+  }
+
+  protected def getWriteConfig(basePath: String): HoodieWriteConfig = {
+    HoodieWriteConfig.newBuilder
+      .withPath(basePath)
+      .withIndexConfig(HoodieIndexConfig.newBuilder.withIndexType(IndexType.BLOOM).build)
+      .withRollbackUsingMarkers(false)
+      .build
+  }
+
+  protected def checkArgs(target: Array[ProcedureParameter], args: ProcedureArgs): Unit = {
+    val internalRow = args.internalRow
+    for (i <- target.indices) {
+      if (target(i).required) {
+        var argsIndex: Integer = null
+        if (args.isNamedArgs) {
+          argsIndex = getArgsIndex(target(i).name, args)
+        } else {
+          argsIndex = getArgsIndex(i.toString, args)
+        }
+        assert(-1 != argsIndex && internalRow.get(argsIndex, target(i).dataType) != null,
+          s"Argument: ${target(i).name} is required")
+      }
+    }
+  }
+
+  protected def getArgsIndex(key: String, args: ProcedureArgs): Integer = {
+    args.map.getOrDefault(key, -1)

Review comment:
       better make this a constant like `INVALID_ARG_INDEX = -1` so it's clear and explicit when used.




-- 
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