drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [4/5] git commit: DRILL-763: Handle SubSchemaWrapper correctly in ShowFileHandler.
Date Wed, 21 May 2014 20:28:42 GMT
DRILL-763: Handle SubSchemaWrapper correctly in ShowFileHandler.


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

Branch: refs/heads/master
Commit: ea1ab62bc5b60fad4c306062b92f91eb429954a5
Parents: 935095e
Author: Mehant Baid <mehantr@gmail.com>
Authored: Wed May 21 01:22:39 2014 -0700
Committer: Mehant Baid <mehantr@gmail.com>
Committed: Wed May 21 01:39:15 2014 -0700

----------------------------------------------------------------------
 .../planner/sql/handlers/ShowFileHandler.java   | 50 ++++++++++----------
 .../exec/store/dfs/FileSystemSchemaFactory.java |  6 +--
 .../exec/store/dfs/HasFileSystemSchema.java     | 26 ----------
 .../exec/store/dfs/WorkspaceSchemaFactory.java  |  7 ++-
 .../apache/drill/jdbc/test/TestJdbcQuery.java   |  3 +-
 5 files changed, 33 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea1ab62b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFileHandler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFileHandler.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFileHandler.java
index 4f7c424..8ce0463 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFileHandler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFileHandler.java
@@ -26,6 +26,10 @@ import net.hydromatic.optiq.tools.Planner;
 import net.hydromatic.optiq.tools.RelConversionException;
 import net.hydromatic.optiq.tools.ValidationException;
 
+import org.apache.drill.exec.store.AbstractSchema;
+import org.apache.drill.exec.store.SubSchemaWrapper;
+import org.apache.drill.exec.store.dfs.WorkspaceSchemaFactory;
+import org.apache.drill.exec.store.dfs.WorkspaceSchemaFactory.WorkspaceSchema;
 import org.eigenbase.sql.SqlIdentifier;
 import org.eigenbase.sql.SqlNode;
 
@@ -33,12 +37,12 @@ import org.apache.drill.exec.ops.QueryContext;
 import org.apache.drill.exec.physical.PhysicalPlan;
 import org.apache.drill.exec.planner.sql.DirectPlan;
 import org.apache.drill.exec.planner.sql.parser.SqlShowFiles;
-import org.apache.drill.exec.store.dfs.HasFileSystemSchema;
 import org.apache.drill.exec.store.dfs.shim.DrillFileSystem;
 
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.FileStatus;
 
+
 public class ShowFileHandler extends DefaultSqlHandler {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SetOptionHandler.class);
 
@@ -50,40 +54,36 @@ public class ShowFileHandler extends DefaultSqlHandler {
   public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException,
IOException {
 
     SqlIdentifier from = ((SqlShowFiles) sqlNode).getDb();
-    String fromDir = from.names.get((from.names.size() - 1));
 
-    // Get the correct subschema
-    SchemaPlus schema = context.getNewDefaultSchema().getParentSchema();
-    for (int i = 0; i < from.names.size() - 1 && schema != null; i++) {
-      schema = schema.getSubSchema(from.names.get(i));
-    }
+    DrillFileSystem fs = null;
+    String defaultLocation = null;
 
-    // Traverse from the root schema if current schema is null
-    if (schema == null) {
-      schema = context.getRootSchema();
-
-      for (int i = 0; i < from.names.size() - 1 && schema != null; i++) {
-        schema = schema.getSubSchema(from.names.get(i));
-      }
+    try {
 
-      if (schema == null) {
-        throw new ValidationException("Invalid schema");
+      // Traverse and find the schema
+      SchemaPlus drillSchema = findSchema(context.getRootSchema(), context.getNewDefaultSchema(),
from.names.subList(0, from.names.size() - 1));
+      AbstractSchema tempSchema = getDrillSchema(drillSchema);
+      WorkspaceSchema schema = null;
+      if (tempSchema instanceof WorkspaceSchema) {
+        schema = ((WorkspaceSchema)tempSchema);
+      } else {
+        throw new ValidationException("Unsupported schema");
       }
-    }
 
-    DrillFileSystem fs;
+      // Get the file system object
+      fs = schema.getFS();
 
-    // Get the DrillFileSystem object
-    try {
-      HasFileSystemSchema fsSchema = schema.unwrap(HasFileSystemSchema.class);
-      fs = fsSchema.getFS();
-    } catch (ClassCastException e) {
-      throw new ValidationException("Schema not an instance of file system schema");
+      // Get the default path
+      defaultLocation = schema.getDefaultLocation();
+    } catch (Exception e) {
+        return DirectPlan.createDirectPlan(context, false, String.format("Current schema
'%s' is not a file system schema. " +
+                                           "Can't execute show files on this schema.", from.toString()));
     }
 
     List<ShowFilesCommandResult> rows = new ArrayList<>();
+    String fromDir = from.names.get((from.names.size() - 1));
 
-    for (FileStatus fileStatus : fs.list(false, new Path(fromDir))) {
+    for (FileStatus fileStatus : fs.list(false, new Path(defaultLocation, fromDir))) {
       ShowFilesCommandResult result = new ShowFilesCommandResult(fileStatus.getPath().getName(),
fileStatus.isDir(),
                                                                  !fileStatus.isDir(), fileStatus.getLen(),
                                                                  fileStatus.getOwner(), fileStatus.getGroup(),

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea1ab62b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
index 5d291f9..3b74b72 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
@@ -66,7 +66,7 @@ public class FileSystemSchemaFactory implements SchemaFactory{
     schema.setPlus(plusOfThis);
   }
 
-  public class FileSystemSchema extends AbstractSchema implements HasFileSystemSchema {
+  public class FileSystemSchema extends AbstractSchema {
 
     private final WorkspaceSchema defaultSchema;
     private final Map<String, WorkspaceSchema> schemaMap = Maps.newHashMap();
@@ -132,10 +132,6 @@ public class FileSystemSchemaFactory implements SchemaFactory{
       return defaultSchema.isMutable();
     }
 
-    public DrillFileSystem getFS() {
-        return defaultSchema.getFS();
-    }
-
     @Override
     public CreateTableEntry createNewTable(String tableName) {
       return defaultSchema.createNewTable(tableName);

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea1ab62b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/HasFileSystemSchema.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/HasFileSystemSchema.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/HasFileSystemSchema.java
deleted file mode 100644
index c11887a..0000000
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/HasFileSystemSchema.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * 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.drill.exec.store.dfs;
-
-import net.hydromatic.optiq.SchemaPlus;
-import org.apache.drill.exec.store.dfs.shim.DrillFileSystem;
-
-public interface HasFileSystemSchema {
-
-  public DrillFileSystem getFS();
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea1ab62b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
index b17779b..cf85861 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
@@ -113,7 +113,7 @@ public class WorkspaceSchemaFactory implements ExpandingConcurrentMap.MapValueFa
   public void destroy(DrillTable value) {
   }
 
-  public class WorkspaceSchema extends AbstractSchema implements HasFileSystemSchema {
+  public class WorkspaceSchema extends AbstractSchema {
 
     private ExpandingConcurrentMap<String, DrillTable> tables = new ExpandingConcurrentMap<String,
DrillTable>(WorkspaceSchemaFactory.this);
     private UserSession session;
@@ -141,11 +141,14 @@ public class WorkspaceSchemaFactory implements ExpandingConcurrentMap.MapValueFa
       return config.isWritable();
     }
 
-    @Override
     public DrillFileSystem getFS() {
       return fs;
     }
 
+    public String getDefaultLocation() {
+      return config.getLocation();
+    }
+
 
     @Override
     public CreateTableEntry createNewTable(String tableName) {

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ea1ab62b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
index 191aa0a..9ef5cc4 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
@@ -46,7 +46,7 @@ import com.google.common.base.Stopwatch;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-public class TestJdbcQuery extends JdbcTest{
+  public class TestJdbcQuery extends JdbcTest{
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestJdbcQuery.class);
 
 
@@ -787,6 +787,7 @@ public class TestJdbcQuery extends JdbcTest{
   @Test
   public void testShowFiles() throws Exception {
     testQuery("show files from dfs.`/tmp`");
+    testQuery("show files from `dfs.default`.`/tmp`");
 
   }
 


Mime
View raw message