You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by ma...@apache.org on 2017/03/09 19:44:39 UTC
calcite git commit: [CALCITE-1675] Two-level column name cannot be
resolved in ORDER BY
Repository: calcite
Updated Branches:
refs/heads/master a56b84e3b -> 55d7c6d80
[CALCITE-1675] Two-level column name cannot be resolved in ORDER BY
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/55d7c6d8
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/55d7c6d8
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/55d7c6d8
Branch: refs/heads/master
Commit: 55d7c6d80faf8a4b1b54bbde41b79064f1e36466
Parents: a56b84e
Author: maryannxue <ma...@gmail.com>
Authored: Thu Mar 9 11:44:25 2017 -0800
Committer: maryannxue <ma...@gmail.com>
Committed: Thu Mar 9 11:44:25 2017 -0800
----------------------------------------------------------------------
.../calcite/sql/validate/DelegatingScope.java | 8 +-----
.../apache/calcite/sql/validate/ListScope.java | 24 +++++++-----------
.../sql/validate/MatchRecognizeScope.java | 10 ++++++--
.../calcite/test/SqlToRelConverterTest.java | 10 ++++++++
.../calcite/test/SqlToRelConverterTest.xml | 26 ++++++++++++++++++++
5 files changed, 54 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/55d7c6d8/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java
index 0ec59a7..eed7d6f 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java
@@ -34,7 +34,6 @@ import org.apache.calcite.util.Pair;
import org.apache.calcite.util.Util;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Collection;
@@ -180,11 +179,6 @@ public abstract class DelegatingScope implements SqlValidatorScope {
return parent.findQualifyingTableName(columnName, ctx);
}
- protected Map<String, ScopeChild> findQualifyingTables(String columnName,
- SqlNameMatcher nameMatcher) {
- return ImmutableMap.of();
- }
-
public Map<String, ScopeChild> findQualifyingTableNames(String columnName,
SqlNode ctx, SqlNameMatcher nameMatcher) {
return parent.findQualifyingTableNames(columnName, ctx, nameMatcher);
@@ -328,7 +322,7 @@ public abstract class DelegatingScope implements SqlValidatorScope {
// Look for a column not qualified by a table alias.
columnName = identifier.names.get(0);
final Map<String, ScopeChild> map =
- findQualifyingTables(columnName, nameMatcher);
+ findQualifyingTableNames(columnName, identifier, nameMatcher);
switch (map.size()) {
default:
final SqlIdentifier prefix1 = identifier.skipLast(1);
http://git-wip-us.apache.org/repos/asf/calcite/blob/55d7c6d8/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java b/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java
index e0f3427..3537e01 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java
@@ -132,10 +132,11 @@ public abstract class ListScope extends DelegatingScope {
findQualifyingTableName(final String columnName, SqlNode ctx) {
final SqlNameMatcher nameMatcher = validator.catalogReader.nameMatcher();
final Map<String, ScopeChild> map =
- findQualifyingTables(columnName, nameMatcher);
+ findQualifyingTableNames(columnName, ctx, nameMatcher);
switch (map.size()) {
case 0:
- return parent.findQualifyingTableName(columnName, ctx);
+ throw validator.newValidationError(ctx,
+ RESOURCE.columnNotFound(columnName));
case 1:
final Map.Entry<String, ScopeChild> entry =
map.entrySet().iterator().next();
@@ -149,18 +150,6 @@ public abstract class ListScope extends DelegatingScope {
@Override public Map<String, ScopeChild>
findQualifyingTableNames(String columnName, SqlNode ctx,
SqlNameMatcher nameMatcher) {
- final Map<String, ScopeChild> map =
- findQualifyingTables(columnName, nameMatcher);
- switch (map.size()) {
- case 0:
- return parent.findQualifyingTableNames(columnName, ctx, nameMatcher);
- default:
- return map;
- }
- }
-
- @Override public Map<String, ScopeChild>
- findQualifyingTables(String columnName, SqlNameMatcher nameMatcher) {
final Map<String, ScopeChild> map = new HashMap<>();
for (ScopeChild child : children) {
final ResolvedImpl resolved = new ResolvedImpl();
@@ -170,7 +159,12 @@ public abstract class ListScope extends DelegatingScope {
map.put(child.name, child);
}
}
- return map;
+ switch (map.size()) {
+ case 0:
+ return parent.findQualifyingTableNames(columnName, ctx, nameMatcher);
+ default:
+ return map;
+ }
}
@Override public void resolve(List<String> names, SqlNameMatcher nameMatcher,
http://git-wip-us.apache.org/repos/asf/calcite/blob/55d7c6d8/core/src/main/java/org/apache/calcite/sql/validate/MatchRecognizeScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/MatchRecognizeScope.java b/core/src/main/java/org/apache/calcite/sql/validate/MatchRecognizeScope.java
index 5050057..c0be246 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/MatchRecognizeScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/MatchRecognizeScope.java
@@ -65,7 +65,8 @@ public class MatchRecognizeScope extends ListScope {
}
@Override public Map<String, ScopeChild>
- findQualifyingTables(String columnName, SqlNameMatcher nameMatcher) {
+ findQualifyingTableNames(String columnName, SqlNode ctx,
+ SqlNameMatcher nameMatcher) {
final Map<String, ScopeChild> map = new HashMap<>();
for (ScopeChild child : children) {
final RelDataType rowType = child.namespace.getRowType();
@@ -73,7 +74,12 @@ public class MatchRecognizeScope extends ListScope {
map.put(STAR, child);
}
}
- return map;
+ switch (map.size()) {
+ case 0:
+ return parent.findQualifyingTableNames(columnName, ctx, nameMatcher);
+ default:
+ return map;
+ }
}
@Override public void resolve(List<String> names, SqlNameMatcher nameMatcher,
http://git-wip-us.apache.org/repos/asf/calcite/blob/55d7c6d8/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index 8bed9c3..d1200e6 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -1895,6 +1895,16 @@ public class SqlToRelConverterTest extends SqlToRelTestBase {
sql(sql).ok();
}
+ @Test public void testCustomColumnResolving4() {
+ final String sql = "select c1 from struct.t order by f0.c1";
+ sql(sql).ok();
+ }
+
+ @Test public void testCustomColumnResolving5() {
+ final String sql = "select count(c1) from struct.t group by f0.c1";
+ sql(sql).ok();
+ }
+
@Test public void testCustomColumnResolvingWithSelectStar() {
final String sql = "select * from struct.t";
sql(sql).ok();
http://git-wip-us.apache.org/repos/asf/calcite/blob/55d7c6d8/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index aa6f106..20c19bd 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -2846,6 +2846,32 @@ LogicalProject(C2=[$7])
]]>
</Resource>
</TestCase>
+ <TestCase name="testCustomColumnResolving4">
+ <Resource name="sql">
+ <![CDATA[select c1 from struct.t order by f0.c1]]>
+ </Resource>
+ <Resource name="plan">
+ <![CDATA[
+LogicalProject(C1=[$0])
+ LogicalSort(sort0=[$1], dir0=[ASC])
+ LogicalProject(C1=[$1], "F0"."C1"=[$6])
+ LogicalTableScan(table=[[CATALOG, STRUCT, T]])
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testCustomColumnResolving5">
+ <Resource name="sql">
+ <![CDATA[select count(c1) from struct.t group by f0.c1]]>
+ </Resource>
+ <Resource name="plan">
+ <![CDATA[
+LogicalProject(EXPR$0=[$1])
+ LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
+ LogicalProject("F0"."C1"=[$6], "C1"=[$1])
+ LogicalTableScan(table=[[CATALOG, STRUCT, T]])
+]]>
+ </Resource>
+ </TestCase>
<TestCase name="testCustomColumnResolvingWithSelectStar">
<Resource name="sql">
<![CDATA[select * from struct.t]]>