ShreelekhyaG commented on a change in pull request #4180:
URL: https://github.com/apache/carbondata/pull/4180#discussion_r694642810



##########
File path: 
integration/spark/src/test/scala/org/apache/spark/carbondata/restructure/vectorreader/AlterTableColumnRenameTestCase.scala
##########
@@ -307,17 +296,117 @@ class AlterTableColumnRenameTestCase extends QueryTest 
with BeforeAndAfterAll {
           make(Array("hello11", "world11")), make(Array(4555)))))
   }
 
-  test("validate alter change datatype for complex children columns") {
+  test("test alter rename and change datatype for map of 
(primitive/array/struct)") {
     sql("drop table if exists test_rename")
     sql(
-      "CREATE TABLE test_rename (str struct<a:int,b:long>) STORED AS 
carbondata")
-
-    val ex1 = intercept[ProcessMetaDataException] {
-      sql("alter table test_rename change str str struct<a:long,b:long>")
-    }
-    assert(ex1.getMessage
-      .contains(
-        "column rename operation failed: Altering datatypes of any child 
column is not supported"))
+      "CREATE TABLE test_rename (map1 map<int,int>, map2 
map<string,array<int>>, " +
+      "map3 map<int, map<string,int>>, map4 map<string,struct<b:int>>) STORED 
AS carbondata")
+    sql("insert into test_rename values (map(1,2), map('a',array(1,2)), " +
+      "map(2,map('hello',1)), map('hi',named_struct('b',3)))")
+    // rename parent column from map1 to map11 and read old rows
+    sql("alter table test_rename change map1 map11 map<int,int>")
+    sql("insert into test_rename values (map(1,2), map('a',array(1,2)), " +
+      "map(2,map('hello',1)), map('hi',named_struct('b',3)))")
+    checkAnswer(sql("select map11 from test_rename"), Seq(Row(Map(1 -> 2)),
+      Row(Map(1 -> 2))))
+    // rename parent column from map2 to map22 and read old rows
+    sql("alter table test_rename change map2 map22 map<string,array<int>>")
+    sql("insert into test_rename values (map(1,2), map('a',array(1,2)), " +
+      "map(2,map('hello',1)), map('hi',named_struct('b',3)))")
+    checkAnswer(sql("select map22 from test_rename"), Seq(Row(Map("a" -> 
make(Array(1, 2)))),
+      Row(Map("a" -> make(Array(1, 2)))), Row(Map("a" -> make(Array(1, 2))))))
+    // rename child column and change datatype
+    sql("alter table test_rename change map4 map4 map<string,struct<b2:long>>")
+    sql("insert into test_rename values (map(1,2), map('a',array(1,2)), " +
+        "map(2,map('hello',1)), map('hi',named_struct('b',26557544541)))")
+    sql("alter table test_rename compact 'minor'")
+    checkAnswer(sql("select map4['hi']['b2'] from test_rename"),
+      Seq(Row(3), Row(3), Row(3), Row(26557544541L)))
+  }
+
+  test("test alter rename and change datatype for struct integer") {
+    sql("drop table if exists test_rename")
+    sql("CREATE TABLE test_rename (str struct<a:int>) STORED AS carbondata")
+    sql("insert into test_rename values(named_struct('a', 1234))")
+    sql("insert into test_rename values(named_struct('a', 3456))")
+    // only rename operation
+    sql("alter table test_rename change str str1 struct<a1:int>")
+    // both rename and change datatype operation
+    sql("alter table test_rename change str1 str1 struct<a2:long>")
+    sql("insert into test_rename values(named_struct('a2', 26557544541))")
+    // rename child column
+    sql("alter table test_rename change str1 str2 struct<a3:long>")
+    sql("insert into test_rename values(named_struct('a3', 26557544541))")
+    sql("alter table test_rename compact 'minor'")
+    checkAnswer(sql("select str2 from test_rename"),
+      Seq(Row(Row(1234L)), Row(Row(3456L)), Row(Row(26557544541L)), 
Row(Row(26557544541L))))
+  }
+
+  test("test alter rename and change datatype for map integer") {
+    sql("drop table if exists test_rename")
+    sql("CREATE TABLE test_rename (name string,mapField1 MAP<int, int>) STORED 
AS carbondata")
+    sql("insert into test_rename values('a',map(1,2))")
+    sql("insert into test_rename values('v',map(3,4))")
+    sql(s"create index si_1 on test_rename(name) as 'carbondata'")
+    // only rename operation
+    sql("alter table test_rename change mapField1 mapField2 MAP<int, int>")
+    sql("insert into test_rename values('df',map(5, 6))")
+    // both rename and change datatype operation
+    sql("alter table test_rename change mapField2 mapField3 MAP<int, long>")
+    sql("insert into test_rename values('sdf',map(7, 26557544541))")
+    sql("alter table test_rename compact 'minor'")
+    checkAnswer(sql("select mapField3 from test_rename"),
+      Seq(Row(Map(1 -> 2L)), Row(Map(3 -> 4L)), Row(Map(5 -> 6L)), Row(Map(7 
-> 26557544541L))))
+  }
+
+  test("test alter rename and change datatype for array integer") {
+    sql("drop table if exists test_rename")
+    sql("CREATE TABLE test_rename (arr array<int>) STORED AS carbondata")
+    sql("insert into test_rename values(array(1,2,3))")
+    sql("insert into test_rename values(array(4,5,6))")
+    // only rename operation
+    sql("alter table test_rename change arr arr1 array<int>")
+    sql("insert into test_rename values(array(7,8,9))")
+    // both rename and change datatype operation
+    sql("alter table test_rename change arr1 arr2 array<long>")
+    sql("insert into test_rename values(array(26557544541,3,46557544541))")
+    sql("alter table test_rename compact 'minor'")
+    checkAnswer(sql("select arr2 from test_rename"),
+      Seq(Row(make(Array(1, 2, 3))), Row(make(Array(4, 5, 6))), 
Row(make(Array(7, 8, 9))),
+        Row(make(Array(26557544541L, 3, 46557544541L)))))
+  }
+
+  test("test alter rename and change datatype for complex decimal types") {
+    sql("drop table if exists test_rename")
+    sql("CREATE TABLE test_rename (strField struct<a:decimal(5,2)>," +
+        "mapField1 map<int,decimal(5,2)>, mapField2 
map<int,struct<a:decimal(5,2)>>, " +
+        "arrField array<decimal(5,2)>) STORED AS carbondata")
+    sql("insert into test_rename values(named_struct('a', 123.45),map(1, 
123.45)," +
+        "map(1, named_struct('a', 123.45)),array(123.45))")
+    sql("insert into test_rename values(named_struct('a', 123.45),map(2, 
123.45)," +
+        "map(2, named_struct('a', 123.45)),array(123.45))")
+    // rename and change datatype
+    sql("alter table test_rename change strField strField1 
struct<a1:decimal(6,2)>")
+    sql("alter table test_rename change mapField1 mapField11 
map<int,decimal(6,2)>")
+    // rename and change nested decimal datatype
+    sql("alter table test_rename change mapField2 mapField22 
map<int,struct<a2:decimal(6,2)>>")

Review comment:
       Done. Validating using describe command.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to