sohami closed pull request #1390: DRILL-6624: Fix loss of the table row type
when the same schema name …
URL: https://github.com/apache/drill/pull/1390
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/exec/java-exec/src/main/java/org/apache/calcite/jdbc/DynamicRootSchema.java
b/exec/java-exec/src/main/java/org/apache/calcite/jdbc/DynamicRootSchema.java
index e6b8f49499d..5fecfddb28b 100644
---
a/exec/java-exec/src/main/java/org/apache/calcite/jdbc/DynamicRootSchema.java
+++
b/exec/java-exec/src/main/java/org/apache/calcite/jdbc/DynamicRootSchema.java
@@ -17,7 +17,6 @@
*/
package org.apache.calcite.jdbc;
-import com.google.common.collect.Lists;
import org.apache.calcite.DataContext;
import org.apache.calcite.linq4j.tree.Expression;
@@ -33,6 +32,7 @@
import org.apache.drill.exec.store.SubSchemaWrapper;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -70,16 +70,16 @@ protected CalciteSchema getImplicitSubSchema(String
schemaName,
}
/**
- * load schema factory(storage plugin) for schemaName
- * @param schemaName
- * @param caseSensitive
+ * Loads schema factory(storage plugin) for specified {@code schemaName}
+ * @param schemaName the name of the schema
+ * @param caseSensitive whether matching for the schema name is case
sensitive
*/
public void loadSchemaFactory(String schemaName, boolean caseSensitive) {
try {
- SchemaPlus thisPlus = this.plus();
+ SchemaPlus schemaPlus = this.plus();
StoragePlugin plugin = getSchemaFactories().getPlugin(schemaName);
if (plugin != null) {
- plugin.registerSchemas(schemaConfig, thisPlus);
+ plugin.registerSchemas(schemaConfig, schemaPlus);
return;
}
@@ -91,15 +91,17 @@ public void loadSchemaFactory(String schemaName, boolean
caseSensitive) {
return;
}
- // Found the storage plugin for first part(e.g. 'dfs') of schemaName
(e.g. 'dfs.tmp')
- // register schema for this storage plugin to 'this'.
- plugin.registerSchemas(schemaConfig, thisPlus);
-
+ // Looking for the SchemaPlus for the top level (e.g. 'dfs') of
schemaName (e.g. 'dfs.tmp')
+ SchemaPlus firstLevelSchema = schemaPlus.getSubSchema(paths.get(0));
+ if (firstLevelSchema == null) {
+ // register schema for this storage plugin to 'this'.
+ plugin.registerSchemas(schemaConfig, schemaPlus);
+ firstLevelSchema = schemaPlus.getSubSchema(paths.get(0));
+ }
// Load second level schemas for this storage plugin
- final SchemaPlus firstlevelSchema =
thisPlus.getSubSchema(paths.get(0));
- final List<SchemaPlus> secondLevelSchemas = Lists.newArrayList();
- for (String secondLevelSchemaName :
firstlevelSchema.getSubSchemaNames()) {
-
secondLevelSchemas.add(firstlevelSchema.getSubSchema(secondLevelSchemaName));
+ List<SchemaPlus> secondLevelSchemas = new ArrayList<>();
+ for (String secondLevelSchemaName :
firstLevelSchema.getSubSchemaNames()) {
+
secondLevelSchemas.add(firstLevelSchema.getSubSchema(secondLevelSchemaName));
}
for (SchemaPlus schema : secondLevelSchemas) {
@@ -110,7 +112,7 @@ public void loadSchemaFactory(String schemaName, boolean
caseSensitive) {
throw new RuntimeException(String.format("Schema '%s' is not
expected under root schema", schema.getName()));
}
SubSchemaWrapper wrapper = new SubSchemaWrapper(drillSchema);
- thisPlus.add(wrapper.getName(), wrapper);
+ schemaPlus.add(wrapper.getName(), wrapper);
}
}
} catch(ExecutionSetupException | IOException ex) {
diff --git
a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSchema.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSchema.java
index 9282eed51a6..986925f4729 100644
---
a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSchema.java
+++
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSchema.java
@@ -84,4 +84,33 @@ public void testUseBrokenStorage() throws Exception {
}
}
+ @Test
+ public void testLocal() throws Exception {
+ try {
+ client.queryBuilder()
+ .sql("create table dfs.tmp.t1 as select 1 as c1")
+ .run();
+
+ client.queryBuilder()
+ .sql("create table dfs.tmp.t2 as select 1 as c1")
+ .run();
+
+ client.testBuilder()
+ .sqlQuery("select a.c1 from dfs.tmp.`t1` a\n" +
+ "join `dfs.tmp`.`t2` b ON b.c1 = a.c1\n")
+ .unOrdered()
+ .baselineColumns("c1")
+ .baselineValues(1)
+ .go();
+ } finally {
+ client.queryBuilder()
+ .sql("drop table if exists `dfs.tmp`.t1")
+ .run();
+
+ client.queryBuilder()
+ .sql("drop table if exists dfs.tmp.t2")
+ .run();
+ }
+ }
+
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services