marchpure commented on a change in pull request #4043:
URL: https://github.com/apache/carbondata/pull/4043#discussion_r537069006



##########
File path: 
integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/iud/IUDConcurrencyTestCase.scala
##########
@@ -0,0 +1,474 @@
+/*
+ * 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.carbondata.spark.testsuite.iud
+
+import java.sql.Date
+import java.text.SimpleDateFormat
+import java.util.concurrent.{Callable, Executors, Future}
+
+import mockit.{Mock, MockUp}
+import org.apache.spark.sql.{DataFrame, Row, SaveMode}
+import 
org.apache.spark.sql.execution.command.mutation.{CarbonProjectForDeleteCommand, 
CarbonProjectForUpdateCommand}
+import org.apache.spark.sql.test.util.QueryTest
+import org.apache.spark.sql.types.StructType
+import org.scalatest.BeforeAndAfterAll
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.exception.ConcurrentOperationException
+import org.apache.carbondata.core.util.CarbonProperties
+import org.apache.carbondata.spark.rdd.CarbonDataRDDFactory
+
+class IUDConcurrencyTestCase extends QueryTest with BeforeAndAfterAll {
+
+  val ONE_LOAD_SIZE = 5
+  var testData: DataFrame = _
+
+  override def beforeAll(): Unit = {
+    sql("DROP DATABASE IF EXISTS iud_concurrency CASCADE")
+    sql("CREATE DATABASE iud_concurrency")
+    sql("USE iud_concurrency")
+
+    buildTestData()
+
+    createTable("orders", testData.schema)
+    createTable("temp_table", testData.schema)
+    createTable("orders_temp_table", testData.schema)
+
+    testData.write
+      .format("carbondata")
+      .option("tableName", "temp_table")
+      .option("tempCSV", "false")
+      .mode(SaveMode.Overwrite)
+      .save()
+
+    sql("insert into orders select * from temp_table")
+    sql("insert into orders_temp_table select * from temp_table")
+  }
+
+  private def buildTestData(): Unit = {
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.CARBON_DATE_FORMAT, "yyyy-MM-dd")
+    import sqlContext.implicits._
+    val sdf = new SimpleDateFormat("yyyy-MM-dd")
+
+    testData = sqlContext.sparkSession.sparkContext.parallelize(1 to 
ONE_LOAD_SIZE)
+      .map(value => (value, new Date(sdf.parse("2015-07-" + (value % 10 + 
10)).getTime),
+        "china", "aaa" + value, "phone" + 555 * value, "ASD" + (60000 + 
value), 14999 + value,
+        "ordersTable" + value))
+      .toDF("o_id", "o_date", "o_country", "o_name",
+        "o_phonetype", "o_serialname", "o_salary", "o_comment")
+  }
+
+  private def createTable(tableName: String, schema: StructType): Unit = {
+    val schemaString = schema.fields.map(x => x.name + " " + 
x.dataType.typeName).mkString(", ")
+    sql(s"CREATE TABLE $tableName ($schemaString) stored as carbondata 
tblproperties" +
+      s"('sort_scope'='local_sort', 'sort_columns'='o_country, o_name, 
o_phonetype, o_serialname," +
+      s"o_comment")
+  }
+
+  // ----------------------- Insert and Update ------------------------
+  // update -> insert -> update
+  test("Update should success when insert completes before it") {
+    val updateSql = "update orders set (o_country)=('newCountry') where 
o_country='china'"
+    val insertSql = "insert into orders select * from orders_temp_table"
+
+    val mockInsert = new MockUp[CarbonProjectForUpdateCommand]() {
+      @Mock
+      def mockForConcurrentInsertTest(): Unit = {

Review comment:
       you shall not mock in this way.

##########
File path: 
integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/iud/IUDConcurrencyTestCase.scala
##########
@@ -0,0 +1,474 @@
+/*
+ * 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.carbondata.spark.testsuite.iud
+
+import java.sql.Date
+import java.text.SimpleDateFormat
+import java.util.concurrent.{Callable, Executors, Future}
+
+import mockit.{Mock, MockUp}
+import org.apache.spark.sql.{DataFrame, Row, SaveMode}
+import 
org.apache.spark.sql.execution.command.mutation.{CarbonProjectForDeleteCommand, 
CarbonProjectForUpdateCommand}
+import org.apache.spark.sql.test.util.QueryTest
+import org.apache.spark.sql.types.StructType
+import org.scalatest.BeforeAndAfterAll
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.exception.ConcurrentOperationException
+import org.apache.carbondata.core.util.CarbonProperties
+import org.apache.carbondata.spark.rdd.CarbonDataRDDFactory
+
+class IUDConcurrencyTestCase extends QueryTest with BeforeAndAfterAll {
+
+  val ONE_LOAD_SIZE = 5
+  var testData: DataFrame = _
+
+  override def beforeAll(): Unit = {
+    sql("DROP DATABASE IF EXISTS iud_concurrency CASCADE")
+    sql("CREATE DATABASE iud_concurrency")
+    sql("USE iud_concurrency")
+
+    buildTestData()
+
+    createTable("orders", testData.schema)
+    createTable("temp_table", testData.schema)
+    createTable("orders_temp_table", testData.schema)
+
+    testData.write
+      .format("carbondata")
+      .option("tableName", "temp_table")
+      .option("tempCSV", "false")
+      .mode(SaveMode.Overwrite)
+      .save()
+
+    sql("insert into orders select * from temp_table")
+    sql("insert into orders_temp_table select * from temp_table")
+  }
+
+  private def buildTestData(): Unit = {
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.CARBON_DATE_FORMAT, "yyyy-MM-dd")
+    import sqlContext.implicits._
+    val sdf = new SimpleDateFormat("yyyy-MM-dd")
+
+    testData = sqlContext.sparkSession.sparkContext.parallelize(1 to 
ONE_LOAD_SIZE)

Review comment:
       use insert instead of saving dataframe 

##########
File path: 
integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/iud/IUDConcurrencyTestCase.scala
##########
@@ -0,0 +1,474 @@
+/*
+ * 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.carbondata.spark.testsuite.iud
+
+import java.sql.Date
+import java.text.SimpleDateFormat
+import java.util.concurrent.{Callable, Executors, Future}
+
+import mockit.{Mock, MockUp}
+import org.apache.spark.sql.{DataFrame, Row, SaveMode}
+import 
org.apache.spark.sql.execution.command.mutation.{CarbonProjectForDeleteCommand, 
CarbonProjectForUpdateCommand}
+import org.apache.spark.sql.test.util.QueryTest
+import org.apache.spark.sql.types.StructType
+import org.scalatest.BeforeAndAfterAll
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.exception.ConcurrentOperationException
+import org.apache.carbondata.core.util.CarbonProperties
+import org.apache.carbondata.spark.rdd.CarbonDataRDDFactory
+
+class IUDConcurrencyTestCase extends QueryTest with BeforeAndAfterAll {
+
+  val ONE_LOAD_SIZE = 5
+  var testData: DataFrame = _
+
+  override def beforeAll(): Unit = {
+    sql("DROP DATABASE IF EXISTS iud_concurrency CASCADE")
+    sql("CREATE DATABASE iud_concurrency")
+    sql("USE iud_concurrency")
+
+    buildTestData()
+
+    createTable("orders", testData.schema)
+    createTable("temp_table", testData.schema)
+    createTable("orders_temp_table", testData.schema)
+
+    testData.write
+      .format("carbondata")
+      .option("tableName", "temp_table")
+      .option("tempCSV", "false")
+      .mode(SaveMode.Overwrite)
+      .save()
+
+    sql("insert into orders select * from temp_table")
+    sql("insert into orders_temp_table select * from temp_table")
+  }
+
+  private def buildTestData(): Unit = {
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.CARBON_DATE_FORMAT, "yyyy-MM-dd")
+    import sqlContext.implicits._
+    val sdf = new SimpleDateFormat("yyyy-MM-dd")
+
+    testData = sqlContext.sparkSession.sparkContext.parallelize(1 to 
ONE_LOAD_SIZE)
+      .map(value => (value, new Date(sdf.parse("2015-07-" + (value % 10 + 
10)).getTime),
+        "china", "aaa" + value, "phone" + 555 * value, "ASD" + (60000 + 
value), 14999 + value,
+        "ordersTable" + value))
+      .toDF("o_id", "o_date", "o_country", "o_name",
+        "o_phonetype", "o_serialname", "o_salary", "o_comment")
+  }
+
+  private def createTable(tableName: String, schema: StructType): Unit = {
+    val schemaString = schema.fields.map(x => x.name + " " + 
x.dataType.typeName).mkString(", ")
+    sql(s"CREATE TABLE $tableName ($schemaString) stored as carbondata 
tblproperties" +
+      s"('sort_scope'='local_sort', 'sort_columns'='o_country, o_name, 
o_phonetype, o_serialname," +
+      s"o_comment")
+  }
+
+  // ----------------------- Insert and Update ------------------------
+  // update -> insert -> update
+  test("Update should success when insert completes before it") {
+    val updateSql = "update orders set (o_country)=('newCountry') where 
o_country='china'"
+    val insertSql = "insert into orders select * from orders_temp_table"
+
+    val mockInsert = new MockUp[CarbonProjectForUpdateCommand]() {
+      @Mock
+      def mockForConcurrentInsertTest(): Unit = {
+        val insertFuture = runSqlAsync(insertSql)
+        assert(insertFuture.get().contains("PASS"))
+      }
+    }
+
+    val updateFuture = runSqlAsync(updateSql)
+    assert(updateFuture.get().contains("PASS"))
+    mockInsert.tearDown()
+
+    checkAnswer(
+      sql("select count(1) from orders o_country='newCountry'"), 
Seq(Row(ONE_LOAD_SIZE)))
+    checkAnswer(
+      sql("select count(1) from orders where o_country='china'"), 
Seq(Row(ONE_LOAD_SIZE)))
+  }
+
+  // insert -> update -> insert

Review comment:
       "insert -> update -> insert" 
   
   Confused. What do you want to say?




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to