drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ve...@apache.org
Subject [5/5] drill git commit: DRILL-2423: Show proper message when trying to drop an unknown view.
Date Wed, 06 May 2015 00:27:39 GMT
DRILL-2423: Show proper message when trying to drop an unknown view.


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

Branch: refs/heads/master
Commit: d43324f895172dcdbb5070faef37470d6bc107f5
Parents: ed02612
Author: vkorukanti <venki.korukanti@gmail.com>
Authored: Sat Apr 11 00:11:02 2015 -0700
Committer: vkorukanti <venki.korukanti@gmail.com>
Committed: Tue May 5 16:28:28 2015 -0700

----------------------------------------------------------------------
 .../exec/planner/sql/handlers/ViewHandler.java  | 27 ++++++++++----
 .../drill/exec/sql/TestBaseViewSupport.java     |  2 +-
 .../apache/drill/exec/sql/TestViewSupport.java  | 39 ++++++++++++++++++++
 3 files changed, 59 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/d43324f8/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
index 2428b45..c59c3a2 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.util.List;
 
 import org.apache.calcite.schema.Schema;
+import org.apache.calcite.schema.Schema.TableType;
 import org.apache.calcite.schema.SchemaPlus;
 import org.apache.calcite.schema.Table;
 import org.apache.calcite.tools.Planner;
@@ -134,6 +135,7 @@ public abstract class ViewHandler extends AbstractSqlHandler {
     @Override
     public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException,
IOException, ForemanSetupException {
       SqlDropView dropView = unwrap(sqlNode, SqlDropView.class);
+      final String viewToDrop = dropView.getName();
 
       try {
         SchemaPlus schema = findSchema(context.getRootSchema(), context.getNewDefaultSchema(),
dropView.getSchemaPath());
@@ -141,20 +143,29 @@ public abstract class ViewHandler extends AbstractSqlHandler {
 
         String schemaPath = drillSchema.getFullSchemaName();
         if (!drillSchema.isMutable()) {
-          return DirectPlan.createDirectPlan(context, false, String.format("Schema '%s' is
not a mutable schema. " +
-              "Views don't exist in this schema", schemaPath));
+          return DirectPlan.createDirectPlan(context, false, String.format("Schema [%s] is
immutable.", schemaPath));
         }
 
-        if (drillSchema instanceof WorkspaceSchema) {
-          ((WorkspaceSchema) drillSchema).dropView(dropView.getName());;
-        } else {
-          return DirectPlan.createDirectPlan(context, false, "Schema provided was not a workspace
schema.");
+        if (!(drillSchema instanceof WorkspaceSchema)) {
+          return DirectPlan.createDirectPlan(context, false,
+              String.format("Schema [%s] doesn't support creating/dropping views.", schemaPath));
         }
 
+        final Table existingTable = SqlHandlerUtil.getTableFromSchema(drillSchema, viewToDrop);
+        if (existingTable != null && existingTable.getJdbcTableType() != Schema.TableType.VIEW)
{
+          return DirectPlan.createDirectPlan(context, false,
+              String.format("[%s] is not a VIEW in schema [%s]", viewToDrop, schemaPath));
+        } else if (existingTable == null) {
+          return DirectPlan.createDirectPlan(context, false,
+              String.format("Unknown view [%s] in schema [%s].", viewToDrop, schemaPath));
+        }
+
+        ((WorkspaceSchema) drillSchema).dropView(viewToDrop);
+
         return DirectPlan.createDirectPlan(context, true,
-            String.format("View '%s' deleted successfully from '%s' schema", dropView.getName(),
schemaPath));
+            String.format("View [%s] deleted successfully from schema [%s].", viewToDrop,
schemaPath));
       } catch(Exception e) {
-        logger.debug("Failed to delete view {}", dropView.getName(), e);
+        logger.debug("Failed to delete view {}", viewToDrop, e);
         return DirectPlan.createDirectPlan(context, false, String.format("Error: %s", e.getMessage()));
       }
     }

http://git-wip-us.apache.org/repos/asf/drill/blob/d43324f8/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestBaseViewSupport.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestBaseViewSupport.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestBaseViewSupport.java
index bfe113b..a8f5bbb 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestBaseViewSupport.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestBaseViewSupport.java
@@ -100,7 +100,7 @@ public class TestBaseViewSupport extends BaseTestQuery {
         .sqlQuery(String.format("DROP VIEW %s", viewFullName))
         .unOrdered()
         .baselineColumns("ok", "summary")
-        .baselineValues(true, String.format("View '%s' deleted successfully from '%s' schema",
viewName, finalSchema))
+        .baselineValues(true, String.format("View [%s] deleted successfully from schema [%s].",
viewName, finalSchema))
         .go();
   }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/d43324f8/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
index 5c2dc90..0fc1f32 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
@@ -590,4 +590,43 @@ public class TestViewSupport extends TestBaseViewSupport {
         .baselineValues(false, errorMsg)
         .go();
   }
+
+  @Test // DRILL-2423
+  public void showProperMsgWhenDroppingNonExistentView() throws Exception{
+    testBuilder()
+        .sqlQuery("DROP VIEW dfs_test.tmp.nonExistentView")
+        .unOrdered()
+        .baselineColumns("ok", "summary")
+        .baselineValues(false, "Unknown view [nonExistentView] in schema [dfs_test.tmp].")
+        .go();
+  }
+
+  @Test // DRILL-2423
+  public void showProperMsgWhenTryingToDropAViewInImmutableSchema() throws Exception{
+    testBuilder()
+        .sqlQuery("DROP VIEW cp.nonExistentView")
+        .unOrdered()
+        .baselineColumns("ok", "summary")
+        .baselineValues(false, "Schema [cp.default] is immutable.")
+        .go();
+  }
+
+  @Test // DRILL-2423
+  public void showProperMsgWhenTryingToDropANonViewTable() throws Exception{
+    final String testTableName = "testTableShowErrorMsg";
+    try {
+      test(String.format("CREATE TABLE %s.%s AS SELECT c_custkey, c_nationkey from cp.`tpch/customer.parquet`",
+          TEMP_SCHEMA, testTableName));
+
+      testBuilder()
+          .sqlQuery(String.format("DROP VIEW %s.%s", TEMP_SCHEMA, testTableName))
+          .unOrdered()
+          .baselineColumns("ok", "summary")
+          .baselineValues(false, "[testTableShowErrorMsg] is not a VIEW in schema [dfs_test.tmp]")
+          .go();
+    } finally {
+      File tblPath = new File(getDfsTestTmpSchemaLocation(), testTableName);
+      FileUtils.deleteQuietly(tblPath);
+    }
+  }
 }


Mime
View raw message