Github user akashrn5 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199402465 --- Diff: integration/spark-common/src/main/scala/org/apache/spark/sql/execution/command/carbonTableSchemaCommon.scala --- @@ -318,6 +417,11 @@ class AlterTableColumnSchemaGenerator( tablePropertiesMap.put(x._1, x._2) } } + --- End diff -- mention the reason, why you need to explicitly put these keys into the map --- |
In reply to this post by qiuchenjian-2
Github user akashrn5 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199402195 --- Diff: integration/spark-common/src/main/scala/org/apache/spark/sql/execution/command/carbonTableSchemaCommon.scala --- @@ -299,17 +303,112 @@ class AlterTableColumnSchemaGenerator( val columnValidator = CarbonSparkFactory.getCarbonColumnValidator columnValidator.validateColumns(allColumns) + --- End diff -- add proper comments to all the changes and methods, and you can move this to util class --- |
In reply to this post by qiuchenjian-2
Github user CarbonDataQA commented on the issue:
https://github.com/apache/carbondata/pull/2422 Build Success with Spark 2.1.0, Please check CI http://136.243.101.176:8080/job/ApacheCarbonPRBuilder1/6703/ --- |
In reply to this post by qiuchenjian-2
Github user ravipesala commented on the issue:
https://github.com/apache/carbondata/pull/2422 SDV Build Fail , Please check CI http://144.76.159.231:8080/job/ApacheSDVTests/5555/ --- |
In reply to this post by qiuchenjian-2
Github user CarbonDataQA commented on the issue:
https://github.com/apache/carbondata/pull/2422 Build Failed with Spark 2.2.1, Please check CI http://88.99.58.216:8080/job/ApacheCarbonPRBuilder/5530/ --- |
In reply to this post by qiuchenjian-2
Github user kunal642 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199559760 --- Diff: integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/localdictionary/LocalDictionarySupportAlterTableTest.scala --- @@ -0,0 +1,1183 @@ +package org.apache.carbondata.spark.testsuite.localdictionary --- End diff -- add apache license --- |
In reply to this post by qiuchenjian-2
Github user kunal642 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199563732 --- Diff: integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/localdictionary/LocalDictionarySupportAlterTableTest.scala --- @@ -0,0 +1,1183 @@ +package org.apache.carbondata.spark.testsuite.localdictionary + +import org.apache.spark.sql.test.util.QueryTest +import org.scalatest.BeforeAndAfterAll + +import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException + +class LocalDictionarySupportAlterTableTest extends QueryTest with BeforeAndAfterAll{ + + override protected def beforeAll(): Unit = { + sql("DROP TABLE IF EXISTS LOCAL1") + } + + test("test alter table add column") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,alt")) + } + } + + test("test alter table add column default configs for local dictionary") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string)") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city,alt")) + } + } + + test("test alter table add column where same column is in dictionary include and local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt','dictionary_include'='alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: alt specified in Dictionary " + + "include. Local Dictionary will not be generated for Dictionary include columns. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt,alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE contains Duplicate Columns: alt. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include/exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city', + | 'no_inverted_index'='name') + """.stripMargin) + val exception1 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_include'='abc')") + } + assert(exception1.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + val exception2 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_exclude'='abc')") + } + assert(exception2.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + } + + test("test alter table add column for datatype validation") + { --- End diff -- move opening brackets to previous line. Do this for all test cases --- |
In reply to this post by qiuchenjian-2
Github user kunal642 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199559152 --- Diff: integration/spark-common/src/main/scala/org/apache/spark/sql/execution/command/carbonTableSchemaCommon.scala --- @@ -299,17 +303,112 @@ class AlterTableColumnSchemaGenerator( val columnValidator = CarbonSparkFactory.getCarbonColumnValidator columnValidator.validateColumns(allColumns) + + def getLocalDictColumnList(tableProperties: scala.collection.mutable.Map[String, String], + columns: scala.collection.mutable.ListBuffer[ColumnSchema]): (scala.collection.mutable + .ListBuffer[ColumnSchema], scala.collection.mutable.ListBuffer[ColumnSchema]) = { + val includeColumns = new scala.collection.mutable.ListBuffer[ColumnSchema] + val excludeColumns = new scala.collection.mutable.ListBuffer[ColumnSchema] + val localDictIncludeColumns = if (tableProperties + .get(CarbonCommonConstants.LOCAL_DICTIONARY_INCLUDE).isDefined) { + tableProperties(CarbonCommonConstants.LOCAL_DICTIONARY_INCLUDE) + } else { + null + } + val localDictExcludeColumns = if (tableProperties + .get(CarbonCommonConstants.LOCAL_DICTIONARY_EXCLUDE).isDefined) { + tableProperties(CarbonCommonConstants.LOCAL_DICTIONARY_EXCLUDE) + } else { + null + } + if (null != localDictIncludeColumns) { + if (null == localDictExcludeColumns) { + columns.foreach { column => + if (localDictIncludeColumns.contains(column.getColumnName)) { + includeColumns.append(column) + } else { + if (column.getDataType.equals(DataTypes.STRING) || + column.getDataType.toString.equals("ARRAY") || + column.getDataType.toString.equals("STRUCT")) { + excludeColumns.append(column) + } + } + } + } else { + columns.foreach { column => + if (localDictIncludeColumns.contains(column.getColumnName) && + !localDictExcludeColumns.contains(column.getColumnName)) { + includeColumns.append(column) + } else if (localDictExcludeColumns.contains(column.getColumnName)) { + excludeColumns.append(column) + } + } + } + } else { + if (null == localDictExcludeColumns) { + columns.foreach { column => + if (column.getDataType.equals(DataTypes.STRING) || + column.getDataType.toString.equals("ARRAY") || + column.getDataType.toString.equals("STRUCT")) { + includeColumns.append(column) + } + } + } else { + columns.foreach { column => + if (!localDictExcludeColumns.contains(column.getColumnName) && + (column.getDataType.equals(DataTypes.STRING) || + column.getDataType.toString.equals("ARRAY") || + column.getDataType.toString.equals("STRUCT"))) { + includeColumns.append(column) + } else if (localDictExcludeColumns.contains(column.getColumnName)) { + excludeColumns.append(column) + } + } + } + } + + (includeColumns, excludeColumns) + } + + val columnsWithoutNewCols = new scala.collection.mutable.ListBuffer[ColumnSchema] + allColumns.foreach { column => + if (!newCols.exists(x => x.getColumnName.equalsIgnoreCase(column.getColumnName))) { + columnsWithoutNewCols += column + } + } + + if (alterTableModel.tableProperties != null) { CarbonUtil .setLocalDictColumnsToWrapperSchema(newCols.asJava, alterTableModel.tableProperties.asJava, tableSchema.getTableProperties.get(CarbonCommonConstants.LOCAL_DICTIONARY_ENABLE)) } + val newMainList = getLocalDictColumnList(tableSchema.getTableProperties.asScala, + columnsWithoutNewCols) + val ss: scala.collection.mutable.Map[String, String] = mutable + .Map(alterTableModel.tableProperties.toSeq: _*) + val newAlterList = getLocalDictColumnList(ss, + newCols.to[mutable.ListBuffer]) + + newMainList._1.appendAll(newAlterList._1) + newMainList._2.appendAll(newAlterList._2) + + val localDictioanryIncludeColumn = new StringBuilder + val localDictioanryExcludeColumn = new StringBuilder + newMainList._1.foreach { column => + localDictioanryIncludeColumn.append(column.getColumnName).append(",") + } + newMainList._2.foreach { column => + localDictioanryExcludeColumn.append(column.getColumnName).append(",") + } + // populate table properties map val tablePropertiesMap = tableSchema.getTableProperties alterTableModel.tableProperties.foreach { - x => val value = tablePropertiesMap.get(x._1) + x => --- End diff -- .use a tuple of (key, value) instead of x like .foreach { (key, value) => } --- |
In reply to this post by qiuchenjian-2
Github user kunal642 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199563256 --- Diff: integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/localdictionary/LocalDictionarySupportAlterTableTest.scala --- @@ -0,0 +1,1183 @@ +package org.apache.carbondata.spark.testsuite.localdictionary + +import org.apache.spark.sql.test.util.QueryTest +import org.scalatest.BeforeAndAfterAll + +import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException + +class LocalDictionarySupportAlterTableTest extends QueryTest with BeforeAndAfterAll{ + + override protected def beforeAll(): Unit = { + sql("DROP TABLE IF EXISTS LOCAL1") + } + + test("test alter table add column") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,alt")) + } + } + + test("test alter table add column default configs for local dictionary") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string)") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city,alt")) + } + } + + test("test alter table add column where same column is in dictionary include and local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt','dictionary_include'='alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: alt specified in Dictionary " + + "include. Local Dictionary will not be generated for Dictionary include columns. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt,alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE contains Duplicate Columns: alt. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include/exclude") --- End diff -- Please correct the test case name. --- |
In reply to this post by qiuchenjian-2
Github user kunal642 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199568724 --- Diff: integration/spark-common/src/main/scala/org/apache/spark/sql/execution/command/carbonTableSchemaCommon.scala --- @@ -278,14 +282,14 @@ class AlterTableColumnSchemaGenerator( // Its based on the dimension name and measure name allColumns.filter(x => !x.isInvisible).groupBy(_.getColumnName) .foreach(f => if (f._2.size > 1) { --- End diff -- change f => to (columnName, count) => for better readability --- |
In reply to this post by qiuchenjian-2
Github user kunal642 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199566331 --- Diff: integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/localdictionary/LocalDictionarySupportAlterTableTest.scala --- @@ -0,0 +1,1183 @@ +package org.apache.carbondata.spark.testsuite.localdictionary + +import org.apache.spark.sql.test.util.QueryTest +import org.scalatest.BeforeAndAfterAll + +import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException + +class LocalDictionarySupportAlterTableTest extends QueryTest with BeforeAndAfterAll{ + + override protected def beforeAll(): Unit = { + sql("DROP TABLE IF EXISTS LOCAL1") + } + + test("test alter table add column") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,alt")) + } + } + + test("test alter table add column default configs for local dictionary") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string)") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city,alt")) + } + } + + test("test alter table add column where same column is in dictionary include and local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt','dictionary_include'='alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: alt specified in Dictionary " + + "include. Local Dictionary will not be generated for Dictionary include columns. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt,alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE contains Duplicate Columns: alt. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include/exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city', + | 'no_inverted_index'='name') + """.stripMargin) + val exception1 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_include'='abc')") + } + assert(exception1.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + val exception2 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_exclude'='abc')") + } + assert(exception2.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + } + + test("test alter table add column for datatype validation") + { + sql("drop table if exists local1") + sql( + """ | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc int) tblproperties" + + "('local_dictionary_include'='abc')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc is not a String/complex " + + "datatype column. LOCAL_DICTIONARY_COLUMN should be no dictionary string/complex datatype" + + " column.Please check the DDL.")) + } + + test("test alter table add column where duplicate columns are present in local dictionary include and exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc','local_dictionary_exclude'='alt,abc')") + } + assert(exception.getMessage + .contains( + "Column ambiguity as duplicate column(s):abc is present in LOCAL_DICTIONARY_INCLUDE " + + "and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter table add column unsupported table property") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_enable'='abc')") + } + assert(exception.getMessage + .contains( + "Unsupported Table property in add column: local_dictionary_enable")) + val exception1 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_threshold'='10000')") + } + assert(exception1.getMessage + .contains( + "Unsupported Table property in add column: local_dictionary_threshold")) + } + + test("test alter table add column when main table is disabled for local dictionary") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='false', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Include") + } + + test("test local dictionary threshold for boundary values") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_threshold'='500') + """.stripMargin) + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test alter table add column for local dictionary include and exclude configs") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc','local_dictionary_exclude'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,abc")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("alt")) + } + } + + test("test local dictionary foer varchar datatype columns") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_include'='city', + | 'LONG_STRING_COLUMNS'='city') + """.stripMargin) + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test local dictionary describe formatted only with default configs") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test local dictionary for invalid threshold") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test alter set for local dictionary enable to disable") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc1.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + sql("alter table local1 set tblproperties('local_dictionary_enable'='false')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Threshold") + } + + test("test alter set for local dictionary _001") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_threshold'='30000')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("30000")) + } + } + + + test("test alter set for local dictionary _002") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name") && !row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _003") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + } + + test("test alter set for local dictionary _004") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _005") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name,city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test alter set for local dictionary _006") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _007") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='city, ')") + } + assert(exception1.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: does not exist in table. " + + "Please check the DDL.")) + } + + test("test alter set for local dictionary _008") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter set for local dictionary _009") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='id')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: id is not a String/complex datatype column. LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE should be no dictionary string/complex datatype column.")) + } + + test("test alter set for local dictionary _010") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: name specified in Dictionary include. Local Dictionary will not be generated for Dictionary include columns. Please check the DDL.")) + } + + test("test alter set for local dictionary _011") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _012") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city, ')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: does not exist in table. Please check the DDL.")) + } + + test("test alter set for local dictionary _013") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: name specified in Dictionary include. Local Dictionary will not be generated for Dictionary include columns. Please check the DDL.")) + } + + test("test alter set for local dictionary _014") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter set for local dictionary _015") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_enable'='false')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + } + + test("test alter set for local dictionary _016") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_enable'='false') + """.stripMargin) + + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + } + + test("test alter set for local dictionary _017") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter unset for local dictionary _001") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + sql("alter table local1 unset tblproperties('local_dictionary_exclude')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + } + + test("test alter unset for local dictionary _002") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + sql("alter table local1 unset tblproperties('local_dictionary_exclude')") + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary disable to enable") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_enable'='false','local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Threshold") + sql("alter table local1 set tblproperties('local_dictionary_enable'='true','local_dictionary_threshold'='30000')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("30000")) + } + } + + test("test alter set for local dictionary include valid and invalid") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='city','dictionary_include'='add') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='id')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='city,city')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='add')") + } + } + + test("test alter set for local dictionary exclude valid and invalid") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='city','dictionary_include'='add') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='id')") --- End diff -- already handled. no need to validate again. Remove the whole test case. --- |
In reply to this post by qiuchenjian-2
Github user kunal642 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199565923 --- Diff: integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/localdictionary/LocalDictionarySupportAlterTableTest.scala --- @@ -0,0 +1,1183 @@ +package org.apache.carbondata.spark.testsuite.localdictionary + +import org.apache.spark.sql.test.util.QueryTest +import org.scalatest.BeforeAndAfterAll + +import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException + +class LocalDictionarySupportAlterTableTest extends QueryTest with BeforeAndAfterAll{ + + override protected def beforeAll(): Unit = { + sql("DROP TABLE IF EXISTS LOCAL1") + } + + test("test alter table add column") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,alt")) + } + } + + test("test alter table add column default configs for local dictionary") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string)") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city,alt")) + } + } + + test("test alter table add column where same column is in dictionary include and local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt','dictionary_include'='alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: alt specified in Dictionary " + + "include. Local Dictionary will not be generated for Dictionary include columns. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt,alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE contains Duplicate Columns: alt. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include/exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city', + | 'no_inverted_index'='name') + """.stripMargin) + val exception1 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_include'='abc')") + } + assert(exception1.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + val exception2 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_exclude'='abc')") + } + assert(exception2.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + } + + test("test alter table add column for datatype validation") + { + sql("drop table if exists local1") + sql( + """ | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc int) tblproperties" + + "('local_dictionary_include'='abc')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc is not a String/complex " + + "datatype column. LOCAL_DICTIONARY_COLUMN should be no dictionary string/complex datatype" + + " column.Please check the DDL.")) + } + + test("test alter table add column where duplicate columns are present in local dictionary include and exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc','local_dictionary_exclude'='alt,abc')") + } + assert(exception.getMessage + .contains( + "Column ambiguity as duplicate column(s):abc is present in LOCAL_DICTIONARY_INCLUDE " + + "and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter table add column unsupported table property") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_enable'='abc')") + } + assert(exception.getMessage + .contains( + "Unsupported Table property in add column: local_dictionary_enable")) + val exception1 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_threshold'='10000')") + } + assert(exception1.getMessage + .contains( + "Unsupported Table property in add column: local_dictionary_threshold")) + } + + test("test alter table add column when main table is disabled for local dictionary") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='false', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Include") + } + + test("test local dictionary threshold for boundary values") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_threshold'='500') + """.stripMargin) + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test alter table add column for local dictionary include and exclude configs") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc','local_dictionary_exclude'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,abc")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("alt")) + } + } + + test("test local dictionary foer varchar datatype columns") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_include'='city', + | 'LONG_STRING_COLUMNS'='city') + """.stripMargin) + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test local dictionary describe formatted only with default configs") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test local dictionary for invalid threshold") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test alter set for local dictionary enable to disable") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc1.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + sql("alter table local1 set tblproperties('local_dictionary_enable'='false')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Threshold") + } + + test("test alter set for local dictionary _001") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_threshold'='30000')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("30000")) + } + } + + + test("test alter set for local dictionary _002") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name") && !row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _003") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + } + + test("test alter set for local dictionary _004") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _005") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name,city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test alter set for local dictionary _006") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _007") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='city, ')") + } + assert(exception1.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: does not exist in table. " + + "Please check the DDL.")) + } + + test("test alter set for local dictionary _008") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter set for local dictionary _009") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='id')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: id is not a String/complex datatype column. LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE should be no dictionary string/complex datatype column.")) + } + + test("test alter set for local dictionary _010") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: name specified in Dictionary include. Local Dictionary will not be generated for Dictionary include columns. Please check the DDL.")) + } + + test("test alter set for local dictionary _011") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _012") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city, ')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: does not exist in table. Please check the DDL.")) + } + + test("test alter set for local dictionary _013") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: name specified in Dictionary include. Local Dictionary will not be generated for Dictionary include columns. Please check the DDL.")) + } + + test("test alter set for local dictionary _014") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter set for local dictionary _015") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_enable'='false')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + } + + test("test alter set for local dictionary _016") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_enable'='false') + """.stripMargin) + + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + } + + test("test alter set for local dictionary _017") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter unset for local dictionary _001") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + sql("alter table local1 unset tblproperties('local_dictionary_exclude')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + } + + test("test alter unset for local dictionary _002") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + sql("alter table local1 unset tblproperties('local_dictionary_exclude')") + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary disable to enable") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_enable'='false','local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Threshold") + sql("alter table local1 set tblproperties('local_dictionary_enable'='true','local_dictionary_threshold'='30000')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("30000")) + } + } + + test("test alter set for local dictionary include valid and invalid") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='city','dictionary_include'='add') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + intercept[Exception] { --- End diff -- all these negative scenarios are already handled in previous test cases --- |
In reply to this post by qiuchenjian-2
Github user kunal642 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199565592 --- Diff: integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/localdictionary/LocalDictionarySupportAlterTableTest.scala --- @@ -0,0 +1,1183 @@ +package org.apache.carbondata.spark.testsuite.localdictionary + +import org.apache.spark.sql.test.util.QueryTest +import org.scalatest.BeforeAndAfterAll + +import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException + +class LocalDictionarySupportAlterTableTest extends QueryTest with BeforeAndAfterAll{ + + override protected def beforeAll(): Unit = { + sql("DROP TABLE IF EXISTS LOCAL1") + } + + test("test alter table add column") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,alt")) + } + } + + test("test alter table add column default configs for local dictionary") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string)") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city,alt")) + } + } + + test("test alter table add column where same column is in dictionary include and local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt','dictionary_include'='alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: alt specified in Dictionary " + + "include. Local Dictionary will not be generated for Dictionary include columns. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt,alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE contains Duplicate Columns: alt. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include/exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city', + | 'no_inverted_index'='name') + """.stripMargin) + val exception1 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_include'='abc')") + } + assert(exception1.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + val exception2 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_exclude'='abc')") + } + assert(exception2.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + } + + test("test alter table add column for datatype validation") + { + sql("drop table if exists local1") + sql( + """ | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc int) tblproperties" + + "('local_dictionary_include'='abc')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc is not a String/complex " + + "datatype column. LOCAL_DICTIONARY_COLUMN should be no dictionary string/complex datatype" + + " column.Please check the DDL.")) + } + + test("test alter table add column where duplicate columns are present in local dictionary include and exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc','local_dictionary_exclude'='alt,abc')") + } + assert(exception.getMessage + .contains( + "Column ambiguity as duplicate column(s):abc is present in LOCAL_DICTIONARY_INCLUDE " + + "and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter table add column unsupported table property") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_enable'='abc')") + } + assert(exception.getMessage + .contains( + "Unsupported Table property in add column: local_dictionary_enable")) + val exception1 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_threshold'='10000')") + } + assert(exception1.getMessage + .contains( + "Unsupported Table property in add column: local_dictionary_threshold")) + } + + test("test alter table add column when main table is disabled for local dictionary") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='false', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Include") + } + + test("test local dictionary threshold for boundary values") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_threshold'='500') + """.stripMargin) + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test alter table add column for local dictionary include and exclude configs") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc','local_dictionary_exclude'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,abc")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("alt")) + } + } + + test("test local dictionary foer varchar datatype columns") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_include'='city', + | 'LONG_STRING_COLUMNS'='city') + """.stripMargin) + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test local dictionary describe formatted only with default configs") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test local dictionary for invalid threshold") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test alter set for local dictionary enable to disable") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc1.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + sql("alter table local1 set tblproperties('local_dictionary_enable'='false')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Threshold") + } + + test("test alter set for local dictionary _001") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_threshold'='30000')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("30000")) + } + } + + + test("test alter set for local dictionary _002") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name") && !row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _003") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + } + + test("test alter set for local dictionary _004") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _005") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name,city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test alter set for local dictionary _006") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _007") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='city, ')") + } + assert(exception1.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: does not exist in table. " + + "Please check the DDL.")) + } + + test("test alter set for local dictionary _008") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter set for local dictionary _009") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='id')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: id is not a String/complex datatype column. LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE should be no dictionary string/complex datatype column.")) + } + + test("test alter set for local dictionary _010") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: name specified in Dictionary include. Local Dictionary will not be generated for Dictionary include columns. Please check the DDL.")) + } + + test("test alter set for local dictionary _011") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _012") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city, ')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: does not exist in table. Please check the DDL.")) + } + + test("test alter set for local dictionary _013") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: name specified in Dictionary include. Local Dictionary will not be generated for Dictionary include columns. Please check the DDL.")) + } + + test("test alter set for local dictionary _014") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter set for local dictionary _015") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_enable'='false')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + } + + test("test alter set for local dictionary _016") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_enable'='false') + """.stripMargin) + + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + } + + test("test alter set for local dictionary _017") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter unset for local dictionary _001") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + sql("alter table local1 unset tblproperties('local_dictionary_exclude')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + } + + test("test alter unset for local dictionary _002") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + sql("alter table local1 unset tblproperties('local_dictionary_exclude')") --- End diff -- remove if not needed --- |
In reply to this post by qiuchenjian-2
Github user kunal642 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199567737 --- Diff: integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/localdictionary/LocalDictionarySupportAlterTableTest.scala --- @@ -0,0 +1,1183 @@ +package org.apache.carbondata.spark.testsuite.localdictionary + +import org.apache.spark.sql.test.util.QueryTest +import org.scalatest.BeforeAndAfterAll + +import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException + +class LocalDictionarySupportAlterTableTest extends QueryTest with BeforeAndAfterAll{ + + override protected def beforeAll(): Unit = { + sql("DROP TABLE IF EXISTS LOCAL1") + } + + test("test alter table add column") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,alt")) + } + } + + test("test alter table add column default configs for local dictionary") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string)") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city,alt")) + } + } + + test("test alter table add column where same column is in dictionary include and local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt','dictionary_include'='alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: alt specified in Dictionary " + + "include. Local Dictionary will not be generated for Dictionary include columns. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt,alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE contains Duplicate Columns: alt. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include/exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city', + | 'no_inverted_index'='name') + """.stripMargin) + val exception1 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_include'='abc')") + } + assert(exception1.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + val exception2 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_exclude'='abc')") + } + assert(exception2.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + } + + test("test alter table add column for datatype validation") + { + sql("drop table if exists local1") + sql( + """ | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc int) tblproperties" + + "('local_dictionary_include'='abc')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc is not a String/complex " + + "datatype column. LOCAL_DICTIONARY_COLUMN should be no dictionary string/complex datatype" + + " column.Please check the DDL.")) + } + + test("test alter table add column where duplicate columns are present in local dictionary include and exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc','local_dictionary_exclude'='alt,abc')") + } + assert(exception.getMessage + .contains( + "Column ambiguity as duplicate column(s):abc is present in LOCAL_DICTIONARY_INCLUDE " + + "and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter table add column unsupported table property") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_enable'='abc')") + } + assert(exception.getMessage + .contains( + "Unsupported Table property in add column: local_dictionary_enable")) + val exception1 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_threshold'='10000')") + } + assert(exception1.getMessage + .contains( + "Unsupported Table property in add column: local_dictionary_threshold")) + } + + test("test alter table add column when main table is disabled for local dictionary") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='false', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Include") + } + + test("test local dictionary threshold for boundary values") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_threshold'='500') + """.stripMargin) + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test alter table add column for local dictionary include and exclude configs") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc','local_dictionary_exclude'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,abc")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("alt")) + } + } + + test("test local dictionary foer varchar datatype columns") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_include'='city', + | 'LONG_STRING_COLUMNS'='city') + """.stripMargin) + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test local dictionary describe formatted only with default configs") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test local dictionary for invalid threshold") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test alter set for local dictionary enable to disable") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc1.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + sql("alter table local1 set tblproperties('local_dictionary_enable'='false')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Threshold") + } + + test("test alter set for local dictionary _001") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_threshold'='30000')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("30000")) + } + } + + + test("test alter set for local dictionary _002") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name") && !row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _003") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + } + + test("test alter set for local dictionary _004") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _005") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name,city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test alter set for local dictionary _006") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _007") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='city, ')") + } + assert(exception1.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: does not exist in table. " + + "Please check the DDL.")) + } + + test("test alter set for local dictionary _008") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter set for local dictionary _009") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='id')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: id is not a String/complex datatype column. LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE should be no dictionary string/complex datatype column.")) + } + + test("test alter set for local dictionary _010") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: name specified in Dictionary include. Local Dictionary will not be generated for Dictionary include columns. Please check the DDL.")) + } + + test("test alter set for local dictionary _011") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _012") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city, ')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: does not exist in table. Please check the DDL.")) + } + + test("test alter set for local dictionary _013") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: name specified in Dictionary include. Local Dictionary will not be generated for Dictionary include columns. Please check the DDL.")) + } + + test("test alter set for local dictionary _014") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter set for local dictionary _015") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_enable'='false')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + } + + test("test alter set for local dictionary _016") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_enable'='false') + """.stripMargin) + + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + } + + test("test alter set for local dictionary _017") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter unset for local dictionary _001") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + sql("alter table local1 unset tblproperties('local_dictionary_exclude')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + } + + test("test alter unset for local dictionary _002") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + sql("alter table local1 unset tblproperties('local_dictionary_exclude')") + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary disable to enable") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_enable'='false','local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Threshold") + sql("alter table local1 set tblproperties('local_dictionary_enable'='true','local_dictionary_threshold'='30000')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("30000")) + } + } + + test("test alter set for local dictionary include valid and invalid") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='city','dictionary_include'='add') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='id')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='city,city')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='add')") + } + } + + test("test alter set for local dictionary exclude valid and invalid") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='city','dictionary_include'='add') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='id')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city,city')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='add')") + } + } + + test("test alter set same column for local dictionary exclude and include") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='city') + """.stripMargin) + intercept[Exception] { + sql( + "alter table local1 set tblproperties('local_dictionary_include'='name'," + + "'local_dictionary_exclude'='name')") + } + } + + test("test alter set for valid and invalid complex type as include/exclude") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,st struct<s_id:int, + | s_name:string,s_city:array<string>>, dcity array<string>) + | STORED BY 'org.apache.carbondata.format' + | tblproperties('local_dictionary_exclude'='name','local_dictionary_include'='city,dcity', + | 'local_dictionary_enable'='true') + """. + stripMargin) + val descFormatted1 = sql("describe formatted local1").collect + descFormatted1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descFormatted1.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert( + row.get(1).toString.contains("city,dcity") && !row.get(1).toString.contains("name")) + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='dcity')") + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='st')") + val descFormatted2 = sql("describe formatted local1").collect + descFormatted2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("st")) + } + descFormatted2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,dcity")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='st'," + + "'local_dictionary_include'='dcity')") + val descFormatted3 = sql("describe formatted local1").collect + descFormatted3.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("st")) + } + descFormatted3.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("dcity")) + } + } + + test("test alter set for invalid complex type as include/exclude") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,st struct<s_id:int, + | s_name:int,s_city:array<int>>, dcity array<int>) + | STORED BY 'org.apache.carbondata.format' + | tblproperties('local_dictionary_exclude'='name', + | 'local_dictionary_enable'='true') + """. + stripMargin) + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='dcity')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='st')") + } + } + + test("test alter unset for local dictionary disable") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_enable'='false') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enable")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + sql("alter table local1 unset tblproperties('local_dictionary_enable')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enable")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + } + + test("test alter unset for local dictionary enable local dict include") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='city') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + sql("alter table local1 unset tblproperties('local_dictionary_include')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test alter unset for local dictionary enable local dict exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='city', + | 'local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + sql("alter table local1 unset tblproperties('local_dictionary_include')") --- End diff -- unset 'local_dictionary_exclude' instead of 'local_dictionary_include' as the name suggests --- |
In reply to this post by qiuchenjian-2
Github user kunal642 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2422#discussion_r199568278 --- Diff: integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/localdictionary/LocalDictionarySupportAlterTableTest.scala --- @@ -0,0 +1,1183 @@ +package org.apache.carbondata.spark.testsuite.localdictionary + +import org.apache.spark.sql.test.util.QueryTest +import org.scalatest.BeforeAndAfterAll + +import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException + +class LocalDictionarySupportAlterTableTest extends QueryTest with BeforeAndAfterAll{ + + override protected def beforeAll(): Unit = { + sql("DROP TABLE IF EXISTS LOCAL1") + } + + test("test alter table add column") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,alt")) + } + } + + test("test alter table add column default configs for local dictionary") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string)") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("20000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city,alt")) + } + } + + test("test alter table add column where same column is in dictionary include and local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt','dictionary_include'='alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: alt specified in Dictionary " + + "include. Local Dictionary will not be generated for Dictionary include columns. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city','no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties('local_dictionary_include'='alt,alt')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE contains Duplicate Columns: alt. " + + "Please check the DDL.")) + } + + test("test alter table add column where duplicate columns present in local dictionary include/exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','local_dictionary_include'='city', + | 'no_inverted_index'='name') + """.stripMargin) + val exception1 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_include'='abc')") + } + assert(exception1.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + val exception2 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string) tblproperties" + + "('local_dictionary_exclude'='abc')") + } + assert(exception2.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc does not exist in table. " + + "Please check the DDL.")) + } + + test("test alter table add column for datatype validation") + { + sql("drop table if exists local1") + sql( + """ | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc int) tblproperties" + + "('local_dictionary_include'='abc')") + } + assert(exception.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: abc is not a String/complex " + + "datatype column. LOCAL_DICTIONARY_COLUMN should be no dictionary string/complex datatype" + + " column.Please check the DDL.")) + } + + test("test alter table add column where duplicate columns are present in local dictionary include and exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc','local_dictionary_exclude'='alt,abc')") + } + assert(exception.getMessage + .contains( + "Column ambiguity as duplicate column(s):abc is present in LOCAL_DICTIONARY_INCLUDE " + + "and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter table add column unsupported table property") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + val exception = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_enable'='abc')") + } + assert(exception.getMessage + .contains( + "Unsupported Table property in add column: local_dictionary_enable")) + val exception1 = intercept[MalformedCarbonCommandException] { + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_threshold'='10000')") + } + assert(exception1.getMessage + .contains( + "Unsupported Table property in add column: local_dictionary_threshold")) + } + + test("test alter table add column when main table is disabled for local dictionary") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='false', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Include") + } + + test("test local dictionary threshold for boundary values") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_threshold'='500') + """.stripMargin) + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test alter table add column for local dictionary include and exclude configs") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_include'='city', 'no_inverted_index'='name') + """.stripMargin) + sql( + "alter table local1 add columns (alt string,abc string) tblproperties" + + "('local_dictionary_include'='abc','local_dictionary_exclude'='alt')") + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,abc")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("alt")) + } + } + + test("test local dictionary foer varchar datatype columns") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_include'='city', + | 'LONG_STRING_COLUMNS'='city') + """.stripMargin) + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test local dictionary describe formatted only with default configs") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + descLoc.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test local dictionary for invalid threshold") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc = sql("describe formatted local1").collect + descLoc.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + } + + test("test alter set for local dictionary enable to disable") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc1.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("10000")) + } + sql("alter table local1 set tblproperties('local_dictionary_enable'='false')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Threshold") + } + + test("test alter set for local dictionary _001") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_threshold'='30000')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("30000")) + } + } + + + test("test alter set for local dictionary _002") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name") && !row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _003") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + } + + test("test alter set for local dictionary _004") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _005") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name,city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test alter set for local dictionary _006") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _007") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='city, ')") + } + assert(exception1.getMessage + .contains( + "LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: does not exist in table. " + + "Please check the DDL.")) + } + + test("test alter set for local dictionary _008") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter set for local dictionary _009") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='id')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: id is not a String/complex datatype column. LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE should be no dictionary string/complex datatype column.")) + } + + test("test alter set for local dictionary _010") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: name specified in Dictionary include. Local Dictionary will not be generated for Dictionary include columns. Please check the DDL.")) + } + + test("test alter set for local dictionary _011") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary _012") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city, ')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: does not exist in table. Please check the DDL.")) + } + + test("test alter set for local dictionary _013") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("LOCAL_DICTIONARY_INCLUDE/LOCAL_DICTIONARY_EXCLUDE column: name specified in Dictionary include. Local Dictionary will not be generated for Dictionary include columns. Please check the DDL.")) + } + + test("test alter set for local dictionary _014") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter set for local dictionary _015") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + sql("alter table local1 set tblproperties('local_dictionary_enable'='false')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + } + + test("test alter set for local dictionary _016") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_enable'='false') + """.stripMargin) + + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + } + + test("test alter set for local dictionary _017") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + val exception1 = intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + } + assert(exception1.getMessage.contains("Column ambiguity as duplicate column(s):name is present in LOCAL_DICTIONARY_INCLUDE and LOCAL_DICTIONARY_EXCLUDE. Duplicate columns are not allowed.")) + } + + test("test alter unset for local dictionary _001") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + sql("alter table local1 unset tblproperties('local_dictionary_exclude')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + } + + test("test alter unset for local dictionary _002") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='name','local_dictionary_exclude'='city') + """.stripMargin) + + sql("alter table local1 unset tblproperties('local_dictionary_exclude')") + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter set for local dictionary disable to enable") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_enable'='false','local_dictionary_threshold'='300000') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + checkExistence(sql("DESC FORMATTED local1"), false, + "Local Dictionary Threshold") + sql("alter table local1 set tblproperties('local_dictionary_enable'='true','local_dictionary_threshold'='30000')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descLoc2.find(_.get(0).toString.contains("Local Dictionary Threshold")) match { + case Some(row) => assert(row.get(1).toString.contains("30000")) + } + } + + test("test alter set for local dictionary include valid and invalid") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='city','dictionary_include'='add') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + sql("alter table local1 set tblproperties('local_dictionary_include'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='id')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='city,city')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='add')") + } + } + + test("test alter set for local dictionary exclude valid and invalid") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='city','dictionary_include'='add') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='name')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("name")) + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='id')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='city,city')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='add')") + } + } + + test("test alter set same column for local dictionary exclude and include") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'carbondata' tblproperties('local_dictionary_exclude'='city') + """.stripMargin) + intercept[Exception] { + sql( + "alter table local1 set tblproperties('local_dictionary_include'='name'," + + "'local_dictionary_exclude'='name')") + } + } + + test("test alter set for valid and invalid complex type as include/exclude") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,st struct<s_id:int, + | s_name:string,s_city:array<string>>, dcity array<string>) + | STORED BY 'org.apache.carbondata.format' + | tblproperties('local_dictionary_exclude'='name','local_dictionary_include'='city,dcity', + | 'local_dictionary_enable'='true') + """. + stripMargin) + val descFormatted1 = sql("describe formatted local1").collect + descFormatted1.find(_.get(0).toString.contains("Local Dictionary Enabled")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + descFormatted1.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert( + row.get(1).toString.contains("city,dcity") && !row.get(1).toString.contains("name")) + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='dcity')") + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='st')") + val descFormatted2 = sql("describe formatted local1").collect + descFormatted2.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("st")) + } + descFormatted2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city,dcity")) + } + sql("alter table local1 set tblproperties('local_dictionary_exclude'='st'," + + "'local_dictionary_include'='dcity')") + val descFormatted3 = sql("describe formatted local1").collect + descFormatted3.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert(row.get(1).toString.contains("st")) + } + descFormatted3.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("dcity")) + } + } + + test("test alter set for invalid complex type as include/exclude") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,st struct<s_id:int, + | s_name:int,s_city:array<int>>, dcity array<int>) + | STORED BY 'org.apache.carbondata.format' + | tblproperties('local_dictionary_exclude'='name', + | 'local_dictionary_enable'='true') + """. + stripMargin) + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_exclude'='dcity')") + } + intercept[Exception] { + sql("alter table local1 set tblproperties('local_dictionary_include'='st')") + } + } + + test("test alter unset for local dictionary disable") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_enable'='false') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Enable")) match { + case Some(row) => assert(row.get(1).toString.contains("false")) + } + sql("alter table local1 unset tblproperties('local_dictionary_enable')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Enable")) match { + case Some(row) => assert(row.get(1).toString.contains("true")) + } + } + + test("test alter unset for local dictionary enable local dict include") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='city') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + sql("alter table local1 unset tblproperties('local_dictionary_include')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city")) + } + } + + test("test alter unset for local dictionary enable local dict exclude") + { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,add string) + | STORED BY 'carbondata' tblproperties('local_dictionary_include'='city', + | 'local_dictionary_exclude'='name') + """.stripMargin) + + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + sql("alter table local1 unset tblproperties('local_dictionary_include')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + } + + test("test alter unset for valid/invalid complex type as include/exclude") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int,st struct<s_id:int, + | s_name:string,s_city:array<int>>, dcity array<string>) + | STORED BY 'org.apache.carbondata.format' + | tblproperties('local_dictionary_exclude'='st','local_dictionary_include'='city', + | 'local_dictionary_enable'='true') + """. + stripMargin) + val descLoc1 = sql("describe formatted local1").collect + descLoc1.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("city")) + } + descLoc1.find(_.get(0).toString.contains("Local Dictionary Exclude")) match { + case Some(row) => assert( + row.get(1).toString.contains("st.s_name") && !row.get(1).toString.contains("st.s_id")) + } + sql("alter table local1 unset tblproperties('local_dictionary_include')") + val descLoc2 = sql("describe formatted local1").collect + descLoc2.find(_.get(0).toString.contains("Local Dictionary Include")) match { + case Some(row) => assert(row.get(1).toString.contains("name,city,dcity.val")) + } + } + + test("test alter table add column default configs for local dictionary _002") { + sql("drop table if exists local1") + sql( + """ + | CREATE TABLE local1(id int, name string, city string, age int) + | STORED BY 'org.apache.carbondata.format' tblproperties('local_dictionary_enable'='true', + | 'local_dictionary_threshold'='20000','no_inverted_index'='name') + """.stripMargin) + sql("alter table local1 add columns (alt string) " + --- End diff -- add columns scenarios are already verified in previous test cases. --- |
In reply to this post by qiuchenjian-2
Github user CarbonDataQA commented on the issue:
https://github.com/apache/carbondata/pull/2422 Build Success with Spark 2.1.0, Please check CI http://136.243.101.176:8080/job/ApacheCarbonPRBuilder1/6739/ --- |
In reply to this post by qiuchenjian-2
Github user ravipesala commented on the issue:
https://github.com/apache/carbondata/pull/2422 SDV Build Fail , Please check CI http://144.76.159.231:8080/job/ApacheSDVTests/5584/ --- |
In reply to this post by qiuchenjian-2
Github user CarbonDataQA commented on the issue:
https://github.com/apache/carbondata/pull/2422 Build Success with Spark 2.2.1, Please check CI http://88.99.58.216:8080/job/ApacheCarbonPRBuilder/5572/ --- |
In reply to this post by qiuchenjian-2
Github user ravipesala commented on the issue:
https://github.com/apache/carbondata/pull/2422 SDV Build Success , Please check CI http://144.76.159.231:8080/job/ApacheSDVTests/5592/ --- |
In reply to this post by qiuchenjian-2
Github user CarbonDataQA commented on the issue:
https://github.com/apache/carbondata/pull/2422 Build Success with Spark 2.1.0, Please check CI http://136.243.101.176:8080/job/ApacheCarbonPRBuilder1/6751/ --- |
Free forum by Nabble | Edit this page |