carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipes...@apache.org
Subject [carbondata] 06/22: [CARBONDATA-3344] Fix Drop column not present in table
Date Thu, 16 May 2019 19:05:39 GMT
This is an automated email from the ASF dual-hosted git repository.

ravipesala pushed a commit to branch branch-1.5
in repository https://gitbox.apache.org/repos/asf/carbondata.git

commit 4f7f17d53e768554ec519a70394546d01e585c8b
Author: Indhumathi27 <indhumathim27@gmail.com>
AuthorDate: Sat Apr 6 16:53:56 2019 +0530

    [CARBONDATA-3344] Fix Drop column not present in table
    
    Why this PR needed?
    When trying to drop column which is not present in main table, it is throwing Null pointer
exception, instead of throwing exception for column does not exists in table.
    
    This closes #3174
---
 .../cluster/sdv/generated/AlterTableTestCase.scala         | 12 ++++++++++++
 .../command/schema/CarbonAlterTableDropColumnCommand.scala | 14 +++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/integration/spark-common-cluster-test/src/test/scala/org/apache/carbondata/cluster/sdv/generated/AlterTableTestCase.scala
b/integration/spark-common-cluster-test/src/test/scala/org/apache/carbondata/cluster/sdv/generated/AlterTableTestCase.scala
index d15f70b..297ff04 100644
--- a/integration/spark-common-cluster-test/src/test/scala/org/apache/carbondata/cluster/sdv/generated/AlterTableTestCase.scala
+++ b/integration/spark-common-cluster-test/src/test/scala/org/apache/carbondata/cluster/sdv/generated/AlterTableTestCase.scala
@@ -29,6 +29,8 @@ import org.apache.carbondata.core.constants.CarbonCommonConstants
 import org.apache.carbondata.core.util.CarbonProperties
 import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
 
+import org.apache.carbondata.spark.exception.ProcessMetaDataException
+
 /**
  * Test Class for AlterTableTestCase to verify all scenerios
  */
@@ -1024,6 +1026,16 @@ class AlterTableTestCase extends QueryTest with BeforeAndAfterAll {
     }
   }
 
+  test("Test drop columns not present in the table") {
+    sql("drop table if exists test1")
+    sql("create table test1(col1 int) stored by 'carbondata'")
+    val exception = intercept[ProcessMetaDataException] {
+      sql("alter table test1 drop columns(name)")
+    }
+    assert(exception.getMessage.contains("Column name does not exists in the table default.test1"))
+    sql("drop table if exists test1")
+  }
+
   val prop = CarbonProperties.getInstance()
   val p1 = prop.getProperty("carbon.horizontal.compaction.enable", CarbonCommonConstants.CARBON_HORIZONTAL_COMPACTION_ENABLE_DEFAULT)
   val p2 = prop.getProperty("carbon.horizontal.update.compaction.threshold", CarbonCommonConstants.DEFAULT_UPDATE_DELTAFILE_COUNT_THRESHOLD_IUD_COMPACTION)
diff --git a/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableDropColumnCommand.scala
b/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableDropColumnCommand.scala
index 7d5cb41..31cfdaf 100644
--- a/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableDropColumnCommand.scala
+++ b/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableDropColumnCommand.scala
@@ -76,15 +76,6 @@ private[sql] case class CarbonAlterTableDropColumnCommand(
         }
       }
 
-      // Check if column to be dropped is of complex dataType
-      alterTableDropColumnModel.columns.foreach { column =>
-        if (carbonTable.getColumnByName(alterTableDropColumnModel.tableName, column).getDataType
-          .isComplexType) {
-          val errMsg = "Complex column cannot be dropped"
-          throw new MalformedCarbonCommandException(errMsg)
-        }
-      }
-
       val tableColumns = carbonTable.getCreateOrderColumn(tableName).asScala
       var dictionaryColumns = Seq[org.apache.carbondata.core.metadata.schema.table.column
       .ColumnSchema]()
@@ -99,6 +90,11 @@ private[sql] case class CarbonAlterTableDropColumnCommand(
                 dictionaryColumns ++= Seq(tableColumn.getColumnSchema)
               }
             }
+            // Check if column to be dropped is of complex dataType
+            if (tableColumn.getDataType.isComplexType) {
+              val errMsg = "Complex column cannot be dropped"
+              throw new MalformedCarbonCommandException(errMsg)
+            }
             columnExist = true
           }
         }


Mime
View raw message