Repository: carbondata
Updated Branches:
  refs/heads/master fa1c515f2 -> f97db6877


[CARBONDATA-2131] Alter table adding long datatype is failing but Create table 
with long type is successful, in Spark 2.1

Modified code to make "Create table" supported data types and "alter add 
columns" supported data types consistent

This closes #1932


Project: http://git-wip-us.apache.org/repos/asf/carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/carbondata/commit/f97db687
Tree: http://git-wip-us.apache.org/repos/asf/carbondata/tree/f97db687
Diff: http://git-wip-us.apache.org/repos/asf/carbondata/diff/f97db687

Branch: refs/heads/master
Commit: f97db687760c012eda46f8108e02ae3ee45720a8
Parents: fa1c515
Author: dhatchayani <[email protected]>
Authored: Mon Feb 5 16:21:09 2018 +0530
Committer: manishgupta88 <[email protected]>
Committed: Thu Feb 8 12:14:34 2018 +0530

----------------------------------------------------------------------
 .../spark/sql/catalyst/CarbonDDLSqlParser.scala |  3 ++-
 .../table/CarbonCreateTableCommand.scala        |  2 +-
 .../AlterTableValidationTestCase.scala          | 22 ++++++++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/carbondata/blob/f97db687/integration/spark-common/src/main/scala/org/apache/spark/sql/catalyst/CarbonDDLSqlParser.scala
----------------------------------------------------------------------
diff --git 
a/integration/spark-common/src/main/scala/org/apache/spark/sql/catalyst/CarbonDDLSqlParser.scala
 
b/integration/spark-common/src/main/scala/org/apache/spark/sql/catalyst/CarbonDDLSqlParser.scala
index 3da603b..84215fd 100644
--- 
a/integration/spark-common/src/main/scala/org/apache/spark/sql/catalyst/CarbonDDLSqlParser.scala
+++ 
b/integration/spark-common/src/main/scala/org/apache/spark/sql/catalyst/CarbonDDLSqlParser.scala
@@ -168,6 +168,7 @@ abstract class CarbonDDLSqlParser extends 
AbstractCarbonSparkSQLParser {
   protected val SHORT = carbonKeyWord("SHORT")
   protected val INT = carbonKeyWord("INT")
   protected val BOOLEAN = carbonKeyWord("BOOLEAN")
+  protected val LONG = carbonKeyWord("LONG")
   protected val BIGINT = carbonKeyWord("BIGINT")
   protected val ARRAY = carbonKeyWord("ARRAY")
   protected val STRUCT = carbonKeyWord("STRUCT")
@@ -1022,7 +1023,7 @@ abstract class CarbonDDLSqlParser extends 
AbstractCarbonSparkSQLParser {
   protected lazy val primitiveTypes =
     STRING ^^^ "string" |BOOLEAN ^^^ "boolean" | INTEGER ^^^ "integer" |
     TIMESTAMP ^^^ "timestamp" | NUMERIC ^^^ "numeric" |
-    BIGINT ^^^ "bigint" | (SHORT | SMALLINT) ^^^ "smallint" |
+    (LONG | BIGINT) ^^^ "bigint" | (SHORT | SMALLINT) ^^^ "smallint" |
     INT ^^^ "int" | DOUBLE ^^^ "double" | FLOAT ^^^ "double" | decimalType |
     DATE ^^^ "date" | charType
 

http://git-wip-us.apache.org/repos/asf/carbondata/blob/f97db687/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonCreateTableCommand.scala
----------------------------------------------------------------------
diff --git 
a/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonCreateTableCommand.scala
 
b/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonCreateTableCommand.scala
index 13d6274..c4030d6 100644
--- 
a/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonCreateTableCommand.scala
+++ 
b/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonCreateTableCommand.scala
@@ -124,7 +124,7 @@ case class CarbonCreateTableCommand(
             val msg = s"Create table'$tableName' in database '$dbName' failed"
             LOGGER.audit(msg.concat(", ").concat(e.getMessage))
             LOGGER.error(e, msg)
-            throwMetadataException(dbName, tableName, msg)
+            throwMetadataException(dbName, tableName, msg.concat(", 
").concat(e.getMessage))
         }
       }
       val createTablePostExecutionEvent: CreateTablePostExecutionEvent =

http://git-wip-us.apache.org/repos/asf/carbondata/blob/f97db687/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/AlterTableValidationTestCase.scala
----------------------------------------------------------------------
diff --git 
a/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/AlterTableValidationTestCase.scala
 
b/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/AlterTableValidationTestCase.scala
index b62e3c9..04f2a71 100644
--- 
a/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/AlterTableValidationTestCase.scala
+++ 
b/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/AlterTableValidationTestCase.scala
@@ -128,6 +128,28 @@ class AlterTableValidationTestCase extends Spark2QueryTest 
with BeforeAndAfterAl
       Row(new BigDecimal("123.45").setScale(2, RoundingMode.HALF_UP)))
   }
 
+  // test alter add LONG datatype before load, see CARBONDATA-2131
+  test("test add long column before load") {
+    sql("drop table if exists alterLong")
+    sql("create table alterLong (name string) stored by 'carbondata'")
+    sql("alter table alterLong add columns(newCol long)")
+    sql("insert into alterLong select 'a',60000")
+    checkAnswer(sql("select * from alterLong"), Row("a", 60000))
+    sql("drop table if exists alterLong")
+  }
+
+  // test alter add LONG datatype after load, see CARBONDATA-2131
+  test("test add long column after load") {
+    sql("drop table if exists alterLong1")
+    sql("create table alterLong1 (name string) stored by 'carbondata'")
+    sql("insert into alterLong1 select 'a'")
+    sql("alter table alterLong1 add columns(newCol long)")
+    checkAnswer(sql("select * from alterLong1"), Row("a", null))
+    sql("insert into alterLong1 select 'b',70")
+    checkAnswer(sql("select * from alterLong1"), Seq(Row("a", null),Row("b", 
70)))
+    sql("drop table if exists alterLong1")
+  }
+
   test("test add all datatype supported dictionary column") {
     sql(
       "alter table restructure add columns(strfld string, datefld date, tptfld 
timestamp, " +

Reply via email to