Fix regression with using views inside and outside schema due to persistent changes.
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/3e78cbf3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/3e78cbf3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/3e78cbf3 Branch: refs/heads/master Commit: 3e78cbf3dd7cd671cac36b48f0ce949f1e7d94b7 Parents: 99313db Author: Jacques Nadeau <[email protected]> Authored: Tue Jun 10 18:05:07 2014 -0700 Committer: Jacques Nadeau <[email protected]> Committed: Tue Jun 10 18:59:41 2014 -0700 ---------------------------------------------------------------------- .../exec/planner/logical/DrillViewTable.java | 10 +++-- .../exec/store/dfs/WorkspaceSchemaFactory.java | 2 +- .../apache/drill/exec/sql/TestViewSupport.java | 44 ++++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3e78cbf3/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java index 8ce6af3..aaf32ad 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java @@ -17,6 +17,8 @@ */ package org.apache.drill.exec.planner.logical; +import java.util.List; + import net.hydromatic.optiq.Schema.TableType; import net.hydromatic.optiq.Statistic; import net.hydromatic.optiq.Statistics; @@ -33,10 +35,12 @@ import org.eigenbase.reltype.RelDataTypeFactory; public class DrillViewTable implements TranslatableTable{ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillViewTable.class); - private View view; + private final View view; + private final List<String> path; - public DrillViewTable(View view){ + public DrillViewTable(List<String> path, View view){ this.view = view; + this.path = path; } @Override @@ -52,7 +56,7 @@ public class DrillViewTable implements TranslatableTable{ @Override public RelNode toRel(ToRelContext context, RelOptTable relOptTable) { RelDataType rowType = relOptTable.getRowType(); - RelNode rel = context.expandView(rowType, view.getSql(), relOptTable.getQualifiedName()); + RelNode rel = context.expandView(rowType, view.getSql(), path); if (view.isDynamic()){ return rel; http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3e78cbf3/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 e1cd835..1d2bf91 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 @@ -223,7 +223,7 @@ public class WorkspaceSchemaFactory implements ExpandingConcurrentMap.MapValueFa for(DotDrillFile f : files){ switch(f.getType()){ case VIEW: - return new DrillViewTable(getView(f)); + return new DrillViewTable(schemaPath, getView(f)); } } } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3e78cbf3/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 new file mode 100644 index 0000000..5c034e5 --- /dev/null +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java @@ -0,0 +1,44 @@ +/** + * 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.sql; + +import org.apache.drill.BaseTestQuery; +import org.junit.Test; + +public class TestViewSupport extends BaseTestQuery{ + static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestViewSupport.class); + + @Test + public void referToSchemaInsideAndOutsideView() throws Exception { + String use = "use dfs.tmp;"; + String selectInto = "create table monkey as select c_custkey, c_regionkey from cp.`tpch/customer.parquet`"; + String createView = "create view myMonkeyView as select c_custkey, c_regionkey from monkey"; + String selectInside = "select * from myMonkeyView;"; + String use2 = "use cp;"; + String selectOutside = "select * from dfs.tmp.myMonkeyView;"; + + test(use); + test(selectInto); + test(createView); + test(selectInside); + test(use2); + test(selectOutside); + } + + +}
