carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chenliang...@apache.org
Subject [1/2] incubator-carbondata git commit: Fixed unwanted exception in case of Drop table through spark-sql-CLI
Date Thu, 04 May 2017 13:05:36 GMT
Repository: incubator-carbondata
Updated Branches:
  refs/heads/master ccd8175f8 -> fe730fa76


Fixed unwanted exception in case of Drop table through spark-sql-CLI

Incorporated review comments


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

Branch: refs/heads/master
Commit: a0cba3851e952e73f3c8ace4391dbe33bd77684d
Parents: ccd8175
Author: Bhavya <bhavya@knoldus.com>
Authored: Wed Apr 19 12:50:54 2017 +0530
Committer: chenliang613 <chenliang613@huawei.com>
Committed: Thu May 4 21:04:08 2017 +0800

----------------------------------------------------------------------
 .../org/apache/spark/sql/CarbonSource.scala     | 38 +++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/a0cba385/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 536c19f..19a278b 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
@@ -112,7 +112,17 @@ class CarbonSource extends CreatableRelationProvider with RelationProvider
       dataSchema: StructType): BaseRelation = {
     CarbonEnv.getInstance(sqlContext.sparkSession)
     addLateDecodeOptimization(sqlContext.sparkSession)
-    val path = createTableIfNotExists(sqlContext.sparkSession, parameters, dataSchema)
+    val dbName: String = parameters.getOrElse("dbName",
+      CarbonCommonConstants.DATABASE_DEFAULT_NAME).toLowerCase
+    val tableName: String = parameters.getOrElse("tableName", "default_table").toLowerCase
+
+    val path = if (sqlContext.sparkSession.sessionState.catalog.listTables(dbName)
+      .exists(_.table.equalsIgnoreCase(tableName))) {
+        getPathForTable(sqlContext.sparkSession, dbName, tableName)
+    } else {
+        createTableIfNotExists(sqlContext.sparkSession, parameters, dataSchema)
+    }
+
     CarbonDatasourceHadoopRelation(sqlContext.sparkSession, Array(path), parameters,
       Option(dataSchema))
   }
@@ -186,4 +196,30 @@ class CarbonSource extends CreatableRelationProvider with RelationProvider
     }
   }
 
+  /**
+   * Returns the path of the table
+   * @param sparkSession
+   * @param dbName
+   * @param tableName
+   * @return
+   */
+  private def getPathForTable(sparkSession: SparkSession, dbName: String,
+      tableName : String): String = {
+
+    if (StringUtils.isBlank(tableName)) {
+      throw new MalformedCarbonCommandException("The Specified Table Name is Blank")
+    }
+    if (tableName.contains(" ")) {
+      throw new MalformedCarbonCommandException("Table Name Should not have spaces ")
+    }
+    try {
+      CarbonEnv.getInstance(sparkSession).carbonMetastore
+        .lookupRelation(Option(dbName), tableName)(sparkSession)
+      CarbonEnv.getInstance(sparkSession).carbonMetastore.storePath + s"/$dbName/$tableName"
+    } catch {
+      case ex: Exception =>
+        throw new Exception(s"Do not have $dbName and $tableName", ex)
+    }
+  }
+
 }


Mime
View raw message