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
---