Skip to content

Commit

Permalink
[CARBONDATA-3344] Fix Drop column not present in table
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Indhumathi27 authored and ravipesala committed Apr 19, 2019
1 parent a803304 commit 1b60763
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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]()
Expand All @@ -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
}
}
Expand Down

0 comments on commit 1b60763

Please sign in to comment.