jonvex commented on code in PR #8875:
URL: https://github.com/apache/hudi/pull/8875#discussion_r1218336860


##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestInsertIntoOperation.scala:
##########
@@ -0,0 +1,329 @@
+/*
+ * 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.functional
+
+import org.apache.hudi.common.testutils.HoodieTestDataGenerator
+import org.apache.hudi.common.testutils.RawTripTestPayload.recordsToStrings
+import org.apache.spark.sql
+import org.apache.spark.sql.hudi.HoodieSparkSqlTestBase
+import org.apache.hudi.common.model.WriteOperationType
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.table.timeline.TimelineUtils
+
+import scala.collection.JavaConversions._
+
+@DisableCI
+class TestInsertIntoOperation extends HoodieSparkSqlTestBase {
+
+  /**
+   * asserts if number of commits = count
+   * returns true if last commit is bulk insert
+   */
+  def assertCommitCountAndIsLastBulkInsert(basePath: String, count: Int): 
Boolean = {
+    val metaClient = HoodieTableMetaClient.builder()
+      .setBasePath(basePath)
+      .setConf(spark.sessionState.newHadoopConf())
+      .build()
+    val timeline = metaClient.getActiveTimeline.getAllCommitsTimeline
+    assert(timeline.countInstants() == count)
+    val latestCommit = timeline.lastInstant()
+    assert(latestCommit.isPresent)
+    assert(latestCommit.get().isCompleted)
+    val metadata = TimelineUtils.getCommitMetadata(latestCommit.get(), 
timeline)
+    metadata.getOperationType.equals(WriteOperationType.BULK_INSERT)
+  }
+
+  def createTable(tableName: String, writeOptions: String, tableBasePath: 
String): Unit = {
+    spark.sql(
+      s"""
+         | create table $tableName (
+         |  timestamp long,
+         |  _row_key string,
+         |  rider string,
+         |  driver string,
+         |  begin_lat double,
+         |  begin_lon double,
+         |  end_lat double,
+         |  end_lon double,
+         |  fare STRUCT<
+         |    amount: double,
+         |    currency: string >,
+         |  _hoodie_is_deleted boolean,
+         |  partition_path string
+         |) using hudi
+         | partitioned by (partition_path)
+         | $writeOptions
+         | location '$tableBasePath'
+         |
+    """.stripMargin)
+  }
+
+  def generateInserts(dataGen: HoodieTestDataGenerator, instantTime: String, 
n: Int): sql.DataFrame = {
+    val recs = dataGen.generateInsertsNestedExample(instantTime, n)
+    spark.read.json(spark.sparkContext.parallelize(recordsToStrings(recs), 2))
+  }
+
+  def doInsert(dataGen: HoodieTestDataGenerator, tableName: String, 
instantTime: String): Unit = {
+    generateInserts(dataGen, instantTime, 100).select("timestamp", "_row_key", 
"rider", "driver",
+      "begin_lat", "begin_lon", "end_lat", "end_lon", "fare", 
"_hoodie_is_deleted", "partition_path").
+      createOrReplaceTempView("insert_temp_table")
+    spark.sql(s"insert into $tableName select * from insert_temp_table")
+  }
+
+  test("No configs set") {

Review Comment:
   pkless will fail because `HoodieWriteConfig.COMBINE_BEFORE_INSERT.key -> 
String.valueOf(hasPrecombineColumn),` is set in ProvidesHoodieConfig. Do we 
want to change that or no? 
   pkless with no preCombine works



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

Reply via email to