You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by ra...@apache.org on 2017/05/11 13:52:59 UTC
[09/50] carbondata git commit: Fixed unwanted exception in case of
Drop table through spark-sql-CLI
Fixed unwanted exception in case of Drop table through spark-sql-CLI
Incorporated review comments
Project: http://git-wip-us.apache.org/repos/asf/carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/carbondata/commit/a0cba385
Tree: http://git-wip-us.apache.org/repos/asf/carbondata/tree/a0cba385
Diff: http://git-wip-us.apache.org/repos/asf/carbondata/diff/a0cba385
Branch: refs/heads/branch-1.1
Commit: a0cba3851e952e73f3c8ace4391dbe33bd77684d
Parents: ccd8175
Author: Bhavya <bh...@knoldus.com>
Authored: Wed Apr 19 12:50:54 2017 +0530
Committer: chenliang613 <ch...@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/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)
+ }
+ }
+
}