You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by vo...@apache.org on 2018/07/05 11:02:39 UTC
calcite git commit: [CALCITE-2392] Prevent columns permutation for
NATURAL JOIN and JOIN USING when dynamic table is used
Repository: calcite
Updated Branches:
refs/heads/master 625edb88e -> 5bbc501a5
[CALCITE-2392] Prevent columns permutation for NATURAL JOIN and JOIN USING when dynamic table is used
Close apache/calcite#752
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/5bbc501a
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/5bbc501a
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/5bbc501a
Branch: refs/heads/master
Commit: 5bbc501a565494442784f65870a20cd65a5016f4
Parents: 625edb8
Author: Volodymyr Vysotskyi <vv...@gmail.com>
Authored: Wed Jul 4 14:58:41 2018 +0300
Committer: Volodymyr Vysotskyi <vv...@gmail.com>
Committed: Thu Jul 5 13:37:22 2018 +0300
----------------------------------------------------------------------
.../apache/calcite/sql/validate/SqlValidatorImpl.java | 6 +++++-
core/src/main/java/org/apache/calcite/util/Bug.java | 6 ++++++
.../apache/calcite/test/SqlToRelConverterTest.java | 8 ++++++++
.../org/apache/calcite/test/SqlToRelConverterTest.xml | 14 ++++++++++++++
4 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/5bbc501a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index 61b7c82..0dd9308 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -474,9 +474,11 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
final SqlParserPos startPosition = identifier.getParserPosition();
switch (identifier.names.size()) {
case 1:
+ boolean hasDynamicStruct = false;
for (ScopeChild child : scope.children) {
final int before = fields.size();
if (child.namespace.getRowType().isDynamicStruct()) {
+ hasDynamicStruct = true;
// don't expand star if the underneath table is dynamic.
// Treat this star as a special field in validation/conversion and
// wait until execution time to expand this star.
@@ -532,7 +534,9 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
}
// If NATURAL JOIN or USING is present, move key fields to the front of
// the list.
- new Permute(scope.getNode().getFrom(), 0).permute(selectItems, fields);
+ if (!hasDynamicStruct || Bug.CALCITE_2400_FIXED) {
+ new Permute(scope.getNode().getFrom(), 0).permute(selectItems, fields);
+ }
return true;
default:
http://git-wip-us.apache.org/repos/asf/calcite/blob/5bbc501a/core/src/main/java/org/apache/calcite/util/Bug.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/Bug.java b/core/src/main/java/org/apache/calcite/util/Bug.java
index e5d7096..ed2d0d1 100644
--- a/core/src/main/java/org/apache/calcite/util/Bug.java
+++ b/core/src/main/java/org/apache/calcite/util/Bug.java
@@ -168,6 +168,12 @@ public abstract class Bug {
* Decorrelate sub-queries in Project and Join</a> is fixed. */
public static final boolean CALCITE_1045_FIXED = false;
+ /** Whether
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-2400">[CALCITE-2400]
+ * Allow standards-compliant column ordering for NATURAL JOIN and JOIN USING
+ * when dynamic tables are used</a> is fixed. */
+ public static final boolean CALCITE_2400_FIXED = false;
+
/**
* Use this to flag temporary code.
*/
http://git-wip-us.apache.org/repos/asf/calcite/blob/5bbc501a/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 a48a791..4a1f2e6 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -114,6 +114,14 @@ public class SqlToRelConverterTest extends SqlToRelTestBase {
sql(sql).ok();
}
+ @Test
+ public void testJoinUsingDynamicTable() {
+ final String sql = "select * from SALES.NATION t1\n"
+ + "join SALES.NATION t2\n"
+ + "using (n_nationkey)";
+ sql(sql).with(getTesterWithDynamicTable()).ok();
+ }
+
/**
* Tests that AND(x, AND(y, z)) gets flattened to AND(x, y, z).
*/
http://git-wip-us.apache.org/repos/asf/calcite/blob/5bbc501a/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 713c2cf..af280e1 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -1608,6 +1608,20 @@ LogicalSort(offset=[?0])
]]>
</Resource>
</TestCase>
+ <TestCase name="testJoinUsingDynamicTable">
+ <Resource name="sql">
+ <![CDATA[select * from SALES.NATION t1
+join SALES.NATION t2 using (n_nationkey)]]>
+ </Resource>
+ <Resource name="plan">
+ <![CDATA[
+LogicalProject(**=[$1], **0=[$3])
+ LogicalJoin(condition=[=($0, $2)], joinType=[inner])
+ LogicalTableScan(table=[[CATALOG, SALES, NATION]])
+ LogicalTableScan(table=[[CATALOG, SALES, NATION]])
+]]>
+ </Resource>
+ </TestCase>
<TestCase name="testMultiAnd">
<Resource name="sql">
<![CDATA[select * from emp