Github user kunal642 commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/2422#discussion_r199126014
  
    --- Diff: 
integration/spark-common-cluster-test/src/test/scala/org/apache/carbondata/cluster/sdv/generated/CreateTableWithLocalDictionaryTestCase.scala
 ---
    @@ -2096,6 +2096,264 @@ class CreateTableWithLocalDictionaryTestCase 
extends QueryTest with BeforeAndAft
         }
       }
     
    +  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 create table statement."))
    +  }
    +
    +  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 create table statement."))
    +  }
    +
    +  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 create table statement."))
    +    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 create table statement."))
    +  }
    +
    +  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 create table statement."))
    +  }
    +
    +  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")
    --- End diff --
    
    Add one test case in which 2 string columns are added using alter but only 
one column is specified in local_dic_include. Both should be considered for 
local dict generation.


---

Reply via email to