You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by ja...@apache.org on 2017/09/14 09:20:33 UTC

[40/54] [abbrv] carbondata git commit: [CARBONDATA-1446] Fixed Bug for error message on invalid partition id in alter partition command

[CARBONDATA-1446] Fixed Bug for error message on invalid partition id in alter partition command

1.In alter partition command, if the user has given invalid partition id ( that is, partition id which does not exist ), this case is not handled, and the invalid partition id results in inappropriate exception further in code.
2.In this PR, an appropriate exception is thrown for Invalid Partition Id.
3.Added test case for the same in class TestAlterPartitionTable.scala

This closes #1320


Project: http://git-wip-us.apache.org/repos/asf/carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/carbondata/commit/92f34700
Tree: http://git-wip-us.apache.org/repos/asf/carbondata/tree/92f34700
Diff: http://git-wip-us.apache.org/repos/asf/carbondata/diff/92f34700

Branch: refs/heads/streaming_ingest
Commit: 92f347008fbdcf2a80d1f8b0c7f9e316a2524127
Parents: fc39b28
Author: ksimar <si...@gmail.com>
Authored: Mon Sep 4 18:13:32 2017 +0530
Committer: Jacky Li <ja...@qq.com>
Committed: Tue Sep 12 22:11:34 2017 +0800

----------------------------------------------------------------------
 .../scala/org/apache/spark/util/PartitionUtils.scala     |  8 ++++++--
 .../testsuite/partition/TestAlterPartitionTable.scala    | 11 +++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/carbondata/blob/92f34700/integration/spark-common/src/main/scala/org/apache/spark/util/PartitionUtils.scala
----------------------------------------------------------------------
diff --git a/integration/spark-common/src/main/scala/org/apache/spark/util/PartitionUtils.scala b/integration/spark-common/src/main/scala/org/apache/spark/util/PartitionUtils.scala
index 184ab9e..3982f7b 100644
--- a/integration/spark-common/src/main/scala/org/apache/spark/util/PartitionUtils.scala
+++ b/integration/spark-common/src/main/scala/org/apache/spark/util/PartitionUtils.scala
@@ -80,12 +80,16 @@ object PartitionUtils {
       dateFormatter: SimpleDateFormat): Unit = {
     val columnDataType = partitionInfo.getColumnSchemaList.get(0).getDataType
     val index = partitionIdList.indexOf(partitionId)
+    if (index < 0) {
+      throw new IllegalArgumentException("Invalid Partition Id " + partitionId +
+        "\n Use show partitions table_name to get the list of valid partitions")
+    }
     if (partitionInfo.getPartitionType == PartitionType.RANGE) {
       val rangeInfo = partitionInfo.getRangeInfo.asScala.toList
       val newRangeInfo = partitionId match {
         case 0 => rangeInfo ++ splitInfo
         case _ => rangeInfo.take(index - 1) ++ splitInfo ++
-                  rangeInfo.takeRight(rangeInfo.size - index)
+          rangeInfo.takeRight(rangeInfo.size - index)
       }
       CommonUtil.validateRangeInfo(newRangeInfo, columnDataType,
         timestampFormatter, dateFormatter)
@@ -102,7 +106,7 @@ object PartitionUtils {
       val newListInfo = partitionId match {
         case 0 => originList ++ addListInfo
         case _ => originList.take(index - 1) ++ addListInfo ++
-                  originList.takeRight(originList.size - index)
+          originList.takeRight(originList.size - index)
       }
       partitionInfo.setListInfo(newListInfo.map(_.asJava).asJava)
     }

http://git-wip-us.apache.org/repos/asf/carbondata/blob/92f34700/integration/spark2/src/test/scala/org/apache/carbondata/spark/testsuite/partition/TestAlterPartitionTable.scala
----------------------------------------------------------------------
diff --git a/integration/spark2/src/test/scala/org/apache/carbondata/spark/testsuite/partition/TestAlterPartitionTable.scala b/integration/spark2/src/test/scala/org/apache/carbondata/spark/testsuite/partition/TestAlterPartitionTable.scala
index 090a636..9de2ef5 100644
--- a/integration/spark2/src/test/scala/org/apache/carbondata/spark/testsuite/partition/TestAlterPartitionTable.scala
+++ b/integration/spark2/src/test/scala/org/apache/carbondata/spark/testsuite/partition/TestAlterPartitionTable.scala
@@ -342,6 +342,17 @@ class TestAlterPartitionTable extends QueryTest with BeforeAndAfterAll {
     checkAnswer(result_after5, result_origin5)
   }
 
+  test("test exception if invalid partition id is provided in alter command") {
+    sql("drop table if exists test_invalid_partition_id")
+
+    sql("CREATE TABLE test_invalid_partition_id (CUST_NAME String,ACTIVE_EMUI_VERSION string,DOB Timestamp,DOJ timestamp, " +
+      "BIGINT_COLUMN1 bigint,BIGINT_COLUMN2 bigint,DECIMAL_COLUMN1 decimal(30,10), DECIMAL_COLUMN2 decimal(36,10)," +
+      "Double_COLUMN1 double, Double_COLUMN2 double,INTEGER_COLUMN1 int) PARTITIONED BY (CUST_ID int)" +
+      " STORED BY 'org.apache.carbondata.format' " +
+      "TBLPROPERTIES ('PARTITION_TYPE'='RANGE','RANGE_INFO'='9090,9500,9800',\"TABLE_BLOCKSIZE\"= \"256 MB\")")
+    intercept[IllegalArgumentException] { sql("ALTER TABLE test_invalid_partition_id SPLIT PARTITION(6) INTO ('9800','9900')") }
+  }
+
   test("Alter table split partition: List Partition") {
     sql("""ALTER TABLE list_table_country SPLIT PARTITION(4) INTO ('Canada', 'Russia', '(Good, NotGood)')""".stripMargin)
     val carbonTable = CarbonMetadata.getInstance().getCarbonTable("default_list_table_country")