carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chenliang...@apache.org
Subject [17/50] [abbrv] incubator-carbondata git commit: Drop Table dbname.tablename is not working, carbondata file path if '-' exist, gives wrong value. (#797)
Date Wed, 20 Jul 2016 10:13:45 GMT
Drop Table dbname.tablename is not working, carbondata file path if '-' exist, gives wrong
value. (#797)



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

Branch: refs/heads/master
Commit: eecbdfde7734421c461a2d1f1780fc879e23f13e
Parents: 6a092bb
Author: nareshpr <prnaresh.naresh@gmail.com>
Authored: Fri Jul 15 22:31:16 2016 +0530
Committer: Ravindra Pesala <ravi.pesala@gmail.com>
Committed: Fri Jul 15 22:31:16 2016 +0530

----------------------------------------------------------------------
 .../core/carbon/path/CarbonTablePath.java       | 42 ++++++++++++++------
 .../CarbonFormatDirectoryStructureTest.java     |  4 ++
 .../spark/sql/hive/CarbonMetastoreCatalog.scala | 11 ++---
 .../spark/sql/hive/CarbonStrategies.scala       | 18 ++++++++-
 .../deleteTable/TestDeleteTableNewDDL.scala     | 11 +++++
 5 files changed, 67 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/eecbdfde/core/src/main/java/org/carbondata/core/carbon/path/CarbonTablePath.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/carbondata/core/carbon/path/CarbonTablePath.java b/core/src/main/java/org/carbondata/core/carbon/path/CarbonTablePath.java
index bf2ef57..4696927 100644
--- a/core/src/main/java/org/carbondata/core/carbon/path/CarbonTablePath.java
+++ b/core/src/main/java/org/carbondata/core/carbon/path/CarbonTablePath.java
@@ -305,33 +305,51 @@ public class CarbonTablePath extends Path {
      * gets updated timestamp information from given carbon data file name
      */
     public static String getUpdateTimeStamp(String carbonDataFileName) {
+      // Get the filename from file path
+      String fileName = getFileName(carbonDataFileName);
       // + 1 for size of "-"
-      int firstDashPos = carbonDataFileName.indexOf("-");
-      int secondDashPos = carbonDataFileName.indexOf("-", firstDashPos + 1);
-      int startIndex = carbonDataFileName.indexOf("-", secondDashPos + 1) + 1;
-      int endIndex = carbonDataFileName.indexOf(".");
-      return carbonDataFileName.substring(startIndex, endIndex);
+      int firstDashPos = fileName.indexOf("-");
+      int secondDashPos = fileName.indexOf("-", firstDashPos + 1);
+      int startIndex = fileName.indexOf("-", secondDashPos + 1) + 1;
+      int endIndex = fileName.indexOf(".");
+      return fileName.substring(startIndex, endIndex);
     }
 
     /**
      * gets file part number information from given carbon data file name
      */
     public static String getPartNo(String carbonDataFileName) {
+      // Get the filename from file path
+      String fileName = getFileName(carbonDataFileName);
       // + 1 for size of "-"
-      int startIndex = carbonDataFileName.indexOf("-") + 1;
-      int endIndex = carbonDataFileName.indexOf("-", startIndex);
-      return carbonDataFileName.substring(startIndex, endIndex);
+      int startIndex = fileName.indexOf("-") + 1;
+      int endIndex = fileName.indexOf("-", startIndex);
+      return fileName.substring(startIndex, endIndex);
     }
 
     /**
      * gets updated timestamp information from given carbon data file name
      */
     public static String getTaskNo(String carbonDataFileName) {
+      // Get the filename from file path
+      String fileName = getFileName(carbonDataFileName);
       // + 1 for size of "-"
-      int firstDashPos = carbonDataFileName.indexOf("-");
-      int startIndex = carbonDataFileName.indexOf("-", firstDashPos + 1) + 1;
-      int endIndex = carbonDataFileName.indexOf("-", startIndex);
-      return carbonDataFileName.substring(startIndex, endIndex);
+      int firstDashPos = fileName.indexOf("-");
+      int startIndex = fileName.indexOf("-", firstDashPos + 1) + 1;
+      int endIndex = fileName.indexOf("-", startIndex);
+      return fileName.substring(startIndex, endIndex);
+    }
+  }
+
+  /**
+   * Gets the file name from file path
+   */
+  private static String getFileName(String carbonDataFileName) {
+    int endIndex = carbonDataFileName.lastIndexOf(CarbonCommonConstants.FILE_SEPARATOR);
+    if (endIndex > -1) {
+      return carbonDataFileName.substring(endIndex + 1, carbonDataFileName.length());
+    } else {
+      return carbonDataFileName;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/eecbdfde/core/src/test/java/org/carbondata/core/path/CarbonFormatDirectoryStructureTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/carbondata/core/path/CarbonFormatDirectoryStructureTest.java
b/core/src/test/java/org/carbondata/core/path/CarbonFormatDirectoryStructureTest.java
index 540daa1..ee0059d 100644
--- a/core/src/test/java/org/carbondata/core/path/CarbonFormatDirectoryStructureTest.java
+++ b/core/src/test/java/org/carbondata/core/path/CarbonFormatDirectoryStructureTest.java
@@ -65,5 +65,9 @@ public class CarbonFormatDirectoryStructureTest {
     assertTrue(CarbonTablePath.DataFileUtil.getTaskNo("part-3-4-999.carbondata").equals("4"));
     assertTrue(
         CarbonTablePath.DataFileUtil.getUpdateTimeStamp("part-3-4-999.carbondata").equals("999"));
+    assertTrue(CarbonTablePath.DataFileUtil.getPartNo("/opt/apache-carbon/part-3-4-999.carbondata").equals("3"));
+    assertTrue(CarbonTablePath.DataFileUtil.getTaskNo("/opt/apache-carbon/part-3-4-999.carbondata").equals("4"));
+    assertTrue(
+        CarbonTablePath.DataFileUtil.getUpdateTimeStamp("/opt/apache-carbon/part-3-4-999.carbondata").equals("999"));
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/eecbdfde/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonMetastoreCatalog.scala
----------------------------------------------------------------------
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonMetastoreCatalog.scala
b/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonMetastoreCatalog.scala
index e8f752c..f952aa3 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonMetastoreCatalog.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonMetastoreCatalog.scala
@@ -481,6 +481,12 @@ class CarbonMetastoreCatalog(hive: HiveContext, val storePath: String,
client: C
       }
     }
 
+    metadata.cubesMeta -= metadata.cubesMeta.filter(
+      c => c.carbonTableIdentifier.getDatabaseName.equalsIgnoreCase(schemaName) &&
+           c.carbonTableIdentifier.getTableName.equalsIgnoreCase(cubeName))(0)
+    org.carbondata.core.carbon.metadata.CarbonMetadata.getInstance
+      .removeTable(schemaName + "_" + cubeName)
+
     try {
       sqlContext.sql(s"DROP TABLE $schemaName.$cubeName").collect()
     } catch {
@@ -489,11 +495,6 @@ class CarbonMetastoreCatalog(hive: HiveContext, val storePath: String,
client: C
           s"Error While deleting the table $schemaName.$cubeName during drop Table" + e.getMessage)
     }
 
-    metadata.cubesMeta -= metadata.cubesMeta.filter(
-      c => c.carbonTableIdentifier.getDatabaseName.equalsIgnoreCase(schemaName) &&
-           c.carbonTableIdentifier.getTableName.equalsIgnoreCase(cubeName))(0)
-    org.carbondata.core.carbon.metadata.CarbonMetadata.getInstance
-      .removeTable(schemaName + "_" + cubeName)
     logInfo(s"Table $cubeName of $schemaName Database dropped syccessfully.")
     LOGGER.info("Table " + cubeName + " of " + schemaName + " Database dropped syccessfully.")
 

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/eecbdfde/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonStrategies.scala
----------------------------------------------------------------------
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonStrategies.scala
b/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonStrategies.scala
index 429014d..fb5f8a5 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonStrategies.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonStrategies.scala
@@ -337,8 +337,14 @@ class CarbonStrategies(sqlContext: SQLContext) extends QueryPlanner[SparkPlan]
{
         ExecutedCommand(ShowAllTablesDetail(schemaName, plan.output)) :: Nil
       case DropTable(tableName, ifNotExists)
         if CarbonEnv.getInstance(sqlContext).carbonCatalog
-          .cubeExists(Seq(tableName.toLowerCase()))(sqlContext) =>
-        ExecutedCommand(DropCubeCommand(ifNotExists, None, tableName.toLowerCase())) :: Nil
+          .cubeExists(toTableIdentifier(tableName))(sqlContext) =>
+        val tblIdentifier = toTableIdentifier(tableName)
+        if(tblIdentifier.size == 2) {
+          ExecutedCommand(DropCubeCommand(ifNotExists,
+              Some(tblIdentifier(0)), tblIdentifier(1))) :: Nil
+        } else {
+          ExecutedCommand(DropCubeCommand(ifNotExists, None, tableName.toLowerCase())) ::
Nil
+        }
       case ShowAggregateTablesCommand(schemaName) =>
         ExecutedCommand(ShowAggregateTables(schemaName, plan.output)) :: Nil
       case ShowLoadsCommand(schemaName, cube, limit) =>
@@ -391,6 +397,14 @@ class CarbonStrategies(sqlContext: SQLContext) extends QueryPlanner[SparkPlan]
{
       case _ =>
         Nil
     }
+
+    private def toTableIdentifier(name: String): Seq[String] = {
+      val identifier = name.toLowerCase.split("\\.")
+      identifier match {
+        case Array(tableName) => Seq(tableName)
+        case Array(dbName, tableName) => Seq(dbName, tableName)
+      }
+    }
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/eecbdfde/integration/spark/src/test/scala/org/carbondata/spark/testsuite/deleteTable/TestDeleteTableNewDDL.scala
----------------------------------------------------------------------
diff --git a/integration/spark/src/test/scala/org/carbondata/spark/testsuite/deleteTable/TestDeleteTableNewDDL.scala
b/integration/spark/src/test/scala/org/carbondata/spark/testsuite/deleteTable/TestDeleteTableNewDDL.scala
index aeac733..c137e58 100644
--- a/integration/spark/src/test/scala/org/carbondata/spark/testsuite/deleteTable/TestDeleteTableNewDDL.scala
+++ b/integration/spark/src/test/scala/org/carbondata/spark/testsuite/deleteTable/TestDeleteTableNewDDL.scala
@@ -74,6 +74,17 @@ class TestDeleteTableNewDDL extends QueryTest with BeforeAndAfterAll {
 
   }
 
+  test("drop table using dbName and table name") {
+    // create table
+    sql(
+      "CREATE table default.table3 (ID int, date String, country String, name " +
+      "String," +
+      "phonetype String, serialname String, salary int) stored by 'org.apache.carbondata.format'"
+
+      "TBLPROPERTIES('DICTIONARY_INCLUDE'='ID', 'DICTIONARY_INCLUDE'='salary')"
+    )
+    // table should drop without any error
+    sql("drop table default.table3")
+  }
 
   override def afterAll: Unit = {
 


Mime
View raw message