carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jack...@apache.org
Subject [10/50] [abbrv] carbondata git commit: [CARBONDATA-1910]do not allow tupleid, referenceid and positionReference as columns names
Date Sun, 07 Jan 2018 03:05:18 GMT
[CARBONDATA-1910]do not allow tupleid, referenceid and positionReference as columns names

This closes #1682


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

Branch: refs/heads/carbonstore
Commit: 7a36c1a8de6d6c5a38d51807783e16cb50e48d8a
Parents: b120601
Author: akashrn5 <akashnilugal@gmail.com>
Authored: Tue Dec 19 18:34:10 2017 +0530
Committer: ravipesala <ravi.pesala@gmail.com>
Committed: Thu Dec 28 12:59:01 2017 +0530

----------------------------------------------------------------------
 .../createTable/TestCreateTableAsSelect.scala   | 18 +++++++++++
 .../iud/UpdateCarbonTableTestCase.scala         | 34 +++++++++++++++++++-
 .../spark/sql/catalyst/CarbonDDLSqlParser.scala | 20 ++++++++++++
 3 files changed, 71 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/carbondata/blob/7a36c1a8/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/createTable/TestCreateTableAsSelect.scala
----------------------------------------------------------------------
diff --git a/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/createTable/TestCreateTableAsSelect.scala
b/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/createTable/TestCreateTableAsSelect.scala
index ffe6261..09268b5 100644
--- a/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/createTable/TestCreateTableAsSelect.scala
+++ b/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/createTable/TestCreateTableAsSelect.scala
@@ -152,6 +152,24 @@ class TestCreateTableAsSelect extends QueryTest with BeforeAndAfterAll
{
     assert(dictFiles.length == 3)
   }
 
+  test("test create table as select with column name as tupleid") {
+    intercept[Exception] {
+      sql("create table t2 stored by 'carbondata' as select count(value) AS tupleid from
carbon_ctas_test")
+    }
+  }
+
+  test("test create table as select with column name as positionid") {
+    intercept[Exception] {
+      sql("create table t2 stored by 'carbondata' as select count(value) AS positionid from
carbon_ctas_test")
+    }
+  }
+
+  test("test create table as select with column name as positionreference") {
+    intercept[Exception] {
+      sql("create table t2 stored by 'carbondata' as select count(value) AS positionreference
from carbon_ctas_test")
+    }
+  }
+
   override def afterAll {
     sql("DROP TABLE IF EXISTS carbon_ctas_test")
     sql("DROP TABLE IF EXISTS parquet_ctas_test")

http://git-wip-us.apache.org/repos/asf/carbondata/blob/7a36c1a8/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/iud/UpdateCarbonTableTestCase.scala
----------------------------------------------------------------------
diff --git a/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/iud/UpdateCarbonTableTestCase.scala
b/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/iud/UpdateCarbonTableTestCase.scala
index 25a4999..7f6cae4 100644
--- a/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/iud/UpdateCarbonTableTestCase.scala
+++ b/integration/spark-common-test/src/test/scala/org/apache/carbondata/spark/testsuite/iud/UpdateCarbonTableTestCase.scala
@@ -637,6 +637,38 @@ class UpdateCarbonTableTestCase extends QueryTest with BeforeAndAfterAll
{
     sql("""drop table if exists iud.dest33_part""")
   }
 
+  test("test create table with tupleid as column name") {
+    try {
+      sql("create table create_with_tupleid_column(item int, tupleId String) stored by "
+
+          "'carbondata'")
+    } catch {
+      case ex: Exception =>
+        assert(ex.getMessage.contains("not allowed in column name while creating table"))
+    }
+  }
+
+  test("test create table with position reference as column name") {
+    try {
+      sql(
+        "create table create_with_positionReference_column(item int, positionReference String)
" +
+        "stored by 'carbondata'")
+    } catch {
+      case ex: Exception =>
+        assert(ex.getMessage.contains("not allowed in column name while creating table"))
+    }
+  }
+
+  test("test create table with position id as column name") {
+    try {
+      sql(
+        "create table create_with_positionid_column(item int, positionId String) stored by
" +
+        "'carbondata'")
+    } catch {
+      case ex: Exception =>
+        assert(ex.getMessage.contains("not allowed in column name while creating table"))
+    }
+  }
+
   override def afterAll {
     sql("use default")
     sql("drop database  if exists iud cascade")
@@ -645,4 +677,4 @@ class UpdateCarbonTableTestCase extends QueryTest with BeforeAndAfterAll
{
     CarbonProperties.getInstance()
       .addProperty(CarbonCommonConstants.ENABLE_VECTOR_READER , "true")
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/carbondata/blob/7a36c1a8/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 129e6b3..66351e3 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
@@ -231,6 +231,23 @@ abstract class CarbonDDLSqlParser extends AbstractCarbonSparkSQLParser
{
   }
 
   /**
+   * this function validates for the column names as tupleId, PositionReference and positionId
+   * @param fields
+   */
+  private def validateColumnNames(fields: Seq[Field]): Unit = {
+    fields.foreach { col =>
+      if (col.column.equalsIgnoreCase(CarbonCommonConstants.CARBON_IMPLICIT_COLUMN_TUPLEID)
||
+          col.column.equalsIgnoreCase(CarbonCommonConstants.CARBON_IMPLICIT_COLUMN_POSITIONID)
||
+          col.column.equalsIgnoreCase(CarbonCommonConstants.POSITION_REFERENCE)) {
+        throw new MalformedCarbonCommandException(
+          s"Carbon Implicit column ${col.column} is not allowed in" +
+          s" column name while creating table")
+      }
+
+    }
+  }
+
+  /**
    * This will prepate the Model from the Tree details.
    *
    * @param ifNotExistPresent
@@ -252,6 +269,9 @@ abstract class CarbonDDLSqlParser extends AbstractCarbonSparkSQLParser
{
       isAlterFlow: Boolean = false,
       tableComment: Option[String] = None): TableModel = {
 
+    // do not allow below key words as column name
+    validateColumnNames(fields)
+
     fields.zipWithIndex.foreach { case (field, index) =>
       field.schemaOrdinal = index
     }


Mime
View raw message