Repository: incubator-carbondata
Updated Branches:
  refs/heads/master ab4556d71 -> f58853d2f


Drop table IS is throwing exception


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

Branch: refs/heads/master
Commit: 3d21ccba668d3c42c9bd2d276d45c55d23e0b7fe
Parents: ab4556d
Author: Manohar <manohar.craz...@gmail.com>
Authored: Sat Apr 15 13:42:29 2017 +0530
Committer: Manohar <manohar.craz...@gmail.com>
Committed: Sat Apr 15 19:38:56 2017 +0530

----------------------------------------------------------------------
 .../core/metadata/AbsoluteTableIdentifier.java  |  5 +-
 .../spark/sql/hive/CarbonHiveMetadataUtil.scala |  5 +-
 .../deletetable/DeleteTableTestCase.scala       | 65 ++++++++++++++++++++
 3 files changed, 71 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/3d21ccba/core/src/main/java/org/apache/carbondata/core/metadata/AbsoluteTableIdentifier.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/carbondata/core/metadata/AbsoluteTableIdentifier.java
 
b/core/src/main/java/org/apache/carbondata/core/metadata/AbsoluteTableIdentifier.java
index 3791150..3c39145 100644
--- 
a/core/src/main/java/org/apache/carbondata/core/metadata/AbsoluteTableIdentifier.java
+++ 
b/core/src/main/java/org/apache/carbondata/core/metadata/AbsoluteTableIdentifier.java
@@ -90,8 +90,9 @@ public class AbsoluteTableIdentifier implements Serializable {
 
     String tableName = names[names.length - 1];
     String dbName = names[names.length - 2];
-    String storePath = formattedTablePath.substring(0, 
formattedTablePath.lastIndexOf(dbName +
-            CarbonCommonConstants.FILE_SEPARATOR + tableName));
+    String storePath = formattedTablePath.substring(0,
+        formattedTablePath.lastIndexOf(dbName + 
CarbonCommonConstants.FILE_SEPARATOR + tableName)
+            - 1);
 
     CarbonTableIdentifier identifier =
         new CarbonTableIdentifier(dbName, tableName, 
Long.toString(System.currentTimeMillis()));

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/3d21ccba/integration/spark2/src/main/scala/org/apache/spark/sql/hive/CarbonHiveMetadataUtil.scala
----------------------------------------------------------------------
diff --git 
a/integration/spark2/src/main/scala/org/apache/spark/sql/hive/CarbonHiveMetadataUtil.scala
 
b/integration/spark2/src/main/scala/org/apache/spark/sql/hive/CarbonHiveMetadataUtil.scala
index 657d7de..d67ae6b 100644
--- 
a/integration/spark2/src/main/scala/org/apache/spark/sql/hive/CarbonHiveMetadataUtil.scala
+++ 
b/integration/spark2/src/main/scala/org/apache/spark/sql/hive/CarbonHiveMetadataUtil.scala
@@ -17,6 +17,7 @@
 package org.apache.spark.sql.hive
 
 import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.catalyst.TableIdentifier
 
 import org.apache.carbondata.common.logging.LogServiceFactory
 
@@ -41,8 +42,8 @@ object CarbonHiveMetadataUtil {
       tableName: String,
       sparkSession: SparkSession): Unit = {
     try {
-      
sparkSession.sharedState.externalCatalog.asInstanceOf[HiveExternalCatalog].client.
-        runSqlHive(s"DROP TABLE IF EXISTS $databaseName.$tableName")
+      val tabelIdentifier = TableIdentifier(tableName, Some(databaseName))
+      sparkSession.sessionState.catalog.dropTable(tabelIdentifier, true, false)
     } catch {
       case e: Exception =>
         LOGGER.audit(

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/3d21ccba/integration/spark2/src/test/scala/org/apache/spark/carbondata/deletetable/DeleteTableTestCase.scala
----------------------------------------------------------------------
diff --git 
a/integration/spark2/src/test/scala/org/apache/spark/carbondata/deletetable/DeleteTableTestCase.scala
 
b/integration/spark2/src/test/scala/org/apache/spark/carbondata/deletetable/DeleteTableTestCase.scala
new file mode 100644
index 0000000..1ab9409
--- /dev/null
+++ 
b/integration/spark2/src/test/scala/org/apache/spark/carbondata/deletetable/DeleteTableTestCase.scala
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.carbondata.deletetable
+
+import org.apache.spark.sql.common.util.QueryTest
+import org.scalatest.BeforeAndAfterAll
+
+/**
+ * Test cases for drop table
+ */
+class DeleteTableTestCase extends QueryTest with BeforeAndAfterAll {
+
+  override def beforeAll {
+    sql("drop table if exists IS")
+  }
+
+  test("drop table IS with load") {
+    sql("drop table if exists IS")
+    sql(
+      "CREATE TABLE IS (imei string,age int,task bigint,name string,country 
string," +
+      "city string,sale int,num double,level decimal(10,3),quest 
bigint,productdate timestamp," +
+      "enddate timestamp,PointId double,score decimal(10,3))STORED BY 
'org.apache.carbondata" +
+      ".format'")
+    sql(
+      s"LOAD DATA INPATH '$resourcesPath/big_int_Decimal.csv'  INTO TABLE IS " 
+
+      "options ('DELIMITER'=',', 'QUOTECHAR'='\"', 
'COMPLEX_DELIMITER_LEVEL_1'='$'," +
+      "'COMPLEX_DELIMITER_LEVEL_2'=':', 'FILEHEADER'= '')")
+    sql("drop table IS")
+    sql("drop table if exists IS")
+    sql(
+      "CREATE TABLE IS (imei string,age int,task bigint,name string,country 
string," +
+      "city string,sale int,num double,level decimal(10,3),quest 
bigint,productdate timestamp," +
+      "enddate timestamp,PointId double,score decimal(10,3))STORED BY 
'org.apache.carbondata" +
+      ".format'")
+    sql("drop table if exists IS")
+  }
+
+  test("drop table IS without load") {
+    sql("drop table if exists IS")
+    sql(
+      "CREATE TABLE IS (imei string,age int,task bigint,name string,country 
string," +
+      "city string,sale int,num double,level decimal(10,3),quest 
bigint,productdate timestamp," +
+      "enddate timestamp,PointId double,score decimal(10,3))STORED BY 
'org.apache.carbondata" +
+      ".format'")
+    sql("drop table if exists IS")
+  }
+  override def afterAll {
+    sql("drop table if exists IS")
+  }
+}

Reply via email to