drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ve...@apache.org
Subject [2/5] drill git commit: DRILL-3215: Resolve the default subschema correctly in DESCRIBE command.
Date Mon, 08 Jun 2015 19:07:27 GMT
DRILL-3215: Resolve the default subschema correctly in DESCRIBE command.


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

Branch: refs/heads/master
Commit: eaf7c8d77058af58795862a0e0fd510b130f457c
Parents: 2af6340
Author: vkorukanti <venki.korukanti@gmail.com>
Authored: Fri May 29 08:57:40 2015 -0700
Committer: vkorukanti <venki.korukanti@gmail.com>
Committed: Fri Jun 5 07:49:54 2015 -0700

----------------------------------------------------------------------
 .../exec/hive/TestInfoSchemaOnHiveStorage.java  | 80 ++++++++++++++++++--
 .../sql/handlers/DescribeTableHandler.java      | 17 ++++-
 2 files changed, 88 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/eaf7c8d7/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestInfoSchemaOnHiveStorage.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestInfoSchemaOnHiveStorage.java
b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestInfoSchemaOnHiveStorage.java
index d8ab5c0..a7bd8e2 100644
--- a/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestInfoSchemaOnHiveStorage.java
+++ b/contrib/storage-hive/core/src/test/java/org/apache/drill/exec/hive/TestInfoSchemaOnHiveStorage.java
@@ -17,9 +17,14 @@
  */
 package org.apache.drill.exec.hive;
 
+import com.google.common.base.Strings;
+import org.apache.drill.TestBuilder;
 import org.junit.Test;
 
 public class TestInfoSchemaOnHiveStorage extends HiveTestBase {
+  private static final String[] baselineCols = new String[] {"COLUMN_NAME", "DATA_TYPE",
"IS_NULLABLE"};
+  private static final Object[] expVal1 = new Object[] {"key", "INTEGER", "YES"};
+  private static final Object[] expVal2 = new Object[] {"value", "VARCHAR", "YES"};
 
   @Test
   public void showTablesFromDb() throws Exception{
@@ -63,17 +68,78 @@ public class TestInfoSchemaOnHiveStorage extends HiveTestBase {
         .go();
   }
 
-  @Test
-  public void describeTableNullableColumns() throws Exception{
-    testBuilder()
-        .sqlQuery("DESCRIBE hive.`default`.kv")
+  private static void describeHelper(final String options, final String describeCmd) throws
Exception {
+    final TestBuilder builder = testBuilder();
+
+    if (!Strings.isNullOrEmpty(options)) {
+      builder.optionSettingQueriesForTestQuery(options);
+    }
+
+    builder.sqlQuery(describeCmd)
         .unOrdered()
-        .baselineColumns("COLUMN_NAME", "DATA_TYPE", "IS_NULLABLE")
-        .baselineValues("key", "INTEGER", "YES")
-        .baselineValues("value", "VARCHAR", "YES")
+        .baselineColumns(baselineCols)
+        .baselineValues(expVal1)
+        .baselineValues(expVal2)
         .go();
   }
 
+  // When table name is fully qualified with schema name (sub-schema is default schema)
+  @Test
+  public void describeTable1() throws Exception{
+    describeHelper(null, "DESCRIBE hive.`default`.kv");
+  }
+
+  // When table name is fully qualified with schema name (sub-schema is non-default schema)
+  @Test
+  public void describeTable2() throws Exception{
+    describeHelper(null, "DESCRIBE hive.`db1`.kv_db1");
+  }
+
+  // When table is qualified with just the top level schema. It should look for the table
in default sub-schema within
+  // the top level schema.
+  @Test
+  public void describeTable3() throws Exception {
+    describeHelper(null, "DESCRIBE hive.kv");
+  }
+
+  // When table name is qualified with multi-level schema (sub-schema is default schema)
given as single level schema name.
+  @Test
+  public void describeTable4() throws Exception {
+    describeHelper(null, "DESCRIBE `hive.default`.kv");
+  }
+
+  // When table name is qualified with multi-level schema (sub-schema is non-default schema)
+  // given as single level schema name.
+  @Test
+  public void describeTable5() throws Exception {
+    describeHelper(null, "DESCRIBE `hive.db1`.kv_db1");
+  }
+
+  // When current default schema is just the top-level schema name and the table has no schema
qualifier. It should
+  // look for the table in default sub-schema within the top level schema.
+  @Test
+  public void describeTable6() throws Exception {
+    describeHelper("USE hive", "DESCRIBE kv");
+  }
+
+  // When default schema is fully qualified with schema name and table is not qualified with
a schema name
+  @Test
+  public void describeTable7() throws Exception {
+    describeHelper("USE hive.`default`", "DESCRIBE kv");
+  }
+
+  // When default schema is qualified with multi-level schema given as single level schema
name.
+  @Test
+  public void describeTable8() throws Exception {
+    describeHelper("USE `hive.default`", "DESCRIBE kv");
+  }
+
+  // When default schema is top-level schema and table is qualified with sub-schema
+  @Test
+  public void describeTable9() throws Exception {
+    describeHelper("USE `hive`", "DESCRIBE `default`.kv");
+  }
+
   @Test
   public void varCharMaxLengthAndDecimalPrecisionInInfoSchema() throws Exception{
     final String query = "SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION,
NUMERIC_SCALE " +

http://git-wip-us.apache.org/repos/asf/drill/blob/eaf7c8d7/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DescribeTableHandler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DescribeTableHandler.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DescribeTableHandler.java
index 81defa3..676dcba 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DescribeTableHandler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DescribeTableHandler.java
@@ -62,12 +62,25 @@ public class DescribeTableHandler extends DefaultSqlHandler {
           ImmutableList.of(IS_SCHEMA_NAME, TAB_COLUMNS), null, SqlParserPos.ZERO, null);
 
       final SqlIdentifier table = node.getTable();
-      final SchemaPlus schema = SchemaUtilites.findSchema(context.getNewDefaultSchema(),
Util.skipLast(table.names));
+      final SchemaPlus defaultSchema = context.getNewDefaultSchema();
+      final List<String> schemaPathGivenInCmd = Util.skipLast(table.names);
+      final SchemaPlus schema = SchemaUtilites.findSchema(defaultSchema, schemaPathGivenInCmd);
+
+      if (schema == null) {
+        SchemaUtilites.throwSchemaNotFoundException(defaultSchema,
+            SchemaUtilites.SCHEMA_PATH_JOINER.join(schemaPathGivenInCmd));
+      }
+
+      if (SchemaUtilites.isRootSchema(schema)) {
+        throw UserException.validationError()
+            .message("No schema selected.")
+            .build();
+      }
 
       final String tableName = Util.last(table.names);
 
       // find resolved schema path
-      final String schemaPath = SchemaUtilites.getSchemaPath(schema);
+      final String schemaPath = SchemaUtilites.unwrapAsDrillSchemaInstance(schema).getFullSchemaName();
 
       if (schema.getTable(tableName) == null) {
         throw UserException.validationError()


Mime
View raw message