You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by ja...@apache.org on 2018/03/26 15:23:27 UTC

carbondata git commit: [CARBONDATA-2264] Support create table using CarbonSource Without TableName

Repository: carbondata
Updated Branches:
  refs/heads/master 5da419149 -> 2eb8f047c


[CARBONDATA-2264] Support create table using CarbonSource Without TableName

CarbonData should work when create table Without TableName in options.

This closes #2080


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

Branch: refs/heads/master
Commit: 2eb8f047c2a6d55751a5593cd7a3a62f33088322
Parents: 5da4191
Author: root <60...@qq.com>
Authored: Tue Mar 20 15:53:40 2018 +0800
Committer: Jacky Li <ja...@qq.com>
Committed: Mon Mar 26 23:22:59 2018 +0800

----------------------------------------------------------------------
 .../org/apache/spark/sql/CarbonSource.scala     |  7 +-
 .../carbondata/CarbonDataSourceSuite.scala      | 72 +++++++++++---------
 2 files changed, 47 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/carbondata/blob/2eb8f047/integration/spark2/src/main/scala/org/apache/spark/sql/CarbonSource.scala
----------------------------------------------------------------------
diff --git a/integration/spark2/src/main/scala/org/apache/spark/sql/CarbonSource.scala b/integration/spark2/src/main/scala/org/apache/spark/sql/CarbonSource.scala
index aab2897..693b6c8 100644
--- a/integration/spark2/src/main/scala/org/apache/spark/sql/CarbonSource.scala
+++ b/integration/spark2/src/main/scala/org/apache/spark/sql/CarbonSource.scala
@@ -36,7 +36,7 @@ import org.apache.spark.sql.types.StructType
 import org.apache.spark.sql.util.CarbonException
 
 import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException
-import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.common.logging.LogServiceFactory
 import org.apache.carbondata.core.metadata.AbsoluteTableIdentifier
 import org.apache.carbondata.core.metadata.schema.SchemaEvolutionEntry
 import org.apache.carbondata.core.metadata.schema.table.TableInfo
@@ -334,6 +334,11 @@ object CarbonSource {
     properties.foreach(e => map.put(e._1, e._2))
     map.put("tablepath", identifier.getTablePath)
     map.put("dbname", identifier.getDatabaseName)
+    if (map.containsKey("tableName")) {
+      val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
+      LOGGER.warn("tableName is not required in options, ignoring it")
+    }
+    map.put("tableName", identifier.getTableName)
     map.asScala.toMap
   }
 }

http://git-wip-us.apache.org/repos/asf/carbondata/blob/2eb8f047/integration/spark2/src/test/scala/org/apache/spark/carbondata/CarbonDataSourceSuite.scala
----------------------------------------------------------------------
diff --git a/integration/spark2/src/test/scala/org/apache/spark/carbondata/CarbonDataSourceSuite.scala b/integration/spark2/src/test/scala/org/apache/spark/carbondata/CarbonDataSourceSuite.scala
index eb52910..3a67107 100644
--- a/integration/spark2/src/test/scala/org/apache/spark/carbondata/CarbonDataSourceSuite.scala
+++ b/integration/spark2/src/test/scala/org/apache/spark/carbondata/CarbonDataSourceSuite.scala
@@ -202,6 +202,37 @@ class CarbonDataSourceSuite extends Spark2QueryTest with BeforeAndAfterAll {
     sql("drop table create_source")
   }
 
+  test("test create table with complex datatype without tablename in options") {
+    sql("DROP TABLE IF EXISTS create_source")
+    sql(
+      s"""
+         | CREATE TABLE create_source(
+         | intField INT,
+         | stringField STRING,
+         | complexField ARRAY<STRING>)
+         | USING org.apache.spark.sql.CarbonSource
+       """.stripMargin)
+    sql("DROP TABLE create_source")
+  }
+
+  test("test create table with different tableName in options") {
+    sql("DROP TABLE IF EXISTS create_source_test")
+    sql("DROP TABLE IF EXISTS create_source_test2")
+    sql(
+      s"""
+         | CREATE TABLE create_source_test(
+         | intField INT,
+         | stringField STRING,
+         | complexField ARRAY<STRING>)
+         | USING org.apache.spark.sql.CarbonSource
+         | OPTIONS('tableName'='create_source_test2')
+       """.stripMargin)
+    checkExistence(sql("show tables"), true, "create_source_test")
+    checkExistence(sql("show tables"), false, "create_source_test2")
+    sql("DROP TABLE IF EXISTS create_source_test")
+    sql("DROP TABLE IF EXISTS create_source_test2")
+  }
+
   test("test to create bucket columns with int field") {
     sql("drop table if exists create_source")
     intercept[Exception] {
@@ -225,40 +256,19 @@ class CarbonDataSourceSuite extends Spark2QueryTest with BeforeAndAfterAll {
     sql("drop table if exists create_source")
   }
 
-  test("test create table without tableName in options") {
+  test("test create table without tableName in options, should support") {
     sql("drop table if exists carbon_test")
-    val exception = intercept[AnalysisException] {
-      sql(
-        s"""
-           | CREATE TABLE carbon_test(
-           |    stringField string,
-           |    intField int)
-           | USING org.apache.spark.sql.CarbonSource
-           | OPTIONS('DICTIONARY_EXCLUDE'='stringField')
-      """.
-          stripMargin
-      )
-    }.getMessage
-    sql("drop table if exists carbon_test")
-    assert(exception.contains("Table creation failed. Table name is not specified"))
-  }
-
-  test("test create table with space in tableName") {
-    sql("drop table if exists carbon_test")
-    val exception = intercept[AnalysisException] {
-      sql(
-        s"""
-           | CREATE TABLE carbon_test(
-           |    stringField string,
-           |    intField int)
-           | USING org.apache.spark.sql.CarbonSource
-           | OPTIONS('DICTIONARY_EXCLUDE'='stringField', 'tableName'='carbon test')
+    sql(
+      s"""
+         | CREATE TABLE carbon_test(
+         |    stringField string,
+         |    intField int)
+         | USING org.apache.spark.sql.CarbonSource
+         | OPTIONS('DICTIONARY_EXCLUDE'='stringField')
       """.
-          stripMargin
-      )
-    }.getMessage
+        stripMargin
+    )
     sql("drop table if exists carbon_test")
-    assert(exception.contains("Table creation failed. Table name cannot contain blank space"))
   }
 
   test("test create table: using") {