Skip to content
Browse files
[CARBONDATA-4208] Wrong Exception received for complex child long str…
…ing columns

Why is this PR needed?
When we create a table with complex columns with child columns with long string
data type then receiving column not found in table exception. Normally it should
throw an exception in the above case by saying that complex child columns will
not support long string data type.

What changes were proposed in this PR?
Added a case if complex child column has long string data type then throw correct
Exception: MalformedCarbonCommandException
Exception Message: Complex child column cannot be set as LONG_STRING_COLUMNS

Does this PR introduce any user interface change?

Is any new testcase added?

This closes #4150
  • Loading branch information
maheshrajus authored and akashrn5 committed Jun 18, 2021
1 parent f1da9e8 commit 65fad9887425a8525a5e61d9c4ed67e3c2e39f84
Showing 4 changed files with 38 additions and 2 deletions.
@@ -37,6 +37,7 @@
import org.apache.carbondata.core.metadata.schema.table.Writable;
import org.apache.carbondata.core.metadata.schema.table.WritableUtil;
import org.apache.carbondata.core.preagg.TimeSeriesUDF;
import org.apache.carbondata.core.util.CarbonUtil;

* Store the information about the column meta data present the table
@@ -589,8 +590,7 @@ public void readFields(DataInput in) throws IOException {
* @return
public boolean isComplexColumn() {
return this.getColumnName()
.contains(".val") || this.getColumnName().contains(".");
return CarbonUtil.isComplexColumn(this.getColumnName());

public ColumnSchema clone() {
@@ -3500,4 +3500,12 @@ public static void updateNullValueBasedOnDatatype(DataOutputStream dataOutputStr

* returns whether column is complex column based on column name for child column
* @return true if column is complex
public static boolean isComplexColumn(String colName) {
return colName.contains(".val") || colName.contains(CarbonCommonConstants.POINT);
@@ -449,6 +449,10 @@ object CarbonParserUtil {
var tmpStr: String = ""
varcharCols.foreach {
column =>
if (CarbonUtil.isComplexColumn(column)) {
val errMsg = s"Complex child column $column cannot be set as LONG_STRING_COLUMNS"
throw new MalformedCarbonCommandException(errMsg)
tmpStr = column.toUpperCase
duplicateColumnErr.get(tmpStr) match {
case None => duplicateColumnErr.put(tmpStr, 1)
@@ -27,6 +27,7 @@ import org.apache.spark.sql.test.util.QueryTest
import org.scalatest.BeforeAndAfterAll

import org.apache.carbondata.common.constants.LoggerAction
import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException
import org.apache.carbondata.core.constants.CarbonCommonConstants
import org.apache.carbondata.core.util.CarbonProperties

@@ -765,6 +766,29 @@ class TestComplexDataType extends QueryTest with BeforeAndAfterAll {
assertResult("Unsupported operation on Complex data type")(arrayException.getMessage)

test("testing the long string properties for complex columns in main table") {
sql("drop table if exists complex1")
sql("drop table if exists complex2")
sql("drop table if exists complex3")
sql("create table complex1 (a int, arr1 array<string>) stored as carbondata")
assert(intercept[RuntimeException] {
sql("alter table complex1 SET TBLPROPERTIES ('LONG_STRING_COLUMNS'='arr1.val')")
"Alter table newProperties operation failed: Complex child column arr1.val cannot be set " +
assert(intercept[MalformedCarbonCommandException] {
sql("create table complex2 (a int, arr1 array<string>) " +
"stored as carbondata TBLPROPERTIES('LONG_STRING_COLUMNS'='arr1.val')")
}.getMessage.contains("Complex child column arr1.val cannot be set as LONG_STRING_COLUMNS"))
assert(intercept[MalformedCarbonCommandException] {
sql("create table complex3 (a int, struct1 struct<b:string,c:string>) " +
"stored as carbondata TBLPROPERTIES('LONG_STRING_COLUMNS'='struct1.b')")
}.getMessage.contains("Complex child column struct1.b cannot be set as LONG_STRING_COLUMNS"))
sql("drop table if exists complex1")
sql("drop table if exists complex2")
sql("drop table if exists complex3")

test("check update operation on primitive data types when complex type present in table which " +
"has child name equal to primitive data types") {
sql("drop table if exists update_complex")

0 comments on commit 65fad98

Please sign in to comment.