You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2016/07/06 05:26:55 UTC
[2/3] calcite git commit: [CALCITE-1305] Case-insensitive table
aliases and GROUP BY
[CALCITE-1305] Case-insensitive table aliases and GROUP BY
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/787a9a1b
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/787a9a1b
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/787a9a1b
Branch: refs/heads/master
Commit: 787a9a1b19da84021d2a9090c6ff5972e999c6b3
Parents: 54d29dc
Author: Julian Hyde <jh...@apache.org>
Authored: Tue Jul 5 12:59:48 2016 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Tue Jul 5 17:38:38 2016 -0700
----------------------------------------------------------------------
.../sql/validate/AggregatingSelectScope.java | 1 -
.../calcite/sql/validate/DelegatingScope.java | 8 ++++++++
.../apache/calcite/sql/validate/WithScope.java | 3 ++-
.../apache/calcite/test/SqlValidatorTest.java | 19 +++++++++++++++++++
.../main/java/org/apache/calcite/piglet/Ast.java | 2 +-
5 files changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/787a9a1b/core/src/main/java/org/apache/calcite/sql/validate/AggregatingSelectScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/AggregatingSelectScope.java b/core/src/main/java/org/apache/calcite/sql/validate/AggregatingSelectScope.java
index cc884ee..29514ac 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/AggregatingSelectScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/AggregatingSelectScope.java
@@ -103,7 +103,6 @@ public class AggregatingSelectScope
// modifies it and makes it no longer equivalent. While copying,
// we fully qualify all identifiers.
final SqlNodeList groupList = select.getGroup();
-// SqlValidatorUtil.DeepCopier.copy(parent, select.getGroup());
for (SqlNode groupExpr : groupList) {
SqlValidatorUtil.analyzeGroupItem(this, temporaryGroupExprList,
groupExprProjection, builder, groupExpr);
http://git-wip-us.apache.org/repos/asf/calcite/blob/787a9a1b/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 383fd12..d48bb50 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
@@ -182,6 +182,14 @@ public abstract class DelegatingScope implements SqlValidatorScope {
final SqlIdentifier prefix = identifier.getComponent(0, i);
fromNs = resolve(prefix.names, null, null);
if (fromNs != null) {
+ if (fromNs.getEnclosingNode() != null) {
+ String alias =
+ SqlValidatorUtil.getAlias(fromNs.getEnclosingNode(), -1);
+ if (alias != null
+ && !alias.equals(identifier.names.get(i - 1))) {
+ identifier = identifier.setName(i - 1, alias);
+ }
+ }
break;
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/787a9a1b/core/src/main/java/org/apache/calcite/sql/validate/WithScope.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/WithScope.java b/core/src/main/java/org/apache/calcite/sql/validate/WithScope.java
index b650402..9141f83 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/WithScope.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/WithScope.java
@@ -56,7 +56,8 @@ class WithScope extends ListScope {
@Override public SqlValidatorNamespace resolve(List<String> names,
SqlValidatorScope[] ancestorOut,
int[] offsetOut) {
- if (names.equals(withItem.name.getSimple())) {
+ if (names.size() == 1
+ && names.get(0).equals(withItem.name.getSimple())) {
return validator.getNamespace(withItem);
}
return super.resolve(names, ancestorOut, offsetOut);
http://git-wip-us.apache.org/repos/asf/calcite/blob/787a9a1b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 5fcd47e..02e29c1 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -7347,6 +7347,25 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
"Duplicate relation name 'D' in FROM clause");
}
+ /** Test case for
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-1305">[CALCITE-1305]
+ * Case-insensitive table aliases and GROUP BY</a>. */
+ @Test public void testCaseInsensitiveTableAliasInGroupBy() {
+ final SqlTester tester1 = tester
+ .withCaseSensitive(false)
+ .withUnquotedCasing(Casing.UNCHANGED);
+ tester1.checkQuery("select deptno, count(*) from EMP AS emp\n"
+ + "group by eMp.deptno");
+ tester1.checkQuery("select deptno, count(*) from EMP AS EMP\n"
+ + "group by eMp.deptno");
+ tester1.checkQuery("select deptno, count(*) from EMP\n"
+ + "group by eMp.deptno");
+ tester1.checkQuery("select * from EMP where exists (\n"
+ + " select 1 from dept\n"
+ + " group by eMp.deptno)");
+ tester1.checkQuery("select deptno, count(*) from EMP group by DEPTNO");
+ }
+
/** Tests matching of built-in operator names. */
@Test public void testUnquotedBuiltInFunctionNames() {
final SqlTester mysql = tester
http://git-wip-us.apache.org/repos/asf/calcite/blob/787a9a1b/piglet/src/main/java/org/apache/calcite/piglet/Ast.java
----------------------------------------------------------------------
diff --git a/piglet/src/main/java/org/apache/calcite/piglet/Ast.java b/piglet/src/main/java/org/apache/calcite/piglet/Ast.java
index 6c70606..78d0c13 100644
--- a/piglet/src/main/java/org/apache/calcite/piglet/Ast.java
+++ b/piglet/src/main/java/org/apache/calcite/piglet/Ast.java
@@ -310,7 +310,7 @@ public class Ast {
* <p>Syntax:
* <blockquote>
* <code>alias = GROUP alias
- * ( ALL | BY ( exp | '(' exp [, exp]... ')' ) );</code>
+ * ( ALL | BY ( exp | '(' exp [, exp]... ')' ) )</code>
* </blockquote>
*/
public static class GroupStmt extends Assignment1 {