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/12/14 16:42:44 UTC
[1/3] calcite git commit: [CALCITE-1493] Wrong plan for NOT IN
correlated queries
Repository: calcite
Updated Branches:
refs/heads/master 9535efb6c -> e38d51e8f
[CALCITE-1493] Wrong plan for NOT IN correlated queries
The problem was that RelBuilder.join for correlations needed to add
the filter below the right-hand input.
Additional fix due to Vineet Garg.
Also added a few more RelBuilder methods, and a test case for
[CALCITE-1513] Correlated NOT IN query throws AssertionError.
Improve deduction of nullability of NOT NOT EXISTS.
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/1ccebc89
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/1ccebc89
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/1ccebc89
Branch: refs/heads/master
Commit: 1ccebc89befa93a0bf2a4d98cf35b2558a37f6d4
Parents: 9535efb
Author: Julian Hyde <jh...@apache.org>
Authored: Wed Nov 30 11:57:20 2016 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Tue Dec 13 17:18:52 2016 -0800
----------------------------------------------------------------------
.../org/apache/calcite/plan/RelOptUtil.java | 27 +++++++-
.../calcite/rel/rules/SubQueryRemoveRule.java | 24 +++----
.../org/apache/calcite/rex/LogicVisitor.java | 15 ++++-
.../apache/calcite/sql2rel/RelDecorrelator.java | 20 ++++--
.../org/apache/calcite/tools/RelBuilder.java | 63 ++++++++++++++++--
.../org/apache/calcite/test/RelBuilderTest.java | 42 +++++++++---
.../apache/calcite/test/RelOptRulesTest.java | 3 +-
.../apache/calcite/test/RexTransformerTest.java | 2 +
.../org/apache/calcite/test/RelOptRulesTest.xml | 31 +++++++--
core/src/test/resources/sql/blank.iq | 59 +++++++++++++++++
core/src/test/resources/sql/subquery.iq | 68 ++++++++++++++++++++
site/_docs/algebra.md | 13 +++-
12 files changed, 318 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
index 7d50d52..b03c544 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
@@ -58,6 +58,7 @@ import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.rel.type.RelDataTypeFieldImpl;
import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rex.LogicVisitor;
import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.rex.RexCall;
import org.apache.calcite.rex.RexCorrelVariable;
@@ -3038,7 +3039,14 @@ public abstract class RelOptUtil {
/** A semi-join will have been applied, so that only rows for which the
* value is TRUE will have been returned. */
- TRUE;
+ TRUE,
+
+ /** An anti-semi-join will have been applied, so that only rows for which
+ * the value is FALSE will have been returned.
+ *
+ * <p>Currently only used within {@link LogicVisitor}, to ensure that
+ * 'NOT (NOT EXISTS (q))' behaves the same as 'EXISTS (q)') */
+ FALSE;
public Logic negate() {
switch (this) {
@@ -3051,6 +3059,23 @@ public abstract class RelOptUtil {
return this;
}
}
+
+ /** Variant of {@link #negate()} to be used within {@link LogicVisitor},
+ * where FALSE values may exist. */
+ public Logic negate2() {
+ switch (this) {
+ case FALSE:
+ return TRUE;
+ case TRUE:
+ return FALSE;
+ case UNKNOWN_AS_FALSE:
+ return UNKNOWN_AS_TRUE;
+ case UNKNOWN_AS_TRUE:
+ return UNKNOWN_AS_FALSE;
+ default:
+ return this;
+ }
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java b/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java
index 6eec2fc..f0779d9 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java
@@ -36,6 +36,7 @@ import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexShuttle;
import org.apache.calcite.rex.RexSubQuery;
import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql2rel.RelDecorrelator;
import org.apache.calcite.tools.RelBuilder;
@@ -225,20 +226,9 @@ public abstract class SubQueryRemoveRule extends RelOptRule {
switch (logic) {
case TRUE_FALSE_UNKNOWN:
case UNKNOWN_AS_TRUE:
- if (!variablesSet.isEmpty()) {
- // We have not yet figured out how to include "ct" in a query if
- // the source relation "e.rel" is correlated. So, dodge the issue:
- // we pretend that the join key is NOT NULL.
- //
- // We will get wrong results in correlated IN where the join
- // key has nulls. E.g.
- //
- // SELECT *
- // FROM emp
- // WHERE mgr NOT IN (
- // SELECT mgr
- // FROM emp AS e2
- // WHERE
+ // Since EXISTS/NOT EXISTS are not affected by presence of
+ // null keys we do not need to generate count(*), count(c)
+ if (e.getKind() == SqlKind.EXISTS) {
logic = RelOptUtil.Logic.TRUE_FALSE;
break;
}
@@ -247,7 +237,11 @@ public abstract class SubQueryRemoveRule extends RelOptRule {
builder.aggregateCall(SqlStdOperatorTable.COUNT, false, null, "ck",
builder.fields()));
builder.as("ct");
- builder.join(JoinRelType.INNER, builder.literal(true), variablesSet);
+ if (!variablesSet.isEmpty()) {
+ builder.join(JoinRelType.LEFT, builder.literal(true), variablesSet);
+ } else {
+ builder.join(JoinRelType.INNER, builder.literal(true), variablesSet);
+ }
offset += 2;
builder.push(e.rel);
break;
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/core/src/main/java/org/apache/calcite/rex/LogicVisitor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/LogicVisitor.java b/core/src/main/java/org/apache/calcite/rex/LogicVisitor.java
index 610a004..14220df 100644
--- a/core/src/main/java/org/apache/calcite/rex/LogicVisitor.java
+++ b/core/src/main/java/org/apache/calcite/rex/LogicVisitor.java
@@ -21,6 +21,7 @@ import org.apache.calcite.plan.RelOptUtil.Logic;
import com.google.common.collect.Iterables;
import java.util.Collection;
+import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
@@ -53,6 +54,11 @@ public class LogicVisitor implements RexBiVisitor<Logic, Logic> {
for (RexNode node : nodes) {
node.accept(visitor, logic);
}
+ // Convert FALSE (which can only exist within LogicVisitor) to
+ // UNKNOWN_AS_TRUE.
+ if (set.remove(Logic.FALSE)) {
+ set.add(Logic.UNKNOWN_AS_TRUE);
+ }
switch (set.size()) {
case 0:
throw new IllegalArgumentException("not found: " + seek);
@@ -64,8 +70,11 @@ public class LogicVisitor implements RexBiVisitor<Logic, Logic> {
}
public static void collect(RexNode node, RexNode seek, Logic logic,
- Collection<Logic> logicCollection) {
- node.accept(new LogicVisitor(seek, logicCollection), logic);
+ List<Logic> logicList) {
+ node.accept(new LogicVisitor(seek, logicList), logic);
+ // Convert FALSE (which can only exist within LogicVisitor) to
+ // UNKNOWN_AS_TRUE.
+ Collections.replaceAll(logicList, Logic.FALSE, Logic.UNKNOWN_AS_TRUE);
}
public Logic visitCall(RexCall call, Logic logic) {
@@ -84,7 +93,7 @@ public class LogicVisitor implements RexBiVisitor<Logic, Logic> {
logic = Logic.UNKNOWN_AS_TRUE;
break;
case NOT:
- logic = logic.negate();
+ logic = logic.negate2();
break;
case CASE:
logic = Logic.TRUE_FALSE_UNKNOWN;
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
index a705543..5f8f8c5 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
@@ -2531,12 +2531,20 @@ public class RelDecorrelator implements ReflectiveVisitor {
final RexNode ref = fieldAccess.getReferenceExpr();
if (ref instanceof RexCorrelVariable) {
final RexCorrelVariable var = (RexCorrelVariable) ref;
- final Correlation correlation =
- new Correlation(var.id,
- fieldAccess.getField().getIndex(),
- corrIdGenerator++);
- mapFieldAccessToCorVar.put(fieldAccess, correlation);
- mapRefRelToCorVar.put(rel, correlation);
+ if (mapFieldAccessToCorVar.containsKey(fieldAccess)) {
+ //for cases where different Rel nodes are referring to
+ // same correlation var (e.g. in case of NOT IN)
+ // avoid generating another correlation var
+ // and record the 'rel' is using the same correlation
+ mapRefRelToCorVar.put(rel, mapFieldAccessToCorVar.get(fieldAccess));
+ } else {
+ final Correlation correlation =
+ new Correlation(var.id,
+ fieldAccess.getField().getIndex(),
+ corrIdGenerator++);
+ mapFieldAccessToCorVar.put(fieldAccess, correlation);
+ mapRefRelToCorVar.put(rel, correlation);
+ }
}
return super.visitFieldAccess(fieldAccess);
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
index c70725d..f83da05 100644
--- a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
+++ b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
@@ -41,9 +41,11 @@ import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexCorrelVariable;
import org.apache.calcite.rex.RexInputRef;
import org.apache.calcite.rex.RexLiteral;
import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexShuttle;
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.runtime.Hook;
import org.apache.calcite.schema.SchemaPlus;
@@ -56,6 +58,7 @@ import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.sql.validate.SqlValidatorUtil;
import org.apache.calcite.util.CompositeList;
+import org.apache.calcite.util.Holder;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.ImmutableIntList;
import org.apache.calcite.util.Litmus;
@@ -306,6 +309,15 @@ public class RelBuilder {
}
}
+ /** Creates a correlation variable for the current input, and writes it into
+ * a Holder. */
+ public RelBuilder variable(Holder<RexCorrelVariable> v) {
+ v.set((RexCorrelVariable)
+ getRexBuilder().makeCorrel(peek().getRowType(),
+ cluster.createCorrel()));
+ return this;
+ }
+
/** Creates a reference to a field by name.
*
* <p>Equivalent to {@code field(1, 0, fieldName)}.
@@ -417,6 +429,11 @@ public class RelBuilder {
+ "'; aliases are: " + aliases);
}
+ /** Returns a reference to a given field of a record-valued expression. */
+ public RexNode field(RexNode e, String name) {
+ return getRexBuilder().makeFieldAccess(e, name, false);
+ }
+
/** Returns references to the fields of the top input. */
public ImmutableList<RexNode> fields() {
return fields(1, 0);
@@ -1121,10 +1138,11 @@ public class RelBuilder {
* variables. */
public RelBuilder join(JoinRelType joinType, RexNode condition,
Set<CorrelationId> variablesSet) {
- final Frame right = stack.pop();
+ Frame right = stack.pop();
final Frame left = stack.pop();
final RelNode join;
final boolean correlate = variablesSet.size() == 1;
+ RexNode postCondition = literal(true);
if (correlate) {
final CorrelationId id = Iterables.getOnlyElement(variablesSet);
final ImmutableBitSet requiredColumns =
@@ -1133,6 +1151,18 @@ public class RelBuilder {
throw new IllegalArgumentException("variable " + id
+ " must not be used by left input to correlation");
}
+ switch (joinType) {
+ case LEFT:
+ // Correlate does not have an ON clause.
+ // For a LEFT correlate, predicate must be evaluated first.
+ // For INNER, we can defer.
+ stack.push(right);
+ filter(condition.accept(new Shifter(left.rel, id, right.rel)));
+ right = stack.pop();
+ break;
+ default:
+ postCondition = condition;
+ }
join = correlateFactory.createCorrelate(left.rel, right.rel, id,
requiredColumns, SemiJoinType.of(joinType));
} else {
@@ -1143,9 +1173,7 @@ public class RelBuilder {
pairs.addAll(left.right);
pairs.addAll(right.right);
stack.push(new Frame(join, ImmutableList.copyOf(pairs)));
- if (correlate) {
- filter(condition);
- }
+ filter(postCondition);
return this;
}
@@ -1647,6 +1675,33 @@ public class RelBuilder {
return CompositeList.ofCopy(Iterables.transform(right, FN));
}
}
+
+ /** Shuttle that shifts a predicate's inputs to the left, replacing early
+ * ones with references to a
+ * {@link org.apache.calcite.rex.RexCorrelVariable}. */
+ private class Shifter extends RexShuttle {
+ private final RelNode left;
+ private final CorrelationId id;
+ private final RelNode right;
+
+ Shifter(RelNode left, CorrelationId id, RelNode right) {
+ this.left = left;
+ this.id = id;
+ this.right = right;
+ }
+
+ public RexNode visitInputRef(RexInputRef inputRef) {
+ final RelDataType leftRowType = left.getRowType();
+ final RexBuilder rexBuilder = getRexBuilder();
+ final int leftCount = leftRowType.getFieldCount();
+ if (inputRef.getIndex() < leftCount) {
+ final RexNode v = rexBuilder.makeCorrel(leftRowType, id);
+ return rexBuilder.makeFieldAccess(v, inputRef.getIndex());
+ } else {
+ return rexBuilder.makeInputRef(right, inputRef.getIndex() - leftCount);
+ }
+ }
+ }
}
// End RelBuilder.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
index a19947a..6c0b99e 100644
--- a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
@@ -16,13 +16,11 @@
*/
package org.apache.calcite.test;
-import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.plan.RelTraitDef;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.AggregateCall;
import org.apache.calcite.rel.core.Correlate;
-import org.apache.calcite.rel.core.CorrelationId;
import org.apache.calcite.rel.core.Exchange;
import org.apache.calcite.rel.core.JoinRelType;
import org.apache.calcite.rel.core.TableFunctionScan;
@@ -30,6 +28,7 @@ import org.apache.calcite.rel.core.TableModify;
import org.apache.calcite.rel.core.Window;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexCorrelVariable;
import org.apache.calcite.rex.RexInputRef;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.runtime.CalciteException;
@@ -41,6 +40,7 @@ import org.apache.calcite.tools.Frameworks;
import org.apache.calcite.tools.Programs;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.tools.RelRunners;
+import org.apache.calcite.util.Holder;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Util;
import org.apache.calcite.util.mapping.Mappings;
@@ -959,15 +959,14 @@ public class RelBuilderTest {
@Test public void testCorrelationFails() {
final RelBuilder builder = RelBuilder.create(config().build());
- builder.scan("EMP");
- final RelOptCluster cluster = builder.peek().getCluster();
- final CorrelationId id = cluster.createCorrel();
- final RexNode v =
- builder.getRexBuilder().makeCorrel(builder.peek().getRowType(), id);
+ final Holder<RexCorrelVariable> v = Holder.of(null);
try {
- builder.filter(builder.equals(builder.field(0), v))
+ builder.scan("EMP")
+ .variable(v)
+ .filter(builder.equals(builder.field(0), v.get()))
.scan("DEPT")
- .join(JoinRelType.INNER, builder.literal(true), ImmutableSet.of(id));
+ .join(JoinRelType.INNER, builder.literal(true),
+ ImmutableSet.of(v.get().id));
fail("expected error");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(),
@@ -975,6 +974,31 @@ public class RelBuilderTest {
}
}
+ @Test public void testCorrelationWithCondition() {
+ final RelBuilder builder = RelBuilder.create(config().build());
+ final Holder<RexCorrelVariable> v = Holder.of(null);
+ RelNode root = builder.scan("EMP")
+ .variable(v)
+ .scan("DEPT")
+ .filter(
+ builder.equals(builder.field(0),
+ builder.field(v.get(), "DEPTNO")))
+ .join(JoinRelType.LEFT,
+ builder.equals(builder.field(2, 0, "SAL"),
+ builder.literal(1000)),
+ ImmutableSet.of(v.get().id))
+ .build();
+ // Note that the join filter gets pushed to the right-hand input of
+ // LogicalCorrelate
+ final String expected = ""
+ + "LogicalCorrelate(correlation=[$cor0], joinType=[LEFT], requiredColumns=[{7}])\n"
+ + " LogicalTableScan(table=[[scott, EMP]])\n"
+ + " LogicalFilter(condition=[=($cor0.SAL, 1000)])\n"
+ + " LogicalFilter(condition=[=($0, $cor0.DEPTNO)])\n"
+ + " LogicalTableScan(table=[[scott, DEPT]])\n";
+ assertThat(str(root), is(expected));
+ }
+
@Test public void testAlias() {
// Equivalent SQL:
// SELECT *
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index 018a857..2749b7f 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -2749,13 +2749,12 @@ public class RelOptRulesTest extends RelOptTestBase {
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1493">[CALCITE-1493]
* Wrong plan for NOT IN correlated queries</a>. */
- @Ignore("[CALCITE-1493] is not fixed yet")
@Test public void testWhereNotInCorrelated() {
final String sql = "select sal from emp\n"
+ "where empno NOT IN (\n"
+ " select deptno from dept\n"
+ " where emp.job = dept.name)";
- checkSubQuery(sql).withLateDecorrelation(false).check();
+ checkSubQuery(sql).withLateDecorrelation(true).check();
}
@Test public void testExpandProjectIn() throws Exception {
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java b/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java
index fce70c1..9837f91 100644
--- a/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RexTransformerTest.java
@@ -398,6 +398,8 @@ public class RexTransformerTest {
assertThat(deduceLogic(and(x, not(y)), x, Logic.TRUE), is(Logic.TRUE));
assertThat(deduceLogic(and(x, not(y)), y, Logic.TRUE),
is(Logic.UNKNOWN_AS_TRUE));
+ assertThat(deduceLogic(and(x, not(not(y))), y, Logic.TRUE),
+ is(Logic.TRUE_FALSE));
assertThat(deduceLogic(and(x, not(and(y, z))), z, Logic.TRUE),
is(Logic.UNKNOWN_AS_TRUE));
assertThat(deduceLogic(or(x, y), x, Logic.TRUE), is(Logic.TRUE_FALSE));
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index 1acd8b0..e2fd58e 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -6348,15 +6348,32 @@ LogicalProject(DEPTNO=[$0])
<![CDATA[
LogicalProject(SAL=[$5])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
- LogicalFilter(condition=[IS NULL($10)])
- LogicalFilter(condition=[=($0, $9)])
- LogicalCorrelate(correlation=[$cor0], joinType=[LEFT], requiredColumns=[{2}])
+ LogicalFilter(condition=[NOT(CASE(=($10, 0), false, IS NOT NULL($14), true, <($11, $10), true, false))])
+ LogicalJoin(condition=[AND(=($0, $15), =($2, $13))], joinType=[left])
+ LogicalJoin(condition=[=($2, $9)], joinType=[left])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
- LogicalAggregate(group=[{0, 1}])
- LogicalProject(DEPTNO=[$0], i=[true])
- LogicalProject(DEPTNO=[$0])
- LogicalFilter(condition=[=($cor0.JOB, $1)])
+ LogicalAggregate(group=[{0}], c=[COUNT()], ck=[COUNT($1)])
+ LogicalProject(JOB=[$1], DEPTNO=[$0])
+ LogicalProject(DEPTNO=[$0], JOB=[$2])
+ LogicalJoin(condition=[=($2, $1)], joinType=[inner])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalAggregate(group=[{0}])
+ LogicalProject(JOB=[$2])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalJoin(condition=[=($3, $0)], joinType=[inner])
+ LogicalProject(DEPTNO=[$0], JOB=[$1], $f2=[true])
+ LogicalAggregate(group=[{0, 1}])
+ LogicalProject(DEPTNO=[$0], JOB=[$2], i=[$1])
+ LogicalProject(DEPTNO=[$0], i=[true], JOB=[$1])
+ LogicalProject(DEPTNO=[$0], JOB=[$2])
+ LogicalJoin(condition=[=($2, $1)], joinType=[inner])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
+ LogicalAggregate(group=[{0}])
+ LogicalProject(JOB=[$2])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalAggregate(group=[{0}])
+ LogicalProject(EMPNO=[$0])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/core/src/test/resources/sql/blank.iq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/blank.iq b/core/src/test/resources/sql/blank.iq
index e2ce690..c157006 100644
--- a/core/src/test/resources/sql/blank.iq
+++ b/core/src/test/resources/sql/blank.iq
@@ -41,4 +41,63 @@ select * from foo;
!ok
+# Correlated non-equi IN
+select * from foo as f where i in (
+ select j from foo where i > f.i);
++---+---+
+| I | J |
++---+---+
+| 0 | 2 |
++---+---+
+(1 row)
+
+!ok
+
+# [CALCITE-1493] Wrong plan for NOT IN correlated queries
+create table table1(i int, j int);
+(-1 rows modified)
+
+!update
+create table table2(i int, j int);
+(-1 rows modified)
+
+!update
+insert into table1 values (1, 2), (1, 3);
+(2 rows modified)
+
+!update
+insert into table2 values (NULL, 1), (2, 1);
+(2 rows modified)
+
+!update
+# Checked on Oracle
+!set lateDecorrelate true
+select i, j from table1 where table1.j NOT IN (select i from table2 where table1.i=table2.j);
+EnumerableCalc(expr#0..8=[{inputs}], expr#9=[0], expr#10=[=($t3, $t9)], expr#11=[false], expr#12=[IS NOT NULL($t7)], expr#13=[true], expr#14=[IS NULL($t1)], expr#15=[null], expr#16=[<($t4, $t3)], expr#17=[CASE($t10, $t11, $t12, $t13, $t14, $t15, $t16, $t13, $t11)], expr#18=[NOT($t17)], proj#0..1=[{exprs}], $condition=[$t18])
+ EnumerableJoin(condition=[AND(=($0, $6), =($1, $8))], joinType=[left])
+ EnumerableJoin(condition=[=($0, $2)], joinType=[left])
+ EnumerableTableScan(table=[[BLANK, TABLE1]])
+ EnumerableAggregate(group=[{0}], c=[COUNT()], ck=[COUNT($1)])
+ EnumerableJoin(condition=[=($0, $2)], joinType=[inner])
+ EnumerableAggregate(group=[{0}])
+ EnumerableTableScan(table=[[BLANK, TABLE1]])
+ EnumerableTableScan(table=[[BLANK, TABLE2]])
+ EnumerableJoin(condition=[=($0, $3)], joinType=[inner])
+ EnumerableCalc(expr#0..1=[{inputs}], expr#2=[true], I=[$t1], I0=[$t0], $f2=[$t2])
+ EnumerableAggregate(group=[{0, 1}])
+ EnumerableJoin(condition=[=($0, $2)], joinType=[inner])
+ EnumerableAggregate(group=[{0}])
+ EnumerableTableScan(table=[[BLANK, TABLE1]])
+ EnumerableTableScan(table=[[BLANK, TABLE2]])
+ EnumerableAggregate(group=[{1}])
+ EnumerableTableScan(table=[[BLANK, TABLE1]])
+!plan
++---+---+
+| I | J |
++---+---+
++---+---+
+(0 rows)
+
+!ok
+
# End blank.iq
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/core/src/test/resources/sql/subquery.iq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/subquery.iq b/core/src/test/resources/sql/subquery.iq
index ad71655..73ee2f9 100644
--- a/core/src/test/resources/sql/subquery.iq
+++ b/core/src/test/resources/sql/subquery.iq
@@ -370,6 +370,74 @@ where e.job not in (
!plan
!}
+# Condition that returns a NULL key.
+# Tested on Oracle.
+select count(*) as c
+from "scott".emp
+where sal + 100 not in (
+ select comm
+ from "scott".emp);
++---+
+| C |
++---+
+| 0 |
++---+
+(1 row)
+
+!ok
+
+# Condition that happens to eliminate all NULL keys.
+# The one missing row has {ename: 'MARTIN', comm: 1400}
+# Tested on Oracle.
+select count(*) as c
+from "scott".emp
+where sal + 100 not in (
+ select comm from "scott".emp
+ where job = 'SALESMAN');
++----+
+| C |
++----+
+| 13 |
++----+
+(1 row)
+
+!ok
+
+# Condition that provably eliminates all NULL keys.
+# Tested on Oracle.
+select count(*) as c
+from "scott".emp
+where sal + 100 not in (
+ select comm
+ from "scott".emp
+ where comm < 1000);
++----+
+| C |
++----+
+| 14 |
++----+
+(1 row)
+
+!ok
+
+# Correlated condition in NOT IN.
+# Tested on Oracle.
+!if (fixed.calcite1513) {
+select count(*) as c
+from "scott".emp as e
+where sal + 100 not in (
+ select comm
+ from "scott".emp
+ where job = e.job);
+ EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
+---------- ---------- --------- ---------- --------- ---------- ---------- ----------
+ 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
+ 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
+ 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
+ 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
+!ok
+!}
+
# [CALCITE-864] Correlation variable has incorrect row type if it is populated
# by right side of a Join
select *
http://git-wip-us.apache.org/repos/asf/calcite/blob/1ccebc89/site/_docs/algebra.md
----------------------------------------------------------------------
diff --git a/site/_docs/algebra.md b/site/_docs/algebra.md
index 49d1631..490ca4f 100644
--- a/site/_docs/algebra.md
+++ b/site/_docs/algebra.md
@@ -274,7 +274,6 @@ return the `RelBuilder`.
| `union(all [, n])` | Creates a [Union]({{ site.apiRoot }}/org/apache/calcite/rel/core/Union.html) of the `n` (default two) most recent relational expressions.
| `intersect(all [, n])` | Creates an [Intersect]({{ site.apiRoot }}/org/apache/calcite/rel/core/Intersect.html) of the `n` (default two) most recent relational expressions.
| `minus(all)` | Creates a [Minus]({{ site.apiRoot }}/org/apache/calcite/rel/core/Minus.html) of the two most recent relational expressions.
-| `as(alias)` | Assigns the given alias to the top-most relational expression.
Argument types:
@@ -295,6 +294,7 @@ Argument types:
* `all` boolean
* `distinct` boolean
* `alias` String
+* `varHolder` [Holder]({{ site.apiRoot }}/org/apache/calcite/util/Holder.html) of [RexCorrelVariable]({{ site.apiRoot }}/org/apache/calcite/rex/RexCorrelVariable.html)
The builder methods perform various optimizations, including:
* `project` returns its input if asked to project all columns in order
@@ -302,8 +302,15 @@ The builder methods perform various optimizations, including:
simplifies (converting say `x = 1 AND TRUE` to `x = 1`)
* If you apply `sort` then `limit`, the effect is as if you had called `sortLimit`
-### Stack methods
+There are annotation methods that add information to the top relational
+expression on the stack:
+| Method | Description
+|:------------------- |:-----------
+| `as(alias)` | Assigns a table alias to the top relational expression on the stack
+| `variable(varHolder)` | Creates a correlation variable referencing the top relational expression
+
+### Stack methods
| Method | Description
|:------------------- |:-----------
@@ -330,6 +337,8 @@ added to the stack.
| `field(inputCount, inputOrdinal, fieldOrdinal)` | Reference, by ordinal, to a field of the (`inputCount` - `inputOrdinal`)th relational expression
| `field(inputCount, alias, fieldName)` | Reference, by table alias and field name, to a field at most `inputCount - 1` elements from the top of the stack
| `field(alias, fieldName)` | Reference, by table alias and field name, to a field of the top-most relational expressions
+| `field(expr, fieldName)` | Reference, by name, to a field of a record-valued expression
+| `field(expr, fieldOrdinal)` | Reference, by ordinal, to a field of a record-valued expression
| `fields(fieldOrdinalList)` | List of expressions referencing input fields by ordinal
| `fields(mapping)` | List of expressions referencing input fields by a given mapping
| `fields(collation)` | List of expressions, `exprList`, such that `sort(exprList)` would replicate collation
[2/3] calcite git commit: [CALCITE-1519] Standardize on "sub-query"
rather than "subquery" in class names and comments
Posted by jh...@apache.org.
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql2rel/SubqueryConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SubqueryConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SubqueryConverter.java
deleted file mode 100644
index 6145619..0000000
--- a/core/src/main/java/org/apache/calcite/sql2rel/SubqueryConverter.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.calcite.sql2rel;
-
-import org.apache.calcite.rex.RexNode;
-import org.apache.calcite.sql.SqlCall;
-
-/**
- * SubqueryConverter provides the interface for classes that convert subqueries
- * into equivalent expressions.
- */
-public interface SubqueryConverter {
- //~ Methods ----------------------------------------------------------------
-
- /**
- * @return true if the subquery can be converted
- */
- boolean canConvertSubquery();
-
- /**
- * Converts the subquery to an equivalent expression.
- *
- * @param subquery the SqlNode tree corresponding to a subquery
- * @param parentConverter sqlToRelConverter of the parent query
- * @param isExists whether the subquery is part of an EXISTS expression
- * @param isExplain whether the subquery is part of an EXPLAIN PLAN
- * statement
- * @return the equivalent expression or null if the subquery couldn't be
- * converted
- */
- RexNode convertSubquery(
- SqlCall subquery,
- SqlToRelConverter parentConverter,
- boolean isExists,
- boolean isExplain);
-}
-
-// End SubqueryConverter.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/tools/Programs.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/tools/Programs.java b/core/src/main/java/org/apache/calcite/tools/Programs.java
index 5f2f098..6bf65e4 100644
--- a/core/src/main/java/org/apache/calcite/tools/Programs.java
+++ b/core/src/main/java/org/apache/calcite/tools/Programs.java
@@ -106,7 +106,7 @@ public class Programs {
/** Program that expands sub-queries. */
public static final Program SUB_QUERY_PROGRAM =
- subquery(DefaultRelMetadataProvider.INSTANCE);
+ subQuery(DefaultRelMetadataProvider.INSTANCE);
public static final ImmutableSet<RelOptRule> RULE_SET =
ImmutableSet.of(
@@ -261,7 +261,12 @@ public class Programs {
return hep(CALC_RULES, true, metadataProvider);
}
+ @Deprecated // to be removed before 2.0
public static Program subquery(RelMetadataProvider metadataProvider) {
+ return subQuery(metadataProvider);
+ }
+
+ public static Program subQuery(RelMetadataProvider metadataProvider) {
return hep(
ImmutableList.of((RelOptRule) SubQueryRemoveRule.FILTER,
SubQueryRemoveRule.PROJECT,
@@ -303,7 +308,7 @@ public class Programs {
}
};
- return sequence(subquery(metadataProvider),
+ return sequence(subQuery(metadataProvider),
new DecorrelateProgram(),
new TrimFieldsProgram(),
program1,
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
----------------------------------------------------------------------
diff --git a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
index 741ef7f..5a278b6 100644
--- a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
+++ b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
@@ -140,7 +140,7 @@ DuplicateArgumentName=Duplicate argument name ''{0}''
DefaultForOptionalParameter=DEFAULT is only allowed for optional parameters
AccessNotAllowed=Not allowed to perform {0} on {1}
MinMaxBadType=The {0} function does not support the {1} data type.
-OnlyScalarSubqueryAllowed=Only scalar subqueries allowed in select list.
+OnlyScalarSubQueryAllowed=Only scalar sub-queries allowed in select list.
OrderByOrdinalOutOfRange=Ordinal out of range
WindowHasNegativeSize=Window has negative size
UnboundedFollowingWindowNotSupported=UNBOUNDED FOLLOWING window not supported
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
index e7a90a1..b8c0ed7 100644
--- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -1281,7 +1281,7 @@ public class SqlParserTest {
"values a similar to b like c similar to d escape e escape f",
"VALUES (ROW((`A` SIMILAR TO (`B` LIKE (`C` SIMILAR TO `D` ESCAPE `E`) ESCAPE `F`))))");
- // SIMILAR TO with subquery
+ // SIMILAR TO with sub-query
check(
"values a similar to (select * from t where a like b escape c) escape d",
"VALUES (ROW((`A` SIMILAR TO (SELECT *\n"
@@ -1601,7 +1601,7 @@ public class SqlParserTest {
"(?s)Encountered \"with\" at .*");
}
- @Test public void testWithNestedInSubquery() {
+ @Test public void testWithNestedInSubQuery() {
// SQL standard does not allow sub-query to contain WITH but we do
check("with emp2 as (select * from emp)\n"
+ "(\n"
@@ -1956,7 +1956,7 @@ public class SqlParserTest {
+ "WHERE (3 = 3)");
}
- @Test public void testSubqueryInJoin() {
+ @Test public void testSubQueryInJoin() {
if (!Bug.TODO_FIXED) {
return;
}
@@ -3423,7 +3423,7 @@ public class SqlParserTest {
"case col1 when \n1.2 then 'one' when 2 then 'two' else 'three' end",
"(CASE WHEN (`COL1` = 1.2) THEN 'one' WHEN (`COL1` = 2) THEN 'two' ELSE 'three' END)");
- // subqueries as case expression operands
+ // sub-queries as case expression operands
checkExp(
"case (select * from emp) when 1 then 2 end",
"(CASE WHEN ((SELECT *\n"
@@ -3716,7 +3716,7 @@ public class SqlParserTest {
"(?s)Encountered \"w1\" at.*");
}
- @Test public void testWindowInSubquery() {
+ @Test public void testWindowInSubQuery() {
check(
"select * from ( select sum(x) over w, sum(y) over w from s window w as (range interval '1' minute preceding))",
"SELECT *\n"
@@ -3761,7 +3761,7 @@ public class SqlParserTest {
"select count(z) over w as foo from Bids window w as (order by x ^partition^ by y)",
"(?s).*Encountered \"partition\".*");
- // Cannot partition by subquery
+ // Cannot partition by sub-query
checkFails(
"select sum(a) over (partition by ^(^select 1 from t), x) from t2",
"Query expression encountered in illegal context");
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java
index f6d81f4..326a460 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlAdvisorTest.java
@@ -816,7 +816,7 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
@Test public void testSubQueryInWhere() {
String sql;
- // Aliases from enclosing subqueries are inherited: hence A from
+ // Aliases from enclosing sub-queries are inherited: hence A from
// enclosing, B from same scope.
// The raw columns from dept are suggested (because they can
// be used unqualified in the inner scope) but the raw
@@ -988,7 +988,7 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
expected = "SELECT emp.empno FROM sales.emp ORDER BY _suggest_";
assertSimplify(sql, expected);
- // subquery in from
+ // sub-query in from
sql =
"select t.^ from (select 1 as x, 2 as y from sales.emp) as t "
+ "where t.dummy=1";
@@ -1025,10 +1025,10 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
"SELECT t. _suggest_ FROM ( SELECT 0 AS x , 0 AS y FROM sales )";
assertSimplify(sql, expected);
- // subquery in where; note that:
- // 1. removes the SELECT clause of subquery in WHERE clause;
- // 2. keeps SELECT clause of subquery in FROM clause;
- // 3. removes GROUP BY clause of subquery in FROM clause;
+ // sub-query in where; note that:
+ // 1. removes the SELECT clause of sub-query in WHERE clause;
+ // 2. keeps SELECT clause of sub-query in FROM clause;
+ // 3. removes GROUP BY clause of sub-query in FROM clause;
// 4. removes SELECT clause of outer query.
sql =
"select x + y + 32 from "
@@ -1057,7 +1057,7 @@ public class SqlAdvisorTest extends SqlValidatorTestCase {
+ "WHERE substring ( a. _suggest_ FROM 3 for 6 ) = '1234'";
assertSimplify(sql, expected);
- // missing ')' following subquery
+ // missing ')' following sub-query
sql =
"select * from sales.emp a where deptno in ("
+ "select * from sales.dept b where ^";
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
index ef60d10..de58609 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
@@ -1834,8 +1834,8 @@ public abstract class SqlOperatorBaseTest {
"1",
0);
- // Check return type on scalar subquery in select list. Note return
- // type is always nullable even if subquery select value is NOT NULL.
+ // Check return type on scalar sub-query in select list. Note return
+ // type is always nullable even if sub-query select value is NOT NULL.
// Bug FRG-189 causes this test to fail only in SqlOperatorTest; not
// in subtypes.
if (Bug.FRG189_FIXED
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
index f66fd86..e414b0e 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
@@ -207,12 +207,12 @@ public class SqlPrettyWriterTest {
checkSimple(prettyWriter, "${desc}", "${formatted}");
}
- @Test public void testDamiansSubqueryStyle() throws Exception {
+ @Test public void testDamiansSubQueryStyle() throws Exception {
// Note that ( is at the indent, SELECT is on the same line, and ) is
// below it.
final SqlPrettyWriter prettyWriter =
new SqlPrettyWriter(SqlDialect.DUMMY);
- prettyWriter.setSubqueryStyle(SqlWriter.SubqueryStyle.BLACK);
+ prettyWriter.setSubQueryStyle(SqlWriter.SubQueryStyle.BLACK);
checkSimple(prettyWriter, "${desc}", "${formatted}");
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java b/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
index ccff1c8..a2efb1e 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
@@ -539,7 +539,8 @@ public class JdbcAdapterTest {
final String expected;
switch (CalciteAssert.DB) {
case MYSQL:
- expected = "Subquery returns more than 1 row";
+ expected = "Sub"
+ + "query returns more than 1 row";
break;
default:
expected = "more than one value in agg SINGLE_VALUE";
@@ -581,7 +582,7 @@ public class JdbcAdapterTest {
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-666">[CALCITE-666]
* Anti-semi-joins against JDBC adapter give wrong results</a>. */
- @Test public void testScalarSubquery() {
+ @Test public void testScalarSubQuery() {
CalciteAssert.model(JdbcTest.SCOTT_MODEL)
.query("SELECT COUNT(empno) AS cEmpNo FROM \"SCOTT\".\"EMP\" "
+ "WHERE DEPTNO <> (SELECT * FROM (VALUES 1))")
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/test/java/org/apache/calcite/test/JdbcTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcTest.java b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
index 643eb09..b8bbe12 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -4723,7 +4723,7 @@ public class JdbcTest {
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-313">[CALCITE-313]
* Query decorrelation fails</a>. */
- @Test public void testJoinInCorrelatedSubquery() {
+ @Test public void testJoinInCorrelatedSubQuery() {
CalciteAssert.hr()
.query("select *\n"
+ "from \"hr\".\"depts\" as d\n"
@@ -4762,8 +4762,8 @@ public class JdbcTest {
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-559">[CALCITE-559]
- * Correlated scalar subquery in WHERE gives error</a>. */
- @Test public void testJoinCorrelatedScalarSubquery() throws SQLException {
+ * Correlated scalar sub-query in WHERE gives error</a>. */
+ @Test public void testJoinCorrelatedScalarSubQuery() throws SQLException {
final String sql = "select e.employee_id, d.department_id "
+ " from employee e, department d "
+ " where e.department_id = d.department_id "
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index 2749b7f..7aa6b33 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -179,7 +179,8 @@ public class RelOptRulesTest extends RelOptTestBase {
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1479">[CALCITE-1479]
- * AssertionError in ReduceExpressionsRule on multi-column IN subquery</a>. */
+ * AssertionError in ReduceExpressionsRule on multi-column IN
+ * sub-query</a>. */
@Test public void testReduceCompositeInSubQuery() {
final HepProgram hepProgram = new HepProgramBuilder()
.addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/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 4317b7d..14faa67 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -1927,11 +1927,12 @@ public class SqlToRelConverterTest extends SqlToRelTestBase {
// No conversion to join since less than IN-list size threshold 10
SqlToRelConverter.Config noConvertConfig = SqlToRelConverter.configBuilder().
- withInSubqueryThreshold(10).build();
+
+ withInSubQueryThreshold(10).build();
sql(sql).withConfig(noConvertConfig).convertsTo("${planNotConverted}");
// Conversion to join since greater than IN-list size threshold 2
SqlToRelConverter.Config convertConfig = SqlToRelConverter.configBuilder().
- withInSubqueryThreshold(2).build();
+ withInSubQueryThreshold(2).build();
sql(sql).withConfig(convertConfig).convertsTo("${planConverted}");
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/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 78377f8..02d242b 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -4400,7 +4400,7 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
"Duplicate window specification not allowed in the same window clause");
}
- @Test public void testWindowClauseWithSubquery() {
+ @Test public void testWindowClauseWithSubQuery() {
check("select * from\n"
+ "( select sum(empno) over w, sum(deptno) over w from emp\n"
+ "window w as (order by hiredate range interval '1' minute preceding))");
@@ -4748,7 +4748,7 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
ERR_IN_OPERANDS_INCOMPATIBLE);
}
- @Test public void testInSubquery() {
+ @Test public void testInSubQuery() {
check("select * from emp where deptno in (select deptno from dept)");
check("select * from emp where (empno,deptno)"
+ " in (select deptno,deptno from dept)");
@@ -4800,7 +4800,7 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
"select 1 from emp, dept, emp as e, ^dept as emp^, emp",
"Duplicate relation name 'EMP' in FROM clause");
- // alias applied to subquery
+ // alias applied to sub-query
checkFails(
"select 1 from emp, (^select 1 as x from (values (true))) as emp^",
"Duplicate relation name 'EMP' in FROM clause");
@@ -5428,8 +5428,8 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
+ "join (select 1 as job from (true)) using (job)", "ambig");
}
- @Ignore("bug: should fail if subquery does not have alias")
- @Test public void testJoinSubquery() {
+ @Ignore("bug: should fail if sub-query does not have alias")
+ @Test public void testJoinSubQuery() {
// Sub-queries require alias
checkFails("select * from (select 1 as one from emp)\n"
+ "join (values (1), (2)) on true",
@@ -5616,7 +5616,7 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
}
/** Tests the {@code WITH} clause in sub-queries. */
- @Test public void testWithSubquery() {
+ @Test public void testWithSubQuery() {
// nested WITH (parentheses required - and even with parentheses SQL
// standard doesn't allow sub-query to have WITH)
checkResultType("with emp2 as (select * from emp)\n"
@@ -5863,7 +5863,7 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
// invalid in oracle and pre-99
conformance.isSortByOrdinal() ? "Ordinal out of range" : null);
- // Sort by scalar subquery
+ // Sort by scalar sub-query
check("select * from emp\n"
+ "order by (select name from dept where deptno = emp.deptno)");
checkFails(
@@ -6155,7 +6155,7 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
check("select * from (select empno,deptno from emp) group by deptno,empno");
// This query tries to reference an agg expression from within a
- // subquery as a correlating expression, but the SQL syntax rules say
+ // sub-query as a correlating expression, but the SQL syntax rules say
// that the agg function SUM always applies to the current scope.
// As it happens, the query is valid.
check("select deptno\n"
@@ -6163,7 +6163,7 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
+ "group by deptno\n"
+ "having exists (select sum(emp.sal) > 10 from (values(true)))");
- // if you reference a column from a subquery, it must be a group col
+ // if you reference a column from a sub-query, it must be a group col
check("select deptno "
+ "from emp "
+ "group by deptno "
@@ -6283,7 +6283,7 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
// todo: enable when correlating variables work
public void _testGroupExpressionEquivalenceCorrelated() {
- // dname comes from dept, so it is constant within the subquery, and
+ // dname comes from dept, so it is constant within the sub-query, and
// is so is a valid expr in a group-by query
check("select * from dept where exists ("
+ "select dname from emp group by empno)");
@@ -7187,11 +7187,12 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
"SELECT ename, 1 + (select deptno from dept where deptno=1) as X FROM emp",
"RecordType(VARCHAR(20) NOT NULL ENAME, INTEGER X) NOT NULL");
- // scalar subquery inside WHERE
+ // scalar sub-query inside WHERE
check("select * from emp where (select true from dept)");
}
- public void _testSubqueryInOnClause() {
+ @Ignore("not supported")
+ @Test public void testSubQueryInOnClause() {
// Currently not supported. Should give validator error, but gives
// internal error.
check("select * from emp as emps left outer join dept as depts\n"
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/test/resources/org/apache/calcite/sql/test/SqlPrettyWriterTest.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/calcite/sql/test/SqlPrettyWriterTest.xml b/core/src/test/resources/org/apache/calcite/sql/test/SqlPrettyWriterTest.xml
index 38d4240..472061d 100644
--- a/core/src/test/resources/org/apache/calcite/sql/test/SqlPrettyWriterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/sql/test/SqlPrettyWriterTest.xml
@@ -154,7 +154,7 @@ FROM (SELECT *
ORDER BY GG]]>
</Resource>
</TestCase>
- <TestCase name="testDamiansSubqueryStyle">
+ <TestCase name="testDamiansSubQueryStyle">
<Resource name="desc"/>
<Resource name="formatted">
<![CDATA[SELECT `X` AS `A`, `B` AS `B`, `C` AS `C`, `D`, 'mixed-Case string', `UNQUOTEDCAMELCASEID`, `quoted id`
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/test/resources/sql/misc.iq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/misc.iq b/core/src/test/resources/sql/misc.iq
index 972b73c..841966c 100644
--- a/core/src/test/resources/sql/misc.iq
+++ b/core/src/test/resources/sql/misc.iq
@@ -626,7 +626,7 @@ EnumerableCalc(expr#0..1=[{inputs}], expr#2=[1], expr#3=[=($t0, $t2)], proj#0..1
EnumerableTableScan(table=[[foodmart2, days]])
!plan
-# [HIVE-5873] Semi-join to count subquery
+# [HIVE-5873] Semi-join to count sub-query
# [CALCITE-365] AssertionError while translating query with WITH and correlated sub-query
!if (false) {
with parts (PNum, OrderOnHand)
@@ -704,8 +704,8 @@ group by case when a=1 then 1 else 2 end;
!ok
-# [DERBY-4450] GROUP BY in an IN-subquery inside HAVING clause whose select list
-# is subset of group by columns.
+# [DERBY-4450] GROUP BY in an IN-sub-query inside HAVING clause whose select
+# list is subset of group by columns.
select sum("day") from "days" group by "week_day" having "week_day" in (
select "week_day" from "days" group by "week_day", "day");
+--------+
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/test/resources/sql/sub-query.iq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/sub-query.iq b/core/src/test/resources/sql/sub-query.iq
new file mode 100644
index 0000000..ec42c0c
--- /dev/null
+++ b/core/src/test/resources/sql/sub-query.iq
@@ -0,0 +1,513 @@
+# sub-query.iq - Queries involving IN and EXISTS sub-queries
+#
+# 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.
+#
+!use post
+!set outputformat psql
+
+# [CALCITE-373]
+# the following should return no rows, because the IN list has a null.
+# for details on this: see HIVE-784, Dayal's paper from VLDB-87
+with
+t1(x) as (select * from (values 1,2, case when 1 = 1 then null else 3 end)),
+t2(x) as (select * from (values 1,case when 1 = 1 then null else 3 end))
+select *
+from t1
+where t1.x not in (select t2.x from t2);
+ X
+---
+(0 rows)
+
+!ok
+EnumerableCalc(expr#0..4=[{inputs}], expr#5=[0], expr#6=[=($t1, $t5)], expr#7=[false], expr#8=[IS NOT NULL($t4)], expr#9=[true], expr#10=[IS NULL($t0)], expr#11=[null], expr#12=[<($t2, $t1)], expr#13=[CASE($t6, $t7, $t8, $t9, $t10, $t11, $t12, $t9, $t7)], expr#14=[NOT($t13)], EXPR$0=[$t0], $condition=[$t14])
+ EnumerableJoin(condition=[=($0, $3)], joinType=[left])
+ EnumerableJoin(condition=[true], joinType=[inner])
+ EnumerableUnion(all=[true])
+ EnumerableCalc(expr#0=[{inputs}], expr#1=[1], EXPR$0=[$t1])
+ EnumerableValues(tuples=[[{ 0 }]])
+ EnumerableCalc(expr#0=[{inputs}], expr#1=[2], EXPR$0=[$t1])
+ EnumerableValues(tuples=[[{ 0 }]])
+ EnumerableCalc(expr#0=[{inputs}], expr#1=[1], expr#2=[=($t1, $t1)], expr#3=[null], expr#4=[3], expr#5=[CASE($t2, $t3, $t4)], EXPR$0=[$t5])
+ EnumerableValues(tuples=[[{ 0 }]])
+ EnumerableAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0)])
+ EnumerableUnion(all=[true])
+ EnumerableCalc(expr#0=[{inputs}], expr#1=[1], EXPR$0=[$t1])
+ EnumerableValues(tuples=[[{ 0 }]])
+ EnumerableCalc(expr#0=[{inputs}], expr#1=[1], expr#2=[=($t1, $t1)], expr#3=[null], expr#4=[3], expr#5=[CASE($t2, $t3, $t4)], EXPR$0=[$t5])
+ EnumerableValues(tuples=[[{ 0 }]])
+ EnumerableAggregate(group=[{0, 1}])
+ EnumerableCalc(expr#0=[{inputs}], expr#1=[true], proj#0..1=[{exprs}])
+ EnumerableUnion(all=[true])
+ EnumerableCalc(expr#0=[{inputs}], expr#1=[1], EXPR$0=[$t1])
+ EnumerableValues(tuples=[[{ 0 }]])
+ EnumerableCalc(expr#0=[{inputs}], expr#1=[1], expr#2=[=($t1, $t1)], expr#3=[null], expr#4=[3], expr#5=[CASE($t2, $t3, $t4)], EXPR$0=[$t5])
+ EnumerableValues(tuples=[[{ 0 }]])
+!plan
+
+# Use of case is to get around issue with directly specifying null in values
+# list. Postgres gives 0 rows.
+with
+t1(x) as (select * from (values (1),(2),(case when 1 = 1 then null else 3 end)) as t1),
+t2(x) as (select * from (values (1),(case when 1 = 1 then null else 3 end)) as t2)
+select *
+from t1
+where t1.x not in (select t2.x from t2);
+
+ X
+---
+(0 rows)
+
+!ok
+
+# RHS has a mixture of NULL and NOT NULL keys
+select * from dept where deptno not in (select deptno from emp);
+ DEPTNO | DNAME
+--------+-------
+(0 rows)
+
+!ok
+select deptno, deptno in (select deptno from emp) from dept;
+ DEPTNO | EXPR$1
+--------+--------
+ 10 | true
+ 20 | true
+ 30 | true
+ 40 | null
+(4 rows)
+
+!ok
+select deptno, deptno not in (select deptno from emp) from dept;
+ DEPTNO | EXPR$1
+--------+--------
+ 10 | false
+ 20 | false
+ 30 | false
+ 40 | null
+(4 rows)
+
+!ok
+
+# RHS has only NULL keys
+select * from dept where deptno not in (select deptno from emp where deptno is null);
+ DEPTNO | DNAME
+--------+-------
+(0 rows)
+
+!ok
+select deptno, deptno in (select deptno from emp where deptno is null) from dept;
+ DEPTNO | EXPR$1
+--------+--------
+ 10 | null
+ 20 | null
+ 30 | null
+ 40 | null
+(4 rows)
+
+!ok
+select deptno, deptno not in (select deptno from emp where deptno is null) from dept;
+ DEPTNO | EXPR$1
+--------+--------
+ 10 | null
+ 20 | null
+ 30 | null
+ 40 | null
+(4 rows)
+
+!ok
+
+!set outputformat mysql
+
+# RHS has only NOT NULL keys
+select * from dept where deptno not in (select deptno from emp where deptno is not null);
++--------+-------------+
+| DEPTNO | DNAME |
++--------+-------------+
+| 40 | Empty |
++--------+-------------+
+(1 row)
+
+!ok
+select deptno, deptno in (select deptno from emp where deptno is not null) from dept;
++--------+--------+
+| DEPTNO | EXPR$1 |
++--------+--------+
+| 10 | true |
+| 20 | true |
+| 30 | true |
+| 40 | false |
++--------+--------+
+(4 rows)
+
+!ok
+select deptno, deptno not in (select deptno from emp where deptno is not null) from dept;
++--------+--------+
+| DEPTNO | EXPR$1 |
++--------+--------+
+| 10 | false |
+| 20 | false |
+| 30 | false |
+| 40 | true |
++--------+--------+
+(4 rows)
+
+!ok
+
+# RHS has no rows
+# Even 'NULL NOT IN ...' is TRUE.
+select * from dept where deptno not in (select deptno from emp where false);
++--------+-------------+
+| DEPTNO | DNAME |
++--------+-------------+
+| 10 | Sales |
+| 20 | Marketing |
+| 30 | Engineering |
+| 40 | Empty |
++--------+-------------+
+(4 rows)
+
+!ok
+select deptno, deptno in (select deptno from emp where false) from dept;
++--------+--------+
+| DEPTNO | EXPR$1 |
++--------+--------+
+| 10 | false |
+| 20 | false |
+| 30 | false |
+| 40 | false |
++--------+--------+
+(4 rows)
+
+!ok
+select deptno, deptno not in (select deptno from emp where false) from dept;
++--------+--------+
+| DEPTNO | EXPR$1 |
++--------+--------+
+| 10 | true |
+| 20 | true |
+| 30 | true |
+| 40 | true |
++--------+--------+
+(4 rows)
+
+!ok
+
+# Multiple IN, connected by OR
+select * from dept
+where deptno in (select deptno from emp where gender = 'F')
+or deptno in (select deptno from emp where gender = 'M');
++--------+-------------+
+| DEPTNO | DNAME |
++--------+-------------+
+| 10 | Sales |
+| 20 | Marketing |
+| 30 | Engineering |
++--------+-------------+
+(3 rows)
+
+!ok
+
+# Mix IN and EXISTS
+select * from dept
+where deptno in (select deptno from emp where gender = 'F')
+or exists (select 99, 101 from emp where gender = 'X');
++--------+-------------+
+| DEPTNO | DNAME |
++--------+-------------+
+| 10 | Sales |
+| 30 | Engineering |
++--------+-------------+
+(2 rows)
+
+!ok
+
+# Composite key
+select * from dept
+where (deptno, deptno) in (select deptno * 2 - deptno, deptno from emp where gender = 'F');
+
+# Composite key, part literal
+select * from emp
+where (gender, deptno) in (select gender, 10 from emp where gender = 'F');
++-------+--------+--------+
+| ENAME | DEPTNO | GENDER |
++-------+--------+--------+
+| Jane | 10 | F |
++-------+--------+--------+
+(1 row)
+
+!ok
+
+!use scott
+
+# [CALCITE-1155] Support columns for IN list
+SELECT empno, ename, mgr FROM "scott".emp WHERE 7782 IN (empno, mgr);
++-------+--------+------+
+| EMPNO | ENAME | MGR |
++-------+--------+------+
+| 7782 | CLARK | 7839 |
+| 7934 | MILLER | 7782 |
++-------+--------+------+
+(2 rows)
+
+!ok
+
+# [CALCITE-694] Scan HAVING clause for sub-queries and IN-lists
+SELECT count(*) AS c
+FROM "scott".emp
+GROUP BY emp.deptno
+HAVING sum(case when emp.empno in (7369, 7839, 7902) then emp.sal else 0 end)
+ BETWEEN 5000.0 AND 10000.0;
++---+
+| C |
++---+
+| 3 |
++---+
+(1 row)
+
+!ok
+
+# [CALCITE-716] Scalar sub-query and aggregate function in SELECT or HAVING
+# clause gives AssertionError
+SELECT emp.deptno
+FROM "scott".emp
+GROUP BY emp.deptno
+HAVING max(emp.empno) > (SELECT min(emp.empno) FROM "scott".emp);
++--------+
+| DEPTNO |
++--------+
+| 10 |
+| 20 |
+| 30 |
++--------+
+(3 rows)
+
+!ok
+
+# [CALCITE-716] Scalar sub-query and aggregate function in SELECT or HAVING
+# clause gives AssertionError
+SELECT emp.deptno,
+ max(emp.empno) > (SELECT min(emp.empno) FROM "scott".emp) as bbbb
+FROM "scott".emp
+GROUP BY emp.deptno;
++--------+------+
+| DEPTNO | BBBB |
++--------+------+
+| 10 | true |
+| 20 | true |
+| 30 | true |
++--------+------+
+(3 rows)
+
+!ok
+
+# [DRILL-4407] Group by sub-query causes Java NPE
+select count(*) as c
+from "scott".emp
+group by (select deptno from "scott".emp where empno = 10);
++----+
+| C |
++----+
+| 14 |
++----+
+(1 row)
+
+!ok
+
+!if (fixed.calcite1045) {
+# Correlated IN sub-query in WHERE clause of JOIN
+select empno from "scott".emp as e
+join "scott".dept as d using (deptno)
+where e.job in (
+ select e2.job from "scott".emp as e2 where e2.deptno > e.deptno);
+ EMPNO
+-------
+ 7369
+ 7566
+ 7782
+ 7876
+ 7934
+(5 rows)
+
+!ok
+EnumerableCalc(expr#0..5=[{inputs}], EMPNO=[$t0])
+ EnumerableJoin(condition=[=($2, $5)], joinType=[inner])
+ EnumerableCalc(expr#0..4=[{inputs}], EMPNO=[$t2], JOB=[$t3], DEPTNO=[$t4], JOB0=[$t0], DEPTNO0=[$t1])
+ EnumerableJoin(condition=[AND(=($1, $4), =($0, $3))], joinType=[inner])
+ EnumerableCalc(expr#0..1=[{inputs}], JOB=[$t1], DEPTNO=[$t0])
+ EnumerableAggregate(group=[{0, 2}])
+ EnumerableCalc(expr#0..3=[{inputs}], expr#4=[>($t3, $t0)], proj#0..3=[{exprs}], $condition=[$t4])
+ EnumerableJoin(condition=[true], joinType=[inner])
+ EnumerableAggregate(group=[{7}])
+ EnumerableTableScan(table=[[scott, EMP]])
+ EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], JOB=[$t2], DEPTNO=[$t7])
+ EnumerableTableScan(table=[[scott, EMP]])
+ EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], JOB=[$t2], DEPTNO=[$t7])
+ EnumerableTableScan(table=[[scott, EMP]])
+ EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0])
+ EnumerableTableScan(table=[[scott, DEPT]])
+!plan
+!}
+
+!if (fixed.calcite1045) {
+# Correlated NOT IN sub-query in WHERE clause of JOIN
+select empno from "scott".emp as e
+join "scott".dept as d using (deptno)
+where e.job not in (
+ select e2.job from "scott".emp as e2 where e2.deptno > e.deptno);
+!ok
+!plan
+!}
+
+# Condition that returns a NULL key.
+# Tested on Oracle.
+select count(*) as c
+from "scott".emp
+where sal + 100 not in (
+ select comm
+ from "scott".emp);
++---+
+| C |
++---+
+| 0 |
++---+
+(1 row)
+
+!ok
+
+# Condition that happens to eliminate all NULL keys.
+# The one missing row has {ename: 'MARTIN', comm: 1400}
+# Tested on Oracle.
+select count(*) as c
+from "scott".emp
+where sal + 100 not in (
+ select comm from "scott".emp
+ where job = 'SALESMAN');
++----+
+| C |
++----+
+| 13 |
++----+
+(1 row)
+
+!ok
+
+# Condition that provably eliminates all NULL keys.
+# Tested on Oracle.
+select count(*) as c
+from "scott".emp
+where sal + 100 not in (
+ select comm
+ from "scott".emp
+ where comm < 1000);
++----+
+| C |
++----+
+| 14 |
++----+
+(1 row)
+
+!ok
+
+# Correlated condition in NOT IN.
+# Tested on Oracle.
+!if (fixed.calcite1513) {
+select count(*) as c
+from "scott".emp as e
+where sal + 100 not in (
+ select comm
+ from "scott".emp
+ where job = e.job);
+ EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
+---------- ---------- --------- ---------- --------- ---------- ---------- ----------
+ 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
+ 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
+ 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
+ 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
+!ok
+!}
+
+# [CALCITE-864] Correlation variable has incorrect row type if it is populated
+# by right side of a Join
+select *
+from "scott".emp as e
+join "scott".dept as d using (deptno)
+where sal = (
+ select max(sal)
+ from "scott".emp as e2
+ join "scott".dept as d2 using (deptno)
+ where d2.deptno = d.deptno);
++-------+-------+-----------+------+------------+---------+------+--------+---------+------------+----------+
+| EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO | DEPTNO0 | DNAME | LOC |
++-------+-------+-----------+------+------------+---------+------+--------+---------+------------+----------+
+| 7698 | BLAKE | MANAGER | 7839 | 1981-01-05 | 2850.00 | | 30 | 30 | SALES | CHICAGO |
+| 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 | 3000.00 | | 20 | 20 | RESEARCH | DALLAS |
+| 7839 | KING | PRESIDENT | | 1981-11-17 | 5000.00 | | 10 | 10 | ACCOUNTING | NEW YORK |
+| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | | 20 | 20 | RESEARCH | DALLAS |
++-------+-------+-----------+------+------------+---------+------+--------+---------+------------+----------+
+(4 rows)
+
+!ok
+
+# Simpler test case for [CALCITE-864]
+select empno, ename, sal, e.deptno, loc
+from "scott".emp as e
+join "scott".dept as d using (deptno)
+where e.sal = (
+ select max(sal)
+ from "scott".emp as e2
+ where e2.deptno = e.deptno);
++-------+-------+---------+--------+----------+
+| EMPNO | ENAME | SAL | DEPTNO | LOC |
++-------+-------+---------+--------+----------+
+| 7698 | BLAKE | 2850.00 | 30 | CHICAGO |
+| 7788 | SCOTT | 3000.00 | 20 | DALLAS |
+| 7839 | KING | 5000.00 | 10 | NEW YORK |
+| 7902 | FORD | 3000.00 | 20 | DALLAS |
++-------+-------+---------+--------+----------+
+(4 rows)
+
+!ok
+
+# Simpler test case for [CALCITE-864]
+select *
+from "scott".emp as e
+join "scott".dept as d using (deptno)
+where d.dname = (
+ select max(dname)
+ from "scott".dept as d2
+ where d2.deptno = d.deptno);
++-------+--------+-----------+------+------------+---------+---------+--------+---------+------------+----------+
+| EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO | DEPTNO0 | DNAME | LOC |
++-------+--------+-----------+------+------------+---------+---------+--------+---------+------------+----------+
+| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | | 20 | 20 | RESEARCH | DALLAS |
+| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 30 | SALES | CHICAGO |
+| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 30 | SALES | CHICAGO |
+| 7566 | JONES | MANAGER | 7839 | 1981-02-04 | 2975.00 | | 20 | 20 | RESEARCH | DALLAS |
+| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 30 | SALES | CHICAGO |
+| 7698 | BLAKE | MANAGER | 7839 | 1981-01-05 | 2850.00 | | 30 | 30 | SALES | CHICAGO |
+| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | | 10 | 10 | ACCOUNTING | NEW YORK |
+| 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 | 3000.00 | | 20 | 20 | RESEARCH | DALLAS |
+| 7839 | KING | PRESIDENT | | 1981-11-17 | 5000.00 | | 10 | 10 | ACCOUNTING | NEW YORK |
+| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 30 | SALES | CHICAGO |
+| 7876 | ADAMS | CLERK | 7788 | 1987-05-23 | 1100.00 | | 20 | 20 | RESEARCH | DALLAS |
+| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | | 30 | 30 | SALES | CHICAGO |
+| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | | 20 | 20 | RESEARCH | DALLAS |
+| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | | 10 | 10 | ACCOUNTING | NEW YORK |
++-------+--------+-----------+------+------------+---------+---------+--------+---------+------------+----------+
+(14 rows)
+
+!ok
+
+# End sub-query.iq
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/test/resources/sql/subquery.iq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/subquery.iq b/core/src/test/resources/sql/subquery.iq
deleted file mode 100644
index 73ee2f9..0000000
--- a/core/src/test/resources/sql/subquery.iq
+++ /dev/null
@@ -1,513 +0,0 @@
-# subquery.iq - Queries involving IN and EXISTS sub-queries
-#
-# 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.
-#
-!use post
-!set outputformat psql
-
-# [CALCITE-373]
-# the following should return no rows, because the IN list has a null.
-# for details on this: see HIVE-784, Dayal's paper from VLDB-87
-with
-t1(x) as (select * from (values 1,2, case when 1 = 1 then null else 3 end)),
-t2(x) as (select * from (values 1,case when 1 = 1 then null else 3 end))
-select *
-from t1
-where t1.x not in (select t2.x from t2);
- X
----
-(0 rows)
-
-!ok
-EnumerableCalc(expr#0..4=[{inputs}], expr#5=[0], expr#6=[=($t1, $t5)], expr#7=[false], expr#8=[IS NOT NULL($t4)], expr#9=[true], expr#10=[IS NULL($t0)], expr#11=[null], expr#12=[<($t2, $t1)], expr#13=[CASE($t6, $t7, $t8, $t9, $t10, $t11, $t12, $t9, $t7)], expr#14=[NOT($t13)], EXPR$0=[$t0], $condition=[$t14])
- EnumerableJoin(condition=[=($0, $3)], joinType=[left])
- EnumerableJoin(condition=[true], joinType=[inner])
- EnumerableUnion(all=[true])
- EnumerableCalc(expr#0=[{inputs}], expr#1=[1], EXPR$0=[$t1])
- EnumerableValues(tuples=[[{ 0 }]])
- EnumerableCalc(expr#0=[{inputs}], expr#1=[2], EXPR$0=[$t1])
- EnumerableValues(tuples=[[{ 0 }]])
- EnumerableCalc(expr#0=[{inputs}], expr#1=[1], expr#2=[=($t1, $t1)], expr#3=[null], expr#4=[3], expr#5=[CASE($t2, $t3, $t4)], EXPR$0=[$t5])
- EnumerableValues(tuples=[[{ 0 }]])
- EnumerableAggregate(group=[{}], c=[COUNT()], ck=[COUNT($0)])
- EnumerableUnion(all=[true])
- EnumerableCalc(expr#0=[{inputs}], expr#1=[1], EXPR$0=[$t1])
- EnumerableValues(tuples=[[{ 0 }]])
- EnumerableCalc(expr#0=[{inputs}], expr#1=[1], expr#2=[=($t1, $t1)], expr#3=[null], expr#4=[3], expr#5=[CASE($t2, $t3, $t4)], EXPR$0=[$t5])
- EnumerableValues(tuples=[[{ 0 }]])
- EnumerableAggregate(group=[{0, 1}])
- EnumerableCalc(expr#0=[{inputs}], expr#1=[true], proj#0..1=[{exprs}])
- EnumerableUnion(all=[true])
- EnumerableCalc(expr#0=[{inputs}], expr#1=[1], EXPR$0=[$t1])
- EnumerableValues(tuples=[[{ 0 }]])
- EnumerableCalc(expr#0=[{inputs}], expr#1=[1], expr#2=[=($t1, $t1)], expr#3=[null], expr#4=[3], expr#5=[CASE($t2, $t3, $t4)], EXPR$0=[$t5])
- EnumerableValues(tuples=[[{ 0 }]])
-!plan
-
-# Use of case is to get around issue with directly specifying null in values
-# list. Postgres gives 0 rows.
-with
-t1(x) as (select * from (values (1),(2),(case when 1 = 1 then null else 3 end)) as t1),
-t2(x) as (select * from (values (1),(case when 1 = 1 then null else 3 end)) as t2)
-select *
-from t1
-where t1.x not in (select t2.x from t2);
-
- X
----
-(0 rows)
-
-!ok
-
-# RHS has a mixture of NULL and NOT NULL keys
-select * from dept where deptno not in (select deptno from emp);
- DEPTNO | DNAME
---------+-------
-(0 rows)
-
-!ok
-select deptno, deptno in (select deptno from emp) from dept;
- DEPTNO | EXPR$1
---------+--------
- 10 | true
- 20 | true
- 30 | true
- 40 | null
-(4 rows)
-
-!ok
-select deptno, deptno not in (select deptno from emp) from dept;
- DEPTNO | EXPR$1
---------+--------
- 10 | false
- 20 | false
- 30 | false
- 40 | null
-(4 rows)
-
-!ok
-
-# RHS has only NULL keys
-select * from dept where deptno not in (select deptno from emp where deptno is null);
- DEPTNO | DNAME
---------+-------
-(0 rows)
-
-!ok
-select deptno, deptno in (select deptno from emp where deptno is null) from dept;
- DEPTNO | EXPR$1
---------+--------
- 10 | null
- 20 | null
- 30 | null
- 40 | null
-(4 rows)
-
-!ok
-select deptno, deptno not in (select deptno from emp where deptno is null) from dept;
- DEPTNO | EXPR$1
---------+--------
- 10 | null
- 20 | null
- 30 | null
- 40 | null
-(4 rows)
-
-!ok
-
-!set outputformat mysql
-
-# RHS has only NOT NULL keys
-select * from dept where deptno not in (select deptno from emp where deptno is not null);
-+--------+-------------+
-| DEPTNO | DNAME |
-+--------+-------------+
-| 40 | Empty |
-+--------+-------------+
-(1 row)
-
-!ok
-select deptno, deptno in (select deptno from emp where deptno is not null) from dept;
-+--------+--------+
-| DEPTNO | EXPR$1 |
-+--------+--------+
-| 10 | true |
-| 20 | true |
-| 30 | true |
-| 40 | false |
-+--------+--------+
-(4 rows)
-
-!ok
-select deptno, deptno not in (select deptno from emp where deptno is not null) from dept;
-+--------+--------+
-| DEPTNO | EXPR$1 |
-+--------+--------+
-| 10 | false |
-| 20 | false |
-| 30 | false |
-| 40 | true |
-+--------+--------+
-(4 rows)
-
-!ok
-
-# RHS has no rows
-# Even 'NULL NOT IN ...' is TRUE.
-select * from dept where deptno not in (select deptno from emp where false);
-+--------+-------------+
-| DEPTNO | DNAME |
-+--------+-------------+
-| 10 | Sales |
-| 20 | Marketing |
-| 30 | Engineering |
-| 40 | Empty |
-+--------+-------------+
-(4 rows)
-
-!ok
-select deptno, deptno in (select deptno from emp where false) from dept;
-+--------+--------+
-| DEPTNO | EXPR$1 |
-+--------+--------+
-| 10 | false |
-| 20 | false |
-| 30 | false |
-| 40 | false |
-+--------+--------+
-(4 rows)
-
-!ok
-select deptno, deptno not in (select deptno from emp where false) from dept;
-+--------+--------+
-| DEPTNO | EXPR$1 |
-+--------+--------+
-| 10 | true |
-| 20 | true |
-| 30 | true |
-| 40 | true |
-+--------+--------+
-(4 rows)
-
-!ok
-
-# Multiple IN, connected by OR
-select * from dept
-where deptno in (select deptno from emp where gender = 'F')
-or deptno in (select deptno from emp where gender = 'M');
-+--------+-------------+
-| DEPTNO | DNAME |
-+--------+-------------+
-| 10 | Sales |
-| 20 | Marketing |
-| 30 | Engineering |
-+--------+-------------+
-(3 rows)
-
-!ok
-
-# Mix IN and EXISTS
-select * from dept
-where deptno in (select deptno from emp where gender = 'F')
-or exists (select 99, 101 from emp where gender = 'X');
-+--------+-------------+
-| DEPTNO | DNAME |
-+--------+-------------+
-| 10 | Sales |
-| 30 | Engineering |
-+--------+-------------+
-(2 rows)
-
-!ok
-
-# Composite key
-select * from dept
-where (deptno, deptno) in (select deptno * 2 - deptno, deptno from emp where gender = 'F');
-
-# Composite key, part literal
-select * from emp
-where (gender, deptno) in (select gender, 10 from emp where gender = 'F');
-+-------+--------+--------+
-| ENAME | DEPTNO | GENDER |
-+-------+--------+--------+
-| Jane | 10 | F |
-+-------+--------+--------+
-(1 row)
-
-!ok
-
-!use scott
-
-# [CALCITE-1155] Support columns for IN list
-SELECT empno, ename, mgr FROM "scott".emp WHERE 7782 IN (empno, mgr);
-+-------+--------+------+
-| EMPNO | ENAME | MGR |
-+-------+--------+------+
-| 7782 | CLARK | 7839 |
-| 7934 | MILLER | 7782 |
-+-------+--------+------+
-(2 rows)
-
-!ok
-
-# [CALCITE-694] Scan HAVING clause for sub-queries and IN-lists
-SELECT count(*) AS c
-FROM "scott".emp
-GROUP BY emp.deptno
-HAVING sum(case when emp.empno in (7369, 7839, 7902) then emp.sal else 0 end)
- BETWEEN 5000.0 AND 10000.0;
-+---+
-| C |
-+---+
-| 3 |
-+---+
-(1 row)
-
-!ok
-
-# [CALCITE-716] Scalar sub-query and aggregate function in SELECT or HAVING
-# clause gives AssertionError
-SELECT emp.deptno
-FROM "scott".emp
-GROUP BY emp.deptno
-HAVING max(emp.empno) > (SELECT min(emp.empno) FROM "scott".emp);
-+--------+
-| DEPTNO |
-+--------+
-| 10 |
-| 20 |
-| 30 |
-+--------+
-(3 rows)
-
-!ok
-
-# [CALCITE-716] Scalar sub-query and aggregate function in SELECT or HAVING
-# clause gives AssertionError
-SELECT emp.deptno,
- max(emp.empno) > (SELECT min(emp.empno) FROM "scott".emp) as bbbb
-FROM "scott".emp
-GROUP BY emp.deptno;
-+--------+------+
-| DEPTNO | BBBB |
-+--------+------+
-| 10 | true |
-| 20 | true |
-| 30 | true |
-+--------+------+
-(3 rows)
-
-!ok
-
-# [DRILL-4407] Group by subquery causes Java NPE
-select count(*) as c
-from "scott".emp
-group by (select deptno from "scott".emp where empno = 10);
-+----+
-| C |
-+----+
-| 14 |
-+----+
-(1 row)
-
-!ok
-
-!if (fixed.calcite1045) {
-# Correlated IN sub-query in WHERE clause of JOIN
-select empno from "scott".emp as e
-join "scott".dept as d using (deptno)
-where e.job in (
- select e2.job from "scott".emp as e2 where e2.deptno > e.deptno);
- EMPNO
--------
- 7369
- 7566
- 7782
- 7876
- 7934
-(5 rows)
-
-!ok
-EnumerableCalc(expr#0..5=[{inputs}], EMPNO=[$t0])
- EnumerableJoin(condition=[=($2, $5)], joinType=[inner])
- EnumerableCalc(expr#0..4=[{inputs}], EMPNO=[$t2], JOB=[$t3], DEPTNO=[$t4], JOB0=[$t0], DEPTNO0=[$t1])
- EnumerableJoin(condition=[AND(=($1, $4), =($0, $3))], joinType=[inner])
- EnumerableCalc(expr#0..1=[{inputs}], JOB=[$t1], DEPTNO=[$t0])
- EnumerableAggregate(group=[{0, 2}])
- EnumerableCalc(expr#0..3=[{inputs}], expr#4=[>($t3, $t0)], proj#0..3=[{exprs}], $condition=[$t4])
- EnumerableJoin(condition=[true], joinType=[inner])
- EnumerableAggregate(group=[{7}])
- EnumerableTableScan(table=[[scott, EMP]])
- EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], JOB=[$t2], DEPTNO=[$t7])
- EnumerableTableScan(table=[[scott, EMP]])
- EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], JOB=[$t2], DEPTNO=[$t7])
- EnumerableTableScan(table=[[scott, EMP]])
- EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0])
- EnumerableTableScan(table=[[scott, DEPT]])
-!plan
-!}
-
-!if (fixed.calcite1045) {
-# Correlated NOT IN sub-query in WHERE clause of JOIN
-select empno from "scott".emp as e
-join "scott".dept as d using (deptno)
-where e.job not in (
- select e2.job from "scott".emp as e2 where e2.deptno > e.deptno);
-!ok
-!plan
-!}
-
-# Condition that returns a NULL key.
-# Tested on Oracle.
-select count(*) as c
-from "scott".emp
-where sal + 100 not in (
- select comm
- from "scott".emp);
-+---+
-| C |
-+---+
-| 0 |
-+---+
-(1 row)
-
-!ok
-
-# Condition that happens to eliminate all NULL keys.
-# The one missing row has {ename: 'MARTIN', comm: 1400}
-# Tested on Oracle.
-select count(*) as c
-from "scott".emp
-where sal + 100 not in (
- select comm from "scott".emp
- where job = 'SALESMAN');
-+----+
-| C |
-+----+
-| 13 |
-+----+
-(1 row)
-
-!ok
-
-# Condition that provably eliminates all NULL keys.
-# Tested on Oracle.
-select count(*) as c
-from "scott".emp
-where sal + 100 not in (
- select comm
- from "scott".emp
- where comm < 1000);
-+----+
-| C |
-+----+
-| 14 |
-+----+
-(1 row)
-
-!ok
-
-# Correlated condition in NOT IN.
-# Tested on Oracle.
-!if (fixed.calcite1513) {
-select count(*) as c
-from "scott".emp as e
-where sal + 100 not in (
- select comm
- from "scott".emp
- where job = e.job);
- EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----------- ---------- --------- ---------- --------- ---------- ---------- ----------
- 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
- 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
- 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
- 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
-!ok
-!}
-
-# [CALCITE-864] Correlation variable has incorrect row type if it is populated
-# by right side of a Join
-select *
-from "scott".emp as e
-join "scott".dept as d using (deptno)
-where sal = (
- select max(sal)
- from "scott".emp as e2
- join "scott".dept as d2 using (deptno)
- where d2.deptno = d.deptno);
-+-------+-------+-----------+------+------------+---------+------+--------+---------+------------+----------+
-| EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO | DEPTNO0 | DNAME | LOC |
-+-------+-------+-----------+------+------------+---------+------+--------+---------+------------+----------+
-| 7698 | BLAKE | MANAGER | 7839 | 1981-01-05 | 2850.00 | | 30 | 30 | SALES | CHICAGO |
-| 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 | 3000.00 | | 20 | 20 | RESEARCH | DALLAS |
-| 7839 | KING | PRESIDENT | | 1981-11-17 | 5000.00 | | 10 | 10 | ACCOUNTING | NEW YORK |
-| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | | 20 | 20 | RESEARCH | DALLAS |
-+-------+-------+-----------+------+------------+---------+------+--------+---------+------------+----------+
-(4 rows)
-
-!ok
-
-# Simpler test case for [CALCITE-864]
-select empno, ename, sal, e.deptno, loc
-from "scott".emp as e
-join "scott".dept as d using (deptno)
-where e.sal = (
- select max(sal)
- from "scott".emp as e2
- where e2.deptno = e.deptno);
-+-------+-------+---------+--------+----------+
-| EMPNO | ENAME | SAL | DEPTNO | LOC |
-+-------+-------+---------+--------+----------+
-| 7698 | BLAKE | 2850.00 | 30 | CHICAGO |
-| 7788 | SCOTT | 3000.00 | 20 | DALLAS |
-| 7839 | KING | 5000.00 | 10 | NEW YORK |
-| 7902 | FORD | 3000.00 | 20 | DALLAS |
-+-------+-------+---------+--------+----------+
-(4 rows)
-
-!ok
-
-# Simpler test case for [CALCITE-864]
-select *
-from "scott".emp as e
-join "scott".dept as d using (deptno)
-where d.dname = (
- select max(dname)
- from "scott".dept as d2
- where d2.deptno = d.deptno);
-+-------+--------+-----------+------+------------+---------+---------+--------+---------+------------+----------+
-| EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO | DEPTNO0 | DNAME | LOC |
-+-------+--------+-----------+------+------------+---------+---------+--------+---------+------------+----------+
-| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | | 20 | 20 | RESEARCH | DALLAS |
-| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | 30 | SALES | CHICAGO |
-| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | 30 | SALES | CHICAGO |
-| 7566 | JONES | MANAGER | 7839 | 1981-02-04 | 2975.00 | | 20 | 20 | RESEARCH | DALLAS |
-| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | 30 | SALES | CHICAGO |
-| 7698 | BLAKE | MANAGER | 7839 | 1981-01-05 | 2850.00 | | 30 | 30 | SALES | CHICAGO |
-| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | | 10 | 10 | ACCOUNTING | NEW YORK |
-| 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 | 3000.00 | | 20 | 20 | RESEARCH | DALLAS |
-| 7839 | KING | PRESIDENT | | 1981-11-17 | 5000.00 | | 10 | 10 | ACCOUNTING | NEW YORK |
-| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | 30 | SALES | CHICAGO |
-| 7876 | ADAMS | CLERK | 7788 | 1987-05-23 | 1100.00 | | 20 | 20 | RESEARCH | DALLAS |
-| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | | 30 | 30 | SALES | CHICAGO |
-| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | | 20 | 20 | RESEARCH | DALLAS |
-| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | | 10 | 10 | ACCOUNTING | NEW YORK |
-+-------+--------+-----------+------+------------+---------+---------+--------+---------+------------+----------+
-(14 rows)
-
-!ok
-
-# End subquery.iq
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
----------------------------------------------------------------------
diff --git a/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java b/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
index 9f65fc5..6c381e5 100644
--- a/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
+++ b/example/csv/src/test/java/org/apache/calcite/test/CsvTest.java
@@ -408,12 +408,11 @@ public class CsvTest {
final String sql = "SELECT e.name\n"
+ "FROM emps AS e\n"
+ "WHERE cast(e.empno as bigint) in ";
- checkSql(sql + range(130, SqlToRelConverter.DEFAULT_IN_SUBQUERY_THRESHOLD - 5),
- "smart", expect("NAME=Alice"));
- checkSql(sql + range(130, SqlToRelConverter.DEFAULT_IN_SUBQUERY_THRESHOLD),
- "smart", expect("NAME=Alice"));
- checkSql(sql + range(130, SqlToRelConverter.DEFAULT_IN_SUBQUERY_THRESHOLD + 1000),
- "smart", expect("NAME=Alice"));
+ final int threshold = SqlToRelConverter.DEFAULT_IN_SUB_QUERY_THRESHOLD;
+ checkSql(sql + range(130, threshold - 5), "smart", expect("NAME=Alice"));
+ checkSql(sql + range(130, threshold), "smart", expect("NAME=Alice"));
+ checkSql(sql + range(130, threshold + 1000), "smart",
+ expect("NAME=Alice"));
}
/** Test case for
@@ -423,7 +422,7 @@ public class CsvTest {
final String sql = "SELECT e.name\n"
+ "FROM emps AS e\n"
+ "WHERE e.empno in "
- + range(130, SqlToRelConverter.DEFAULT_IN_SUBQUERY_THRESHOLD);
+ + range(130, SqlToRelConverter.DEFAULT_IN_SUB_QUERY_THRESHOLD);
checkSql(sql, "smart", expect("NAME=Alice"));
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
----------------------------------------------------------------------
diff --git a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
index 2f4bbef..70c3cde 100644
--- a/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
+++ b/mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoRules.java
@@ -430,7 +430,7 @@ public class MongoRules {
}
implementor.newline(buf)
.append("FROM ");
- implementor.subquery(buf, 0, getChild(), "t");
+ implementor.subQuery(buf, 0, getChild(), "t");
if (program.getCondition() != null) {
implementor.newline(buf);
buf.append("WHERE ");
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/site/_docs/history.md
----------------------------------------------------------------------
diff --git a/site/_docs/history.md b/site/_docs/history.md
index 138ef45..51f11da 100644
--- a/site/_docs/history.md
+++ b/site/_docs/history.md
@@ -1011,7 +1011,7 @@ Bug fixes, API changes and minor enhancements
Type of 'Java<Long> * `INTEGER`' should be `BIGINT`
* [<a href="https://issues.apache.org/jira/browse/CALCITE-894">CALCITE-894</a>]
Do not generate redundant column alias for the left relation when
- translating `IN` subquery (Maryann Xue)
+ translating `IN` sub-query (Maryann Xue)
* [<a href="https://issues.apache.org/jira/browse/CALCITE-897">CALCITE-897</a>]
Enable debugging using "-Dcalcite.debug"
* [<a href="https://issues.apache.org/jira/browse/CALCITE-885">CALCITE-885</a>]
@@ -1137,7 +1137,7 @@ Bug fixes, API changes and minor enhancements
* [<a href="https://issues.apache.org/jira/browse/CALCITE-813">CALCITE-813</a>]
Upgrade `updateCount`, `maxRows` from int to long
* [<a href="https://issues.apache.org/jira/browse/CALCITE-714">CALCITE-714</a>]
- When de-correlating, push join condition into subquery
+ When de-correlating, push join condition into sub-query
* [<a href="https://issues.apache.org/jira/browse/CALCITE-751">CALCITE-751</a>]
Push aggregate with aggregate functions through join
* Add `RelBuilder.avg`
[3/3] calcite git commit: [CALCITE-1519] Standardize on "sub-query"
rather than "subquery" in class names and comments
Posted by jh...@apache.org.
[CALCITE-1519] Standardize on "sub-query" rather than "subquery" in class names and comments
There are lots of backward-compatible changes (e.g. leaving the old
name but deprecated) but the following changes are breaking (albeit
to APIs not widely used):
* public interface SubqueryConverter becomes SubQueryConverter
* public enum RelOptUtil.SubqueryType becomes SubQueryType
* public void SqlPrettyWriter.setSubqueryStyle() becomes setSubQueryStyle
* public void SqlToRelConverter.setSubqueryConverter() becomes setSubQueryConverter
* public boolean SqlToRelConverter.canConvertSubquery() becomes canConvertSubQuery
* public boolean SqlToRelConverter.convertSubquery() becomes convertSubQuery
* public SqlToRelConverter.Config.getInSubqueryThreshold() becomes getInSubQueryThreshold
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/e38d51e8
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/e38d51e8
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/e38d51e8
Branch: refs/heads/master
Commit: e38d51e8f4e61e32213aaeb39790e58069f718a4
Parents: 1ccebc8
Author: Julian Hyde <jh...@apache.org>
Authored: Wed Nov 30 15:21:51 2016 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Tue Dec 13 20:07:08 2016 -0800
----------------------------------------------------------------------
core/src/main/codegen/templates/Parser.jj | 144 +++---
.../org/apache/calcite/plan/RelOptUtil.java | 12 +-
.../org/apache/calcite/prepare/Prepare.java | 2 +-
.../org/apache/calcite/rel/core/Sample.java | 2 +-
.../apache/calcite/runtime/CalciteResource.java | 4 +-
.../java/org/apache/calcite/sql/SqlKind.java | 2 +-
.../org/apache/calcite/sql/SqlOperator.java | 2 +-
.../java/org/apache/calcite/sql/SqlSelect.java | 6 +-
.../java/org/apache/calcite/sql/SqlWriter.java | 8 +-
.../calcite/sql/advise/SqlSimpleParser.java | 26 +-
.../apache/calcite/sql/fun/SqlInOperator.java | 4 +-
.../calcite/sql/fun/SqlStdOperatorTable.java | 4 +-
.../sql/parser/SqlAbstractParserImpl.java | 12 +-
.../calcite/sql/pretty/SqlPrettyWriter.java | 24 +-
.../calcite/sql/validate/SelectNamespace.java | 2 +-
.../calcite/sql/validate/SqlValidatorImpl.java | 48 +-
.../sql/validate/SqlValidatorNamespace.java | 4 +-
.../apache/calcite/sql2rel/RelDecorrelator.java | 8 +-
.../calcite/sql2rel/SqlToRelConverter.java | 203 ++++----
.../calcite/sql2rel/SubQueryConverter.java | 53 ++
.../calcite/sql2rel/SubqueryConverter.java | 52 --
.../java/org/apache/calcite/tools/Programs.java | 9 +-
.../calcite/runtime/CalciteResource.properties | 2 +-
.../calcite/sql/parser/SqlParserTest.java | 12 +-
.../apache/calcite/sql/test/SqlAdvisorTest.java | 14 +-
.../calcite/sql/test/SqlOperatorBaseTest.java | 4 +-
.../calcite/sql/test/SqlPrettyWriterTest.java | 4 +-
.../apache/calcite/test/JdbcAdapterTest.java | 5 +-
.../java/org/apache/calcite/test/JdbcTest.java | 6 +-
.../apache/calcite/test/RelOptRulesTest.java | 3 +-
.../calcite/test/SqlToRelConverterTest.java | 5 +-
.../apache/calcite/test/SqlValidatorTest.java | 25 +-
.../calcite/sql/test/SqlPrettyWriterTest.xml | 2 +-
core/src/test/resources/sql/misc.iq | 6 +-
core/src/test/resources/sql/sub-query.iq | 513 +++++++++++++++++++
core/src/test/resources/sql/subquery.iq | 513 -------------------
.../java/org/apache/calcite/test/CsvTest.java | 13 +-
.../calcite/adapter/mongodb/MongoRules.java | 2 +-
site/_docs/history.md | 4 +-
39 files changed, 894 insertions(+), 870 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/codegen/templates/Parser.jj
----------------------------------------------------------------------
diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj
index bf03c10..4a0bc46 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -345,11 +345,11 @@ JAVACODE List startList(Object o)
* to keep query expressions (SELECT, UNION, etc) separate from row expressions
* (+, LIKE, etc). However, this is not possible with an LL(k) parser, because
* both kinds of expressions allow parenthesization, so no fixed amount of left
- * context is ever good enough. A subquery can be a leaf in a row expression,
+ * context is ever good enough. A sub-query can be a leaf in a row expression,
* and can include operators like UNION, so it's not even possible to use a
* syntactic lookahead rule like "look past an indefinite number of parentheses
* until you see SELECT, VALUES, or TABLE" (since at that point we still
- * don't know whether we're parsing a subquery like ((select ...) + x)
+ * don't know whether we're parsing a sub-query like ((select ...) + x)
* vs. (select ... union select ...).
*
* The somewhat messy solution is to unify the two kinds of expression,
@@ -389,8 +389,8 @@ JAVACODE SqlParserPos getPos()
JAVACODE void checkQueryExpression(ExprContext exprContext)
{
switch (exprContext) {
- case ACCEPT_NONQUERY:
- case ACCEPT_SUBQUERY:
+ case ACCEPT_NON_QUERY:
+ case ACCEPT_SUB_QUERY:
case ACCEPT_CURSOR:
throw SqlUtil.newContextException(getPos(),
RESOURCE.illegalQueryExpression());
@@ -710,9 +710,9 @@ SqlNode ParenthesizedExpression(ExprContext exprContext) :
<LPAREN>
{
// we've now seen left paren, so queries inside should
- // be allowed as subqueries
+ // be allowed as sub-queries
switch (exprContext) {
- case ACCEPT_SUBQUERY:
+ case ACCEPT_SUB_QUERY:
exprContext = ExprContext.ACCEPT_NONCURSOR;
break;
case ACCEPT_CURSOR:
@@ -739,7 +739,7 @@ SqlNode ParenthesizedExpression(ExprContext exprContext) :
*
* <code>WHERE x IN ((select count(*) from t where c=d),5)</code>,
*
- * which is a legal use of a subquery. The only way to fix the hole is to be
+ * which is a legal use of a sub-query. The only way to fix the hole is to be
* able to remember whether a subexpression was parenthesized or not, which
* means preserving parentheses in the SqlNode tree. This is probably
* desirable anyway for use in purely syntactic parsing applications (e.g. SQL
@@ -759,10 +759,10 @@ SqlNodeList ParenthesizedQueryOrCommaList(
<LPAREN>
{
// we've now seen left paren, so a query by itself should
- // be interpreted as a subquery
+ // be interpreted as a sub-query
pos = getPos();
switch (exprContext) {
- case ACCEPT_SUBQUERY:
+ case ACCEPT_SUB_QUERY:
firstExprContext = ExprContext.ACCEPT_NONCURSOR;
break;
case ACCEPT_CURSOR:
@@ -836,9 +836,9 @@ void Arg0(List list, ExprContext exprContext) :
final ExprContext firstExprContext;
{
// we've now seen left paren, so queries inside should
- // be allowed as subqueries
+ // be allowed as sub-queries
switch (exprContext) {
- case ACCEPT_SUBQUERY:
+ case ACCEPT_SUB_QUERY:
firstExprContext = ExprContext.ACCEPT_NONCURSOR;
break;
case ACCEPT_CURSOR:
@@ -1221,7 +1221,7 @@ SqlNode SqlProcedureCall() :
}
routineCall = NamedRoutineCall(
SqlFunctionCategory.USER_DEFINED_PROCEDURE,
- ExprContext.ACCEPT_SUBQUERY)
+ ExprContext.ACCEPT_SUB_QUERY)
{
return SqlStdOperatorTable.PROCEDURE_CALL.createCall(
callPos, routineCall);
@@ -1366,7 +1366,7 @@ SqlNode SqlUpdate() :
{
targetColumnList.add(id);
}
- <EQ> exp = Expression(ExprContext.ACCEPT_SUBQUERY)
+ <EQ> exp = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
// TODO: support DEFAULT also
sourceExpressionList.add(exp);
@@ -1377,7 +1377,7 @@ SqlNode SqlUpdate() :
{
targetColumnList.add(id);
}
- <EQ> exp = Expression(ExprContext.ACCEPT_SUBQUERY)
+ <EQ> exp = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
sourceExpressionList.add(exp);
}
@@ -1418,7 +1418,7 @@ SqlNode SqlMerge() :
<USING> sourceTableRef = TableRef()
- <ON> condition = Expression(ExprContext.ACCEPT_SUBQUERY)
+ <ON> condition = Expression(ExprContext.ACCEPT_SUB_QUERY)
(
LOOKAHEAD(2)
@@ -1450,7 +1450,7 @@ SqlUpdate WhenMatchedClause(SqlNode table, SqlIdentifier alias) :
updateExprList = new SqlNodeList(pos);
updateColumnList.add(id);
}
- <EQ> exp = Expression(ExprContext.ACCEPT_SUBQUERY)
+ <EQ> exp = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
updateExprList.add(exp);
}
@@ -1460,7 +1460,7 @@ SqlUpdate WhenMatchedClause(SqlNode table, SqlIdentifier alias) :
{
updateColumnList.add(id);
}
- <EQ> exp = Expression(ExprContext.ACCEPT_SUBQUERY)
+ <EQ> exp = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
updateExprList.add(exp);
}
@@ -1559,7 +1559,7 @@ SqlNode SelectExpression() :
return SqlIdentifier.star(getPos());
}
|
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
return e;
}
@@ -1613,7 +1613,7 @@ SqlNode JoinTable(SqlNode e) :
e2 = TableRef()
(
<ON> { pos = getPos(); }
- condition = Expression(ExprContext.ACCEPT_SUBQUERY) {
+ condition = Expression(ExprContext.ACCEPT_SUB_QUERY) {
SqlParserPos onPos = pos.plus(getPos());
return new SqlJoin(joinType.getParserPosition(),
e,
@@ -1682,7 +1682,7 @@ SqlNode FromClause() :
e2 = TableRef()
(
<ON> { pos = getPos(); }
- condition = Expression(ExprContext.ACCEPT_SUBQUERY) {
+ condition = Expression(ExprContext.ACCEPT_SUB_QUERY) {
SqlParserPos onPos = pos.plus(getPos());
e = new SqlJoin(joinType.getParserPosition(),
e,
@@ -1837,7 +1837,7 @@ SqlNode TableRef2(boolean lateral) :
}
|
<UNNEST> { pos = getPos(); }
- args = ParenthesizedQueryOrCommaList(ExprContext.ACCEPT_SUBQUERY)
+ args = ParenthesizedQueryOrCommaList(ExprContext.ACCEPT_SUB_QUERY)
[
<WITH> <ORDINALITY> {
unnestOp = SqlStdOperatorTable.UNNEST_WITH_ORDINALITY;
@@ -2107,7 +2107,7 @@ SqlNode RowConstructor() :
)
{
// REVIEW jvs 8-Feb-2004: Should we discriminate between scalar
- // subqueries inside of ROW and row subqueries? The standard does,
+ // sub-queries inside of ROW and row sub-queries? The standard does,
// but the distinction seems to be purely syntactic.
return SqlStdOperatorTable.ROW.createCall(pos, valueList.toArray());
}
@@ -2121,7 +2121,7 @@ SqlNode WhereOpt() :
SqlNode condition;
}
{
- <WHERE> condition = Expression(ExprContext.ACCEPT_SUBQUERY)
+ <WHERE> condition = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
return condition;
}
@@ -2178,12 +2178,12 @@ SqlNode GroupingElement() :
return SqlStdOperatorTable.GROUPING_SETS.createCall(pos, list);
}
| <ROLLUP> { pos = getPos(); }
- <LPAREN> nlist = ExpressionCommaList(pos, ExprContext.ACCEPT_SUBQUERY)
+ <LPAREN> nlist = ExpressionCommaList(pos, ExprContext.ACCEPT_SUB_QUERY)
<RPAREN> {
return SqlStdOperatorTable.ROLLUP.createCall(nlist);
}
| <CUBE> { pos = getPos(); }
- <LPAREN> nlist = ExpressionCommaList(pos, ExprContext.ACCEPT_SUBQUERY)
+ <LPAREN> nlist = ExpressionCommaList(pos, ExprContext.ACCEPT_SUB_QUERY)
<RPAREN> {
return SqlStdOperatorTable.CUBE.createCall(nlist);
}
@@ -2191,7 +2191,7 @@ SqlNode GroupingElement() :
<LPAREN> <RPAREN> {
return new SqlNodeList(getPos());
}
-| e = Expression(ExprContext.ACCEPT_SUBQUERY) {
+| e = Expression(ExprContext.ACCEPT_SUB_QUERY) {
return e;
}
}
@@ -2219,7 +2219,7 @@ SqlNodeList ExpressionCommaList(
// NOTE jvs 6-Feb-2004: See comments at top of file for why
// hint is necessary here.
LOOKAHEAD(2)
- <COMMA> e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ <COMMA> e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
list.add(e);
pos = pos.plus(getPos());
@@ -2238,7 +2238,7 @@ SqlNode HavingOpt() :
SqlNode e;
}
{
- <HAVING> e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ <HAVING> e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
return e;
}
@@ -2311,7 +2311,7 @@ SqlWindow WindowSpecification() :
<PARTITION>
{ pos = getPos(); }
<BY>
- partitionList = ExpressionCommaList(pos, ExprContext.ACCEPT_NONQUERY)
+ partitionList = ExpressionCommaList(pos, ExprContext.ACCEPT_NON_QUERY)
|
{ partitionList = SqlNodeList.EMPTY; }
)
@@ -2381,7 +2381,7 @@ SqlNode WindowRange() :
}
)
|
- e = Expression(ExprContext.ACCEPT_NONQUERY)
+ e = Expression(ExprContext.ACCEPT_NON_QUERY)
(
<PRECEDING>
{
@@ -2437,7 +2437,7 @@ SqlNode OrderItem() :
SqlNode e;
}
{
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
(
<ASC>
| <DESC> {
@@ -2470,7 +2470,7 @@ SqlNode SqlExpressionEof() :
SqlNode e;
}
{
- e = Expression(ExprContext.ACCEPT_SUBQUERY) (<EOF>)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY) (<EOF>)
{
return e;
}
@@ -2710,7 +2710,7 @@ List<Object> Expression2(ExprContext exprContext) :
<ASYMMETRIC>
]
)
- e = Expression3(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression3(ExprContext.ACCEPT_SUB_QUERY)
{
list.add(new SqlParserUtil.ToTreeListItem(op, pos));
list.add(e);
@@ -2732,14 +2732,14 @@ List<Object> Expression2(ExprContext exprContext) :
|
<SIMILAR> <TO> { op = SqlStdOperatorTable.SIMILAR_TO; }
)
- list2 = Expression2(ExprContext.ACCEPT_SUBQUERY)
+ list2 = Expression2(ExprContext.ACCEPT_SUB_QUERY)
{
list.add(new SqlParserUtil.ToTreeListItem(op, pos));
list.addAll(list2);
}
[
LOOKAHEAD(2)
- <ESCAPE> e = Expression3(ExprContext.ACCEPT_SUBQUERY)
+ <ESCAPE> e = Expression3(ExprContext.ACCEPT_SUB_QUERY)
{
pos = getPos();
list.add(
@@ -2754,10 +2754,10 @@ List<Object> Expression2(ExprContext exprContext) :
checkNonQueryExpression(exprContext);
list.add(new SqlParserUtil.ToTreeListItem(op, getPos()));
}
- Expression2b(ExprContext.ACCEPT_SUBQUERY, list)
+ Expression2b(ExprContext.ACCEPT_SUB_QUERY, list)
|
<LBRACKET>
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
<RBRACKET>
{
list.add(
@@ -2965,23 +2965,23 @@ SqlNode CaseExpression() :
pos = getPos();
}
[
- caseIdentifier = Expression(ExprContext.ACCEPT_SUBQUERY)
+ caseIdentifier = Expression(ExprContext.ACCEPT_SUB_QUERY)
]
(
<WHEN>
{ whenPos = getPos(); }
- e = ExpressionCommaList(pos, ExprContext.ACCEPT_SUBQUERY)
+ e = ExpressionCommaList(pos, ExprContext.ACCEPT_SUB_QUERY)
{
if (((SqlNodeList) e).size() == 1) {
e = ((SqlNodeList) e).get(0);
}
whenList.add(e);
}
- <THEN> e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ <THEN> e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{ thenPos = getPos(); thenList.add(e); }
) +
[
- <ELSE> elseClause = Expression(ExprContext.ACCEPT_SUBQUERY)
+ <ELSE> elseClause = Expression(ExprContext.ACCEPT_SUB_QUERY)
]
<END>
{
@@ -3447,9 +3447,9 @@ SqlNode MultisetConstructor() :
|
// by enumeration "MULTISET[e0, e1, ..., eN]"
<LBRACKET> // TODO: do trigraph as well ??( ??)
- e = Expression(ExprContext.ACCEPT_NONQUERY) { args = startList(e); }
+ e = Expression(ExprContext.ACCEPT_NON_QUERY) { args = startList(e); }
(
- <COMMA> e = Expression(ExprContext.ACCEPT_NONQUERY) { args.add(e); }
+ <COMMA> e = Expression(ExprContext.ACCEPT_NON_QUERY) { args.add(e); }
) *
<RBRACKET>
{
@@ -3482,7 +3482,7 @@ SqlNode ArrayConstructor() :
// by enumeration "ARRAY[e0, e1, ..., eN]"
<LBRACKET> // TODO: do trigraph as well ??( ??)
(
- args = ExpressionCommaList(pos, ExprContext.ACCEPT_NONQUERY)
+ args = ExpressionCommaList(pos, ExprContext.ACCEPT_NON_QUERY)
|
{ args = new SqlNodeList(getPos()); }
)
@@ -3517,7 +3517,7 @@ SqlNode MapConstructor() :
// by enumeration "MAP[k0, v0, ..., kN, vN]"
<LBRACKET> // TODO: do trigraph as well ??( ??)
(
- args = ExpressionCommaList(pos, ExprContext.ACCEPT_NONQUERY)
+ args = ExpressionCommaList(pos, ExprContext.ACCEPT_NON_QUERY)
|
{ args = new SqlNodeList(getPos()); }
)
@@ -3879,7 +3879,7 @@ SqlNode NewSpecification() :
routineCall =
NamedRoutineCall(
SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR,
- ExprContext.ACCEPT_SUBQUERY)
+ ExprContext.ACCEPT_SUB_QUERY)
{
return SqlStdOperatorTable.NEW.createCall(callPos, routineCall);
}
@@ -4216,7 +4216,7 @@ SqlNode BuiltinFunctionCall() :
{
pos = getPos();
}
- <LPAREN> e = Expression(ExprContext.ACCEPT_SUBQUERY) { args = startList(e); }
+ <LPAREN> e = Expression(ExprContext.ACCEPT_SUB_QUERY) { args = startList(e); }
<AS>
(
dt = DataType() { args.add(dt); }
@@ -4239,7 +4239,7 @@ SqlNode BuiltinFunctionCall() :
unit = TimeUnit()
{ args = startList(new SqlIntervalQualifier(unit, null, getPos())); }
<FROM>
- e = Expression(ExprContext.ACCEPT_SUBQUERY) { args.add(e); }
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY) { args.add(e); }
<RPAREN>
{
return SqlStdOperatorTable.EXTRACT.createCall(
@@ -4254,14 +4254,14 @@ SqlNode BuiltinFunctionCall() :
}
<LPAREN>
// FIXME jvs 31-Aug-2006: FRG-192: This should be
- // Expression(ExprContext.ACCEPT_SUBQUERY), but that doesn't work
+ // Expression(ExprContext.ACCEPT_SUB_QUERY), but that doesn't work
// because it matches the other kind of IN.
e = AtomicRowExpression() { args = startList(e); }
<IN>
- e = Expression(ExprContext.ACCEPT_SUBQUERY) { args.add(e);}
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY) { args.add(e);}
[
<FROM>
- e = Expression(ExprContext.ACCEPT_SUBQUERY) { args.add(e); }
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY) { args.add(e); }
]
<RPAREN>
{
@@ -4276,7 +4276,7 @@ SqlNode BuiltinFunctionCall() :
pos = getPos();
}
<LPAREN>
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
args = startList(e);
}
@@ -4298,7 +4298,7 @@ SqlNode BuiltinFunctionCall() :
pos = getPos();
}
<LPAREN>
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
args = startList(e);
}
@@ -4313,7 +4313,7 @@ SqlNode BuiltinFunctionCall() :
}
|
(
- <COMMA> e = Expression(ExprContext.ACCEPT_SUBQUERY) {
+ <COMMA> e = Expression(ExprContext.ACCEPT_SUB_QUERY) {
args.add(e);
}
)*
@@ -4330,23 +4330,23 @@ SqlNode BuiltinFunctionCall() :
pos = getPos();
}
<LPAREN>
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
args = startList(e);
}
<PLACING>
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
args.add(e);
}
<FROM>
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
args.add(e);
}
[
<FOR>
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
args.add(e);
}
@@ -4376,14 +4376,14 @@ SqlNode BuiltinFunctionCall() :
pos = getPos();
}
<LPAREN>
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{ args = startList(e); }
( <FROM> | <COMMA>)
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{ args.add(e); }
[
(<FOR> | <COMMA>)
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{ args.add(e); }
]
<RPAREN>
@@ -4422,7 +4422,7 @@ SqlNode BuiltinFunctionCall() :
flag = SqlTrimFunction.Flag.LEADING.symbol(pos);
}
]
- [ trimChars = Expression(ExprContext.ACCEPT_SUBQUERY) ]
+ [ trimChars = Expression(ExprContext.ACCEPT_SUB_QUERY) ]
(
<FROM>
{
@@ -4446,7 +4446,7 @@ SqlNode BuiltinFunctionCall() :
}
)
]
- e = Expression(ExprContext.ACCEPT_SUBQUERY)
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
if (flag == null) {
flag = SqlTrimFunction.Flag.BOTH.symbol(SqlParserPos.ZERO);
@@ -4489,9 +4489,9 @@ SqlCall TimestampAddFunctionCall() :
args = startList(SqlLiteral.createSymbol(interval, getPos()));
}
<COMMA>
- e = Expression(ExprContext.ACCEPT_SUBQUERY) { args.add(e); }
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY) { args.add(e); }
<COMMA>
- e = Expression(ExprContext.ACCEPT_SUBQUERY) { args.add(e); }
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY) { args.add(e); }
<RPAREN> {
return SqlStdOperatorTable.TIMESTAMP_ADD.createCall(
pos.plus(getPos()), SqlParserUtil.toNodeArray(args));
@@ -4518,9 +4518,9 @@ SqlCall TimestampDiffFunctionCall() :
args = startList(SqlLiteral.createSymbol(interval, getPos()));
}
<COMMA>
- e = Expression(ExprContext.ACCEPT_SUBQUERY) { args.add(e); }
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY) { args.add(e); }
<COMMA>
- e = Expression(ExprContext.ACCEPT_SUBQUERY) { args.add(e); }
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY) { args.add(e); }
<RPAREN> {
return SqlStdOperatorTable.TIMESTAMP_DIFF.createCall(
pos.plus(getPos()), SqlParserUtil.toNodeArray(args));
@@ -4578,7 +4578,7 @@ SqlNode NamedFunctionCall() :
args = Collections.emptyList();
pos = pos.plus(getPos());
}
- | args = FunctionParameterList(ExprContext.ACCEPT_SUBQUERY)
+ | args = FunctionParameterList(ExprContext.ACCEPT_SUB_QUERY)
{
pos = pos.plus(getPos());
quantifier = (SqlLiteral) args.get(0);
@@ -4589,7 +4589,7 @@ SqlNode NamedFunctionCall() :
<FILTER> { filterPos = getPos(); }
<LPAREN>
<WHERE>
- filter = Expression(ExprContext.ACCEPT_SUBQUERY)
+ filter = Expression(ExprContext.ACCEPT_SUB_QUERY)
<RPAREN> { filterPos = filterPos.plus(getPos()); }
]
[
@@ -4637,7 +4637,7 @@ SqlNode StandardFloorCeilOptions(SqlParserPos pos, boolean floorFlag) :
boolean over = false;
}
{
- <LPAREN> e = Expression(ExprContext.ACCEPT_SUBQUERY) {
+ <LPAREN> e = Expression(ExprContext.ACCEPT_SUB_QUERY) {
args = startList(e);
}
(
@@ -4820,7 +4820,7 @@ SqlNode JdbcFunctionCall() :
|
<CONVERT> { name = unquotedIdentifier(); }
<LPAREN>
- e = Expression(ExprContext.ACCEPT_SUBQUERY) {
+ e = Expression(ExprContext.ACCEPT_SUB_QUERY) {
args = new SqlNodeList(getPos());
args.add(e);
}
@@ -4851,7 +4851,7 @@ SqlNode JdbcFunctionCall() :
|
LOOKAHEAD(2) <LPAREN> <RPAREN> { args = new SqlNodeList(pos); }
|
- args = ParenthesizedQueryOrCommaList(ExprContext.ACCEPT_SUBQUERY)
+ args = ParenthesizedQueryOrCommaList(ExprContext.ACCEPT_SUB_QUERY)
)
)
<RBRACE> {
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
index b03c544..bf24a41 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
@@ -442,7 +442,7 @@ public abstract class RelOptUtil {
assert extraExpr == rexBuilder.makeLiteral(true);
// this should only be called for the exists case
- // first stick an Agg on top of the subquery
+ // first stick an Agg on top of the sub-query
// agg does not like no agg functions so just pretend it is
// doing a min(TRUE)
@@ -474,7 +474,7 @@ public abstract class RelOptUtil {
*
* @param seekRel A query rel, for example the resulting rel from 'select *
* from emp' or 'values (1,2,3)' or '('Foo', 34)'.
- * @param subqueryType Sub-query type
+ * @param subQueryType Sub-query type
* @param logic Whether to use 2- or 3-valued boolean logic
* @param notIn Whether the operator is NOT IN
*
@@ -485,10 +485,10 @@ public abstract class RelOptUtil {
*/
public static Exists createExistsPlan(
RelNode seekRel,
- SubqueryType subqueryType,
+ SubQueryType subQueryType,
Logic logic,
boolean notIn) {
- switch (subqueryType) {
+ switch (subQueryType) {
case SCALAR:
return new Exists(seekRel, false, true);
}
@@ -516,7 +516,7 @@ public abstract class RelOptUtil {
// for IN/NOT IN, it needs to output the fields
final List<RexNode> exprs = new ArrayList<>();
- if (subqueryType == SubqueryType.IN) {
+ if (subQueryType == SubQueryType.IN) {
for (int i = 0; i < keyCount; i++) {
exprs.add(rexBuilder.makeInputRef(ret, i));
}
@@ -3628,7 +3628,7 @@ public abstract class RelOptUtil {
}
/** What kind of sub-query. */
- public enum SubqueryType {
+ public enum SubQueryType {
EXISTS,
IN,
SCALAR
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/prepare/Prepare.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/prepare/Prepare.java b/core/src/main/java/org/apache/calcite/prepare/Prepare.java
index aa4ba8b..b5ceec8 100644
--- a/core/src/main/java/org/apache/calcite/prepare/Prepare.java
+++ b/core/src/main/java/org/apache/calcite/prepare/Prepare.java
@@ -268,7 +268,7 @@ public abstract class Prepare {
root = root.withRel(flattenTypes(root.rel, true));
if (this.context.config().forceDecorrelate()) {
- // Subquery decorrelation.
+ // Sub-query decorrelation.
root = root.withRel(decorrelate(sqlToRelConverter, sqlQuery, root.rel));
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/rel/core/Sample.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Sample.java b/core/src/main/java/org/apache/calcite/rel/core/Sample.java
index e22e0de..9005001 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Sample.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Sample.java
@@ -31,7 +31,7 @@ import java.util.List;
* Relational expression that returns a sample of the rows from its input.
*
* <p>In SQL, a sample is expressed using the {@code TABLESAMPLE BERNOULLI} or
- * {@code SYSTEM} keyword applied to a table, view or subquery.
+ * {@code SYSTEM} keyword applied to a table, view or sub-query.
*/
public class Sample extends SingleRel {
//~ Instance fields --------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
index da3e519..77a6bf9 100644
--- a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
+++ b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
@@ -413,8 +413,8 @@ public interface CalciteResource {
@BaseMessage("The {0} function does not support the {1} data type.")
ExInst<SqlValidatorException> minMaxBadType(String a0, String a1);
- @BaseMessage("Only scalar subqueries allowed in select list.")
- ExInst<SqlValidatorException> onlyScalarSubqueryAllowed();
+ @BaseMessage("Only scalar sub-queries allowed in select list.")
+ ExInst<SqlValidatorException> onlyScalarSubQueryAllowed();
@BaseMessage("Ordinal out of range")
ExInst<SqlValidatorException> orderByOrdinalOutOfRange();
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql/SqlKind.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlKind.java b/core/src/main/java/org/apache/calcite/sql/SqlKind.java
index 3300f00..2f6b5fd 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlKind.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlKind.java
@@ -419,7 +419,7 @@ public enum SqlKind {
EXPLICIT_TABLE,
/**
- * Scalar query; that is, a subquery used in an expression context, and
+ * Scalar query; that is, a sub-query used in an expression context, and
* returning one row and one column.
*/
SCALAR_QUERY,
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql/SqlOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlOperator.java
index 3d84004..d558fce 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlOperator.java
@@ -900,7 +900,7 @@ public abstract class SqlOperator {
* be scalar (as opposed to a query).
*
* <p>If true (the default), the validator will attempt to convert the
- * argument into a scalar subquery, which must have one column and return at
+ * argument into a scalar sub-query, which must have one column and return at
* most one row.
*
* <p>Operators such as <code>SELECT</code> and <code>EXISTS</code> override
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql/SqlSelect.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlSelect.java b/core/src/main/java/org/apache/calcite/sql/SqlSelect.java
index c054763..bb847bc 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlSelect.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlSelect.java
@@ -208,11 +208,11 @@ public class SqlSelect extends SqlCall {
validator.validateQuery(this, scope, validator.getUnknownType());
}
- // Override SqlCall, to introduce a subquery frame.
+ // Override SqlCall, to introduce a sub-query frame.
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
if (!writer.inQuery()) {
- // If this SELECT is the topmost item in a subquery, introduce a new
- // frame. (The topmost item in the subquery might be a UNION or
+ // If this SELECT is the topmost item in a sub-query, introduce a new
+ // frame. (The topmost item in the sub-query might be a UNION or
// ORDER. In this case, we don't need a wrapper frame.)
final SqlWriter.Frame frame =
writer.startList(SqlWriter.FrameTypeEnum.SUB_QUERY, "(", ")");
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql/SqlWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlWriter.java b/core/src/main/java/org/apache/calcite/sql/SqlWriter.java
index bd961ae..3d09138 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlWriter.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlWriter.java
@@ -28,11 +28,11 @@ public interface SqlWriter {
//~ Enums ------------------------------------------------------------------
/**
- * Style of formatting subqueries.
+ * Style of formatting sub-queries.
*/
- enum SubqueryStyle {
+ enum SubQueryStyle {
/**
- * Julian's style of subquery nesting. Like this:
+ * Julian's style of sub-query nesting. Like this:
*
* <pre>SELECT *
* FROM (
@@ -44,7 +44,7 @@ public interface SqlWriter {
HYDE,
/**
- * Damian's style of subquery nesting. Like this:
+ * Damian's style of sub-query nesting. Like this:
*
* <pre>SELECT *
* FROM
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql/advise/SqlSimpleParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/advise/SqlSimpleParser.java b/core/src/main/java/org/apache/calcite/sql/advise/SqlSimpleParser.java
index 0ad0d32..85dfa10 100644
--- a/core/src/main/java/org/apache/calcite/sql/advise/SqlSimpleParser.java
+++ b/core/src/main/java/org/apache/calcite/sql/advise/SqlSimpleParser.java
@@ -75,7 +75,7 @@ public class SqlSimpleParser {
},
/**
- * A token created by reducing an entire subquery.
+ * A token created by reducing an entire sub-query.
*/
QUERY;
@@ -140,7 +140,7 @@ public class SqlSimpleParser {
list.add(token);
}
- // Gather consecutive sub-sequences of tokens into subqueries.
+ // Gather consecutive sub-sequences of tokens into sub-queries.
List<Token> outList = new ArrayList<Token>();
consumeQuery(list.listIterator(), outList);
@@ -193,18 +193,18 @@ public class SqlSimpleParser {
private void consumeSelect(ListIterator<Token> iter, List<Token> outList) {
boolean isQuery = false;
int start = outList.size();
- List<Token> subqueryList = new ArrayList<Token>();
+ List<Token> subQueryList = new ArrayList<Token>();
loop:
while (iter.hasNext()) {
Token token = iter.next();
- subqueryList.add(token);
+ subQueryList.add(token);
switch (token.type) {
case LPAREN:
- consumeQuery(iter, subqueryList);
+ consumeQuery(iter, subQueryList);
break;
case RPAREN:
if (isQuery) {
- subqueryList.remove(subqueryList.size() - 1);
+ subQueryList.remove(subQueryList.size() - 1);
}
break loop;
case SELECT:
@@ -213,7 +213,7 @@ public class SqlSimpleParser {
case UNION:
case INTERSECT:
case EXCEPT:
- subqueryList.remove(subqueryList.size() - 1);
+ subQueryList.remove(subQueryList.size() - 1);
iter.previous();
break loop;
default:
@@ -223,14 +223,14 @@ public class SqlSimpleParser {
// Fell off end of list. Pretend we saw the required right-paren.
if (isQuery) {
outList.subList(start, outList.size()).clear();
- outList.add(new Query(subqueryList));
+ outList.add(new Query(subQueryList));
if ((outList.size() >= 2)
&& (outList.get(outList.size() - 2).type == TokenType.LPAREN)) {
outList.add(new Token(TokenType.RPAREN));
}
} else {
// not a query - just a parenthesized expr
- outList.addAll(subqueryList);
+ outList.addAll(subQueryList);
}
}
@@ -479,7 +479,7 @@ public class SqlSimpleParser {
public Query simplify(String hintToken) {
TokenType clause = TokenType.SELECT;
TokenType foundInClause = null;
- Query foundInSubquery = null;
+ Query foundInSubQuery = null;
TokenType majorClause = null;
if (hintToken != null) {
for (Token token : tokenList) {
@@ -511,7 +511,7 @@ public class SqlSimpleParser {
case QUERY:
if (((Query) token).contains(hintToken)) {
foundInClause = clause;
- foundInSubquery = (Query) token;
+ foundInSubQuery = (Query) token;
}
break;
}
@@ -566,7 +566,7 @@ public class SqlSimpleParser {
case QUERY:
// Indicates that the expression to be simplified is
- // outside this subquery. Preserve a simplified SELECT
+ // outside this sub-query. Preserve a simplified SELECT
// clause.
purgeSelectExprsKeepAliases();
purgeWhere();
@@ -581,7 +581,7 @@ public class SqlSimpleParser {
case QUERY: {
Query query = (Query) token;
query.simplify(
- (query == foundInSubquery) ? hintToken : null);
+ (query == foundInSubQuery) ? hintToken : null);
break;
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java
index 716902b..2b80173 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlInOperator.java
@@ -45,7 +45,7 @@ import static org.apache.calcite.util.Static.RESOURCE;
/**
* Definition of the SQL <code>IN</code> operator, which tests for a value's
- * membership in a subquery or a list of values.
+ * membership in a sub-query or a list of values.
*/
public class SqlInOperator extends SqlBinaryOperator {
//~ Instance fields --------------------------------------------------------
@@ -183,7 +183,7 @@ public class SqlInOperator extends SqlBinaryOperator {
public boolean argumentMustBeScalar(int ordinal) {
// Argument #0 must be scalar, argument #1 can be a list (1, 2) or
// a query (select deptno from emp). So, only coerce argument #0 into
- // a scalar subquery. For example, in
+ // a scalar sub-query. For example, in
// select * from emp
// where (select count(*) from dept) in (select deptno from dept)
// we should coerce the LHS to a scalar.
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
index 3bbb425..18f48d2 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java
@@ -342,13 +342,13 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable {
OperandTypes.COMPARABLE_ORDERED_COMPARABLE_ORDERED);
/**
- * <code>IN</code> operator tests for a value's membership in a subquery or
+ * <code>IN</code> operator tests for a value's membership in a sub-query or
* a list of values.
*/
public static final SqlBinaryOperator IN = new SqlInOperator(false);
/**
- * <code>NOT IN</code> operator tests for a value's membership in a subquery
+ * <code>NOT IN</code> operator tests for a value's membership in a sub-query
* or a list of values.
*/
public static final SqlBinaryOperator NOT_IN =
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java b/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java
index ad605da..45f004f 100644
--- a/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java
@@ -304,19 +304,25 @@ public abstract class SqlAbstractParserImpl {
/**
* Accept only non-query expressions in this context.
*/
- ACCEPT_NONQUERY,
+ ACCEPT_NON_QUERY,
/**
* Accept only parenthesized queries or non-query expressions in this
* context.
*/
- ACCEPT_SUBQUERY,
+ ACCEPT_SUB_QUERY,
/**
* Accept only CURSOR constructors, parenthesized queries, or non-query
* expressions in this context.
*/
- ACCEPT_CURSOR
+ ACCEPT_CURSOR;
+
+ @Deprecated // to be removed before 2.0
+ public static final ExprContext ACCEPT_SUBQUERY = ACCEPT_SUB_QUERY;
+
+ @Deprecated // to be removed before 2.0
+ public static final ExprContext ACCEPT_NONQUERY = ACCEPT_NON_QUERY;
}
//~ Instance fields --------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
index a1f719b..e212a5d 100644
--- a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
+++ b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
@@ -103,12 +103,12 @@ import java.util.Set;
* <td>false</td>
* </tr>
* <tr>
- * <td>{@link #setSubqueryStyle SubqueryStyle}</td>
+ * <td>{@link #setSubQueryStyle SubQueryStyle}</td>
* <td>Style for formatting sub-queries. Values are:
- * {@link org.apache.calcite.sql.SqlWriter.SubqueryStyle#HYDE Hyde},
- * {@link org.apache.calcite.sql.SqlWriter.SubqueryStyle#BLACK Black}.</td>
+ * {@link org.apache.calcite.sql.SqlWriter.SubQueryStyle#HYDE Hyde},
+ * {@link org.apache.calcite.sql.SqlWriter.SubQueryStyle#BLACK Black}.</td>
*
- * <td>{@link org.apache.calcite.sql.SqlWriter.SubqueryStyle#HYDE Hyde}</td>
+ * <td>{@link org.apache.calcite.sql.SqlWriter.SubQueryStyle#HYDE Hyde}</td>
* </tr>
* <tr>
* <td>{@link #setLineLength LineLength}</td>
@@ -153,7 +153,7 @@ public class SqlPrettyWriter implements SqlWriter {
private boolean windowDeclListNewline;
private boolean updateSetListNewline;
private boolean windowNewline;
- private SubqueryStyle subqueryStyle;
+ private SubQueryStyle subQueryStyle;
private boolean whereListItemsOnSeparateLines;
private boolean caseClausesOnNewLines;
@@ -197,11 +197,11 @@ public class SqlPrettyWriter implements SqlWriter {
}
/**
- * Sets the subquery style. Default is
- * {@link org.apache.calcite.sql.SqlWriter.SubqueryStyle#HYDE}.
+ * Sets the sub-query style. Default is
+ * {@link org.apache.calcite.sql.SqlWriter.SubQueryStyle#HYDE}.
*/
- public void setSubqueryStyle(SubqueryStyle subqueryStyle) {
- this.subqueryStyle = subqueryStyle;
+ public void setSubQueryStyle(SubQueryStyle subQueryStyle) {
+ this.subQueryStyle = subQueryStyle;
}
public void setWindowNewline(boolean windowNewline) {
@@ -266,7 +266,7 @@ public class SqlPrettyWriter implements SqlWriter {
windowDeclListNewline = true;
updateSetListNewline = true;
windowNewline = false;
- subqueryStyle = SubqueryStyle.HYDE;
+ subQueryStyle = SubQueryStyle.HYDE;
alwaysUseParentheses = false;
whereListItemsOnSeparateLines = false;
lineLength = 0;
@@ -512,7 +512,7 @@ public class SqlPrettyWriter implements SqlWriter {
false);
case SUB_QUERY:
- switch (subqueryStyle) {
+ switch (subQueryStyle) {
case BLACK:
// Generate, e.g.:
@@ -559,7 +559,7 @@ public class SqlPrettyWriter implements SqlWriter {
}
};
default:
- throw Util.unexpected(subqueryStyle);
+ throw Util.unexpected(subQueryStyle);
}
case ORDER_BY:
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql/validate/SelectNamespace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SelectNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/SelectNamespace.java
index c0a2dec..a01227b 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SelectNamespace.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SelectNamespace.java
@@ -22,7 +22,7 @@ import org.apache.calcite.sql.SqlSelect;
import org.apache.calcite.sql.type.SqlTypeUtil;
/**
- * Namespace offered by a subquery.
+ * Namespace offered by a sub-query.
*
* @see SelectScope
* @see SetopNamespace
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/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 c2c24c3..eac1b20 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
@@ -1975,7 +1975,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
if (newRight != right) {
join.setRight(newRight);
}
- registerSubqueries(joinScope, join.getCondition());
+ registerSubQueries(joinScope, join.getCondition());
final JoinNamespace joinNamespace = new JoinNamespace(this, join);
registerNamespace(null, null, joinNamespace, forceNullable);
return join;
@@ -2205,7 +2205,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
// Start by registering the WHERE clause
whereScopes.put(select, selectScope);
- registerOperandSubqueries(
+ registerOperandSubQueries(
selectScope,
select,
SqlSelect.WHERE_OPERAND);
@@ -2240,12 +2240,12 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
} else {
selectScopes.put(select, selectScope);
}
- registerSubqueries(selectScope, select.getGroup());
- registerOperandSubqueries(
+ registerSubQueries(selectScope, select.getGroup());
+ registerOperandSubQueries(
aggScope,
select,
SqlSelect.HAVING_OPERAND);
- registerSubqueries(aggScope, select.getSelectList());
+ registerSubQueries(aggScope, select.getSelectList());
final SqlNodeList orderList = select.getOrderList();
if (orderList != null) {
// If the query is 'SELECT DISTINCT', restrict the columns
@@ -2257,7 +2257,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
OrderByScope orderScope =
new OrderByScope(aggScope, orderList, select);
orderScopes.put(select, orderScope);
- registerSubqueries(orderScope, orderList);
+ registerSubQueries(orderScope, orderList);
if (!isAggregate(select)) {
// Since this is not an aggregating query,
@@ -2326,9 +2326,9 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
assert operands.get(i).getKind() == SqlKind.ROW;
// FIXME jvs 9-Feb-2005: Correlation should
- // be illegal in these subqueries. Same goes for
+ // be illegal in these sub-queries. Same goes for
// any non-lateral SELECT in the FROM list.
- registerOperandSubqueries(parentScope, call, i);
+ registerOperandSubQueries(parentScope, call, i);
}
break;
@@ -2442,7 +2442,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
alias,
unnestNs,
forceNullable);
- registerOperandSubqueries(parentScope, call, 0);
+ registerOperandSubQueries(parentScope, call, 0);
scopes.put(node, parentScope);
break;
@@ -2459,7 +2459,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
alias,
procNs,
forceNullable);
- registerSubqueries(parentScope, call);
+ registerSubQueries(parentScope, call);
break;
case MULTISET_QUERY_CONSTRUCTOR:
@@ -2477,7 +2477,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
forceNullable);
operands = call.getOperandList();
for (int i = 0; i < operands.size(); i++) {
- registerOperandSubqueries(parentScope, call, i);
+ registerOperandSubQueries(parentScope, call, i);
}
break;
@@ -2607,7 +2607,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
}
}
- private void registerSubqueries(
+ private void registerSubQueries(
SqlValidatorScope parentScope,
SqlNode node) {
if (node == null) {
@@ -2621,7 +2621,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
validateNodeFeature(node);
SqlCall call = (SqlCall) node;
for (int i = 0; i < call.operandCount(); i++) {
- registerOperandSubqueries(parentScope, call, i);
+ registerOperandSubQueries(parentScope, call, i);
}
} else if (node instanceof SqlNodeList) {
SqlNodeList list = (SqlNodeList) node;
@@ -2634,7 +2634,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
listNode);
list.set(i, listNode);
}
- registerSubqueries(parentScope, listNode);
+ registerSubQueries(parentScope, listNode);
}
} else {
// atomic node -- can be ignored
@@ -2642,15 +2642,15 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
}
/**
- * Registers any subqueries inside a given call operand, and converts the
- * operand to a scalar subquery if the operator requires it.
+ * Registers any sub-queries inside a given call operand, and converts the
+ * operand to a scalar sub-query if the operator requires it.
*
* @param parentScope Parent scope
* @param call Call
* @param operandOrdinal Ordinal of operand within call
* @see SqlOperator#argumentMustBeScalar(int)
*/
- private void registerOperandSubqueries(
+ private void registerOperandSubQueries(
SqlValidatorScope parentScope,
SqlCall call,
int operandOrdinal) {
@@ -2666,7 +2666,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
operand);
call.setOperand(operandOrdinal, operand);
}
- registerSubqueries(parentScope, operand);
+ registerSubQueries(parentScope, operand);
}
public void validateIdentifier(SqlIdentifier id, SqlValidatorScope scope) {
@@ -2816,7 +2816,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
/**
* Validates the FROM clause of a query, or (recursively) a child node of
- * the FROM clause: AS, OVER, JOIN, VALUES, or subquery.
+ * the FROM clause: AS, OVER, JOIN, VALUES, or sub-query.
*
* @param node Node in FROM clause, typically a table or derived
* table
@@ -3603,7 +3603,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
}
getRawSelectScope(select).setExpandedSelectList(expandedSelectItems);
- // TODO: when SELECT appears as a value subquery, should be using
+ // TODO: when SELECT appears as a value sub-query, should be using
// something other than unknownType for targetRowType
inferUnknownTypes(targetRowType, selectScope, newSelectList);
@@ -3640,7 +3640,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
/**
* Processes SubQuery found in Select list. Checks that is actually Scalar
- * subquery and makes proper entries in each of the 3 lists used to create
+ * sub-query and makes proper entries in each of the 3 lists used to create
* the final rowType entry.
*
* @param parentSelect base SqlSelect item
@@ -3655,10 +3655,10 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
List<SqlNode> expandedSelectItems,
Set<String> aliasList,
List<Map.Entry<String, RelDataType>> fieldList) {
- // A scalar subquery only has one output column.
+ // A scalar sub-query only has one output column.
if (1 != selectItem.getSelectList().size()) {
throw newValidationError(selectItem,
- RESOURCE.onlyScalarSubqueryAllowed());
+ RESOURCE.onlyScalarSubQueryAllowed());
}
// No expansion in this routine just append to list.
@@ -3677,7 +3677,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
// we do not want to pass on the RelRecordType returned
// by the sub query. Just the type of the single expression
- // in the subquery select list.
+ // in the sub-query select list.
assert type instanceof RelRecordType;
RelRecordType rec = (RelRecordType) type;
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorNamespace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorNamespace.java
index db9fd3a..2e2af29 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorNamespace.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorNamespace.java
@@ -30,8 +30,8 @@ import java.util.List;
* and DEPT, and a row type consisting of the combined columns of those tables.
*
* <p>Other examples of namespaces include a table in the from list (the
- * namespace contains the constituent columns) and a subquery (the namespace
- * contains the columns in the SELECT clause of the subquery).
+ * namespace contains the constituent columns) and a sub-query (the namespace
+ * contains the columns in the SELECT clause of the sub-query).
*
* <p>These various kinds of namespace are implemented by classes
* {@link IdentifierNamespace} for table names, {@link SelectNamespace} for
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
index 5f8f8c5..41e262b 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
@@ -1402,11 +1402,11 @@ public class RelDecorrelator implements ReflectiveVisitor {
// Construct a CASE expression to handle the null indicator.
//
- // This also covers the case where a left correlated subquery
+ // This also covers the case where a left correlated sub-query
// projects fields from outer relation. Since LOJ cannot produce
// nulls on the LHS, the projection now need to make a nullable LHS
// reference using a nullability indicator. If this this indicator
- // is null, it means the subquery does not produce any value. As a
+ // is null, it means the sub-query does not produce any value. As a
// result, any RHS ref by this usbquery needs to produce null value.
// WHEN indicator IS NULL
@@ -1600,7 +1600,7 @@ public class RelDecorrelator implements ReflectiveVisitor {
// check projRel only projects one expression
// check this project only projects one expression, i.e. scalar
- // subqueries.
+ // sub-queries.
List<RexNode> projExprs = project.getProjects();
if (projExprs.size() != 1) {
return;
@@ -1677,7 +1677,7 @@ public class RelDecorrelator implements ReflectiveVisitor {
}
// check this project only projects one expression, i.e. scalar
- // subqueries.
+ // sub-queries.
if (project.getProjects().size() != 1) {
return;
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index c654d31..a712a7c 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -209,7 +209,11 @@ public class SqlToRelConverter {
/** Size of the smallest IN list that will be converted to a semijoin to a
* static table. */
- public static final int DEFAULT_IN_SUBQUERY_THRESHOLD = 20;
+ public static final int DEFAULT_IN_SUB_QUERY_THRESHOLD = 20;
+
+ @Deprecated // to be removed before 2.0
+ public static final int DEFAULT_IN_SUBQUERY_THRESHOLD =
+ DEFAULT_IN_SUB_QUERY_THRESHOLD;
//~ Instance fields --------------------------------------------------------
@@ -218,7 +222,7 @@ public class SqlToRelConverter {
protected final Prepare.CatalogReader catalogReader;
protected final RelOptCluster cluster;
private DefaultValueFactory defaultValueFactory;
- private SubqueryConverter subqueryConverter;
+ private SubQueryConverter subQueryConverter;
protected final List<RelNode> leaves = new ArrayList<>();
private final List<SqlDynamicParam> dynamicParamSqlNodes = new ArrayList<>();
private final SqlOperatorTable opTab;
@@ -228,7 +232,7 @@ public class SqlToRelConverter {
public final SqlToRelConverter.Config config;
/**
- * Fields used in name resolution for correlated subqueries.
+ * Fields used in name resolution for correlated sub-queries.
*/
private final Map<CorrelationId, DeferredLookup> mapCorrelToDeferred =
new HashMap<>();
@@ -240,8 +244,8 @@ public class SqlToRelConverter {
private final Deque<String> datasetStack = new ArrayDeque<>();
/**
- * Mapping of non-correlated subqueries that have been converted to their
- * equivalent constants. Used to avoid re-evaluating the subquery if it's
+ * Mapping of non-correlated sub-queries that have been converted to their
+ * equivalent constants. Used to avoid re-evaluating the sub-query if it's
* already been evaluated.
*/
private final Map<SqlNode, RexNode> mapConvertedNonCorrSubqs =
@@ -300,7 +304,7 @@ public class SqlToRelConverter {
this.validator = validator;
this.catalogReader = catalogReader;
this.defaultValueFactory = new NullDefaultValueFactory();
- this.subqueryConverter = new NoOpSubqueryConverter();
+ this.subQueryConverter = new NoOpSubQueryConverter();
this.rexBuilder = cluster.getRexBuilder();
this.typeFactory = rexBuilder.getTypeFactory();
this.cluster = Preconditions.checkNotNull(cluster);
@@ -365,7 +369,7 @@ public class SqlToRelConverter {
}
/**
- * @return mapping of non-correlated subqueries that have been converted to
+ * @return mapping of non-correlated sub-queries that have been converted to
* the constants that they evaluate to
*/
public Map<SqlNode, RexNode> getMapConvertedNonCorrSubqs() {
@@ -373,8 +377,8 @@ public class SqlToRelConverter {
}
/**
- * Adds to the current map of non-correlated converted subqueries the
- * elements from another map that contains non-correlated subqueries that
+ * Adds to the current map of non-correlated converted sub-queries the
+ * elements from another map that contains non-correlated sub-queries that
* have been converted by another SqlToRelConverter.
*
* @param alreadyConvertedNonCorrSubqs the other map
@@ -395,13 +399,13 @@ public class SqlToRelConverter {
}
/**
- * Sets a new SubqueryConverter. To have any effect, this must be called
+ * Sets a new SubQueryConverter. To have any effect, this must be called
* before any convert method.
*
- * @param converter new SubqueryConverter
+ * @param converter new SubQueryConverter
*/
- public void setSubqueryConverter(SubqueryConverter converter) {
- subqueryConverter = converter;
+ public void setSubQueryConverter(SubQueryConverter converter) {
+ subQueryConverter = converter;
}
/**
@@ -459,7 +463,7 @@ public class SqlToRelConverter {
}
/**
- * If subquery is correlated and decorrelation is enabled, performs
+ * If sub-query is correlated and decorrelation is enabled, performs
* decorrelation.
*
* @param query Query
@@ -981,7 +985,7 @@ public class SqlToRelConverter {
final Blackboard bb,
final SqlNode expr,
RelOptUtil.Logic logic) {
- findSubqueries(bb, expr, logic, false);
+ findSubQueries(bb, expr, logic, false);
for (SubQuery node : bb.subQueryList) {
substituteSubQuery(bb, node);
}
@@ -1034,7 +1038,7 @@ public class SqlToRelConverter {
if (query instanceof SqlNodeList) {
SqlNodeList valueList = (SqlNodeList) query;
if (!containsNullLiteral(valueList)
- && valueList.size() < config.getInSubqueryThreshold()) {
+ && valueList.size() < config.getInSubQueryThreshold()) {
// We're under the threshold, so convert to OR.
subQuery.expr =
convertInToOr(
@@ -1076,7 +1080,7 @@ public class SqlToRelConverter {
SqlTypeUtil.promoteToRowType(typeFactory,
validator.getValidatedNodeType(leftKeyNode), null);
converted =
- convertExists(query, RelOptUtil.SubqueryType.IN, subQuery.logic,
+ convertExists(query, RelOptUtil.SubQueryType.IN, subQuery.logic,
notIn, targetRowType);
if (converted.indicator) {
// Generate
@@ -1122,19 +1126,19 @@ public class SqlToRelConverter {
case EXISTS:
// "select from emp where exists (select a from T)"
//
- // is converted to the following if the subquery is correlated:
+ // is converted to the following if the sub-query is correlated:
//
// "select from emp left outer join (select AGG_TRUE() as indicator
// from T group by corr_var) q where q.indicator is true"
//
// If there is no correlation, the expression is replaced with a
- // boolean indicating whether the subquery returned 0 or >= 1 row.
+ // boolean indicating whether the sub-query returned 0 or >= 1 row.
call = (SqlBasicCall) subQuery.node;
query = call.operand(0);
if (!config.isExpand()) {
return;
}
- converted = convertExists(query, RelOptUtil.SubqueryType.EXISTS,
+ converted = convertExists(query, RelOptUtil.SubQueryType.EXISTS,
subQuery.logic, true, null);
assert !converted.indicator;
if (convertNonCorrelatedSubQuery(subQuery, bb, converted.r, true)) {
@@ -1144,14 +1148,14 @@ public class SqlToRelConverter {
return;
case SCALAR_QUERY:
- // Convert the subquery. If it's non-correlated, convert it
+ // Convert the sub-query. If it's non-correlated, convert it
// to a constant expression.
if (!config.isExpand()) {
return;
}
call = (SqlBasicCall) subQuery.node;
query = call.operand(0);
- converted = convertExists(query, RelOptUtil.SubqueryType.SCALAR,
+ converted = convertExists(query, RelOptUtil.SubQueryType.SCALAR,
subQuery.logic, true, null);
assert !converted.indicator;
if (convertNonCorrelatedSubQuery(subQuery, bb, converted.r, false)) {
@@ -1166,14 +1170,14 @@ public class SqlToRelConverter {
//
// select * from unnest(select multiset[deptno] from emps);
//
- converted = convertExists(subQuery.node, RelOptUtil.SubqueryType.SCALAR,
+ converted = convertExists(subQuery.node, RelOptUtil.SubQueryType.SCALAR,
subQuery.logic, true, null);
assert !converted.indicator;
subQuery.expr = bb.register(converted.r, JoinRelType.LEFT);
return;
default:
- throw Util.newInternal("unexpected kind of subquery :" + subQuery.node);
+ throw Util.newInternal("unexpected kind of sub-query :" + subQuery.node);
}
}
@@ -1194,7 +1198,7 @@ public class SqlToRelConverter {
//
// RexRangeRef contains the following fields:
// leftKeysForIn,
- // rightKeysForIn (the original subquery select list),
+ // rightKeysForIn (the original sub-query select list),
// nullIndicator
//
// The first two lists contain the same number of fields.
@@ -1277,14 +1281,14 @@ public class SqlToRelConverter {
}
/**
- * Determines if a subquery is non-correlated and if so, converts it to a
+ * Determines if a sub-query is non-correlated and if so, converts it to a
* constant.
*
- * @param subQuery the call that references the subquery
- * @param bb blackboard used to convert the subquery
- * @param converted RelNode tree corresponding to the subquery
- * @param isExists true if the subquery is part of an EXISTS expression
- * @return if the subquery can be converted to a constant
+ * @param subQuery the call that references the sub-query
+ * @param bb blackboard used to convert the sub-query
+ * @param converted RelNode tree corresponding to the sub-query
+ * @param isExists true if the sub-query is part of an EXISTS expression
+ * @return Whether the sub-query can be converted to a constant
*/
private boolean convertNonCorrelatedSubQuery(
SubQuery subQuery,
@@ -1292,15 +1296,15 @@ public class SqlToRelConverter {
RelNode converted,
boolean isExists) {
SqlCall call = (SqlBasicCall) subQuery.node;
- if (subqueryConverter.canConvertSubquery()
+ if (subQueryConverter.canConvertSubQuery()
&& isSubQueryNonCorrelated(converted, bb)) {
- // First check if the subquery has already been converted
- // because it's a nested subquery. If so, don't re-evaluate
+ // First check if the sub-query has already been converted
+ // because it's a nested sub-query. If so, don't re-evaluate
// it again.
RexNode constExpr = mapConvertedNonCorrSubqs.get(call);
if (constExpr == null) {
constExpr =
- subqueryConverter.convertSubquery(
+ subQueryConverter.convertSubQuery(
call,
this,
isExists,
@@ -1449,15 +1453,15 @@ public class SqlToRelConverter {
* predicate. A threshold of 0 forces usage of an inline table in all cases; a
* threshold of Integer.MAX_VALUE forces usage of OR in all cases
*
- * @return threshold, default {@link #DEFAULT_IN_SUBQUERY_THRESHOLD}
+ * @return threshold, default {@link #DEFAULT_IN_SUB_QUERY_THRESHOLD}
*/
@Deprecated // to be removed before 2.0
protected int getInSubqueryThreshold() {
- return config.getInSubqueryThreshold();
+ return config.getInSubQueryThreshold();
}
/**
- * Converts an EXISTS or IN predicate into a join. For EXISTS, the subquery
+ * Converts an EXISTS or IN predicate into a join. For EXISTS, the sub-query
* produces an indicator variable, and the result is a relational expression
* which outer joins that indicator to the original query. After performing
* the outer join, the condition will be TRUE if the EXISTS condition holds,
@@ -1465,7 +1469,7 @@ public class SqlToRelConverter {
*
* @param seek A query, for example 'select * from emp' or
* 'values (1,2,3)' or '('Foo', 34)'.
- * @param subqueryType Whether sub-query is IN, EXISTS or scalar
+ * @param subQueryType Whether sub-query is IN, EXISTS or scalar
* @param logic Whether the answer needs to be in full 3-valued logic (TRUE,
* FALSE, UNKNOWN) will be required, or whether we can accept an
* approximation (say representing UNKNOWN as FALSE)
@@ -1475,7 +1479,7 @@ public class SqlToRelConverter {
*/
private RelOptUtil.Exists convertExists(
SqlNode seek,
- RelOptUtil.SubqueryType subqueryType,
+ RelOptUtil.SubQueryType subQueryType,
RelOptUtil.Logic logic,
boolean notIn,
RelDataType targetDataType) {
@@ -1486,7 +1490,7 @@ public class SqlToRelConverter {
final Blackboard seekBb = createBlackboard(seekScope, null, false);
RelNode seekRel = convertQueryOrInList(seekBb, seek, targetDataType);
- return RelOptUtil.createExistsPlan(seekRel, subqueryType, logic, notIn);
+ return RelOptUtil.createExistsPlan(seekRel, subQueryType, logic, notIn);
}
private RelNode convertQueryOrInList(
@@ -1520,7 +1524,7 @@ public class SqlToRelConverter {
// NOTE jvs 30-Apr-2006: We combine all rows consisting entirely of
// literals into a single LogicalValues; this gives the optimizer a smaller
// input tree. For everything else (computed expressions, row
- // subqueries), we union each row in as a projection on top of a
+ // sub-queries), we union each row in as a projection on top of a
// LogicalOneRow.
final ImmutableList.Builder<ImmutableList<RexLiteral>> tupleList =
@@ -1678,16 +1682,16 @@ public class SqlToRelConverter {
* @param logic Whether the answer needs to be in full 3-valued logic (TRUE,
* FALSE, UNKNOWN) will be required, or whether we can accept
* an approximation (say representing UNKNOWN as FALSE)
- * @param registerOnlyScalarSubqueries if set to true and the parse tree
+ * @param registerOnlyScalarSubQueries if set to true and the parse tree
* corresponds to a variation of a select
* node, only register it if it's a scalar
- * subquery
+ * sub-query
*/
- private void findSubqueries(
+ private void findSubQueries(
Blackboard bb,
SqlNode node,
RelOptUtil.Logic logic,
- boolean registerOnlyScalarSubqueries) {
+ boolean registerOnlyScalarSubQueries) {
final SqlKind kind = node.getKind();
switch (kind) {
case EXISTS:
@@ -1697,7 +1701,7 @@ public class SqlToRelConverter {
case ARRAY_QUERY_CONSTRUCTOR:
case CURSOR:
case SCALAR_QUERY:
- if (!registerOnlyScalarSubqueries
+ if (!registerOnlyScalarSubQueries
|| (kind == SqlKind.SCALAR_QUERY)) {
bb.registerSubQuery(node, RelOptUtil.Logic.TRUE_FALSE);
}
@@ -1715,27 +1719,27 @@ public class SqlToRelConverter {
for (SqlNode operand : ((SqlCall) node).getOperandList()) {
if (operand != null) {
// In the case of an IN expression, locate scalar
- // subqueries so we can convert them to constants
- findSubqueries(
+ // sub-queries so we can convert them to constants
+ findSubQueries(
bb,
operand,
logic,
- kind == SqlKind.IN || registerOnlyScalarSubqueries);
+ kind == SqlKind.IN || registerOnlyScalarSubQueries);
}
}
} else if (node instanceof SqlNodeList) {
for (SqlNode child : (SqlNodeList) node) {
- findSubqueries(
+ findSubQueries(
bb,
child,
logic,
- kind == SqlKind.IN || registerOnlyScalarSubqueries);
+ kind == SqlKind.IN || registerOnlyScalarSubQueries);
}
}
- // Now that we've located any scalar subqueries inside the IN
+ // Now that we've located any scalar sub-queries inside the IN
// expression, register the IN expression itself. We need to
- // register the scalar subqueries first so they can be converted
+ // register the scalar sub-queries first so they can be converted
// before the IN expression is converted.
if (kind == SqlKind.IN) {
switch (logic) {
@@ -2257,7 +2261,7 @@ public class SqlToRelConverter {
Map<Integer, Integer> exprProjection =
bb.mapRootRelToFieldProjection.get(bb.root);
- // subquery can reference group by keys projected from
+ // sub-query can reference group by keys projected from
// the root of the outer relation.
if (exprProjection.containsKey(pos)) {
pos = exprProjection.get(pos);
@@ -2288,15 +2292,15 @@ public class SqlToRelConverter {
}
/**
- * Determines whether a subquery is non-correlated. Note that a
- * non-correlated subquery can contain correlated references, provided those
+ * Determines whether a sub-query is non-correlated. Note that a
+ * non-correlated sub-query can contain correlated references, provided those
* references do not reference select statements that are parents of the
- * subquery.
+ * sub-query.
*
- * @param subq the subquery
- * @param bb blackboard used while converting the subquery, i.e., the
- * blackboard of the parent query of this subquery
- * @return true if the subquery is non-correlated.
+ * @param subq the sub-query
+ * @param bb blackboard used while converting the sub-query, i.e., the
+ * blackboard of the parent query of this sub-query
+ * @return true if the sub-query is non-correlated
*/
private boolean isSubQueryNonCorrelated(RelNode subq, Blackboard bb) {
Set<CorrelationId> correlatedVariables = RelOptUtil.getVariablesUsed(subq);
@@ -2312,7 +2316,7 @@ public class SqlToRelConverter {
SqlValidatorScope ancestorScope = resolved.only().scope;
// If the correlated reference is in a scope that's "above" the
- // subquery, then this is a correlated subquery.
+ // sub-query, then this is a correlated sub-query.
SqlValidatorScope parentScope = bb.scope;
do {
if (ancestorScope == parentScope) {
@@ -2461,7 +2465,7 @@ public class SqlToRelConverter {
having.accept(aggregateFinder);
}
- // first replace the subqueries inside the aggregates
+ // first replace the sub-queries inside the aggregates
// because they will provide input rows to the aggregates.
replaceSubQueries(bb, aggregateFinder.list,
RelOptUtil.Logic.TRUE_FALSE_UNKNOWN);
@@ -2586,7 +2590,7 @@ public class SqlToRelConverter {
bb.mapRootRelToFieldProjection.put(bb.root, r.groupExprProjection);
- // Replace subqueries in having here and modify having to use
+ // Replace sub-queries in having here and modify having to use
// the replaced expressions
if (having != null) {
SqlNode newHaving = pushDownNotForIn(having);
@@ -2597,13 +2601,13 @@ public class SqlToRelConverter {
}
}
- // Now convert the other subqueries in the select list.
- // This needs to be done separately from the subquery inside
+ // Now convert the other sub-queries in the select list.
+ // This needs to be done separately from the sub-query inside
// any aggregate in the select list, and after the aggregate rel
// is allocated.
replaceSubQueries(bb, selectList, RelOptUtil.Logic.TRUE_FALSE_UNKNOWN);
- // Now subqueries in the entire select list have been converted.
+ // Now sub-queries in the entire select list have been converted.
// Convert the select expressions to get the final list to be
// projected.
int k = 0;
@@ -2819,7 +2823,7 @@ public class SqlToRelConverter {
@Deprecated // to be removed before 2.0
protected boolean enableDecorrelation() {
- // disable subquery decorrelation when needed.
+ // disable sub-query decorrelation when needed.
// e.g. if outer joins are not supported.
return config.isDecorrelationEnabled();
}
@@ -3589,7 +3593,7 @@ public class SqlToRelConverter {
SqlCall values,
RelDataType targetRowType) {
// Attempt direct conversion to LogicalValues; if that fails, deal with
- // fancy stuff like subqueries below.
+ // fancy stuff like sub-queries below.
RelNode valuesRel =
convertRowValues(
bb,
@@ -3682,8 +3686,8 @@ public class SqlToRelConverter {
/**
* Project the groupby expressions out of the root of this sub-select.
- * Subqueries can reference group by expressions projected from the
- * "right" to the subquery.
+ * Sub-queries can reference group by expressions projected from the
+ * "right" to the sub-query.
*/
private final Map<RelNode, Map<Integer, Integer>>
mapRootRelToFieldProjection = new HashMap<>();
@@ -3841,7 +3845,7 @@ public class SqlToRelConverter {
* @param leaf Whether the relational expression is a leaf, that is,
* derived from an atomic relational expression such as a table
* name in the from clause, or the projection on top of a
- * select-subquery. In particular, relational expressions
+ * select-sub-query. In particular, relational expressions
* derived from JOIN operators are not leaves, but set
* expressions are.
*/
@@ -4141,12 +4145,12 @@ public class SqlToRelConverter {
if (((kind == SqlKind.SCALAR_QUERY)
|| (kind == SqlKind.EXISTS))
&& isConvertedSubq(rex)) {
- // scalar subquery or EXISTS has been converted to a
+ // scalar sub-query or EXISTS has been converted to a
// constant
return rex;
}
- // The indicator column is the last field of the subquery.
+ // The indicator column is the last field of the sub-query.
RexNode fieldAccess =
rexBuilder.makeFieldAccess(
rex,
@@ -4195,7 +4199,7 @@ public class SqlToRelConverter {
}
/**
- * Determines whether a RexNode corresponds to a subquery that's been
+ * Determines whether a RexNode corresponds to a sub-query that's been
* converted to a constant.
*
* @param rex the expression to be examined
@@ -4348,15 +4352,15 @@ public class SqlToRelConverter {
}
/**
- * A default implementation of SubqueryConverter that does no conversion.
+ * A default implementation of SubQueryConverter that does no conversion.
*/
- private class NoOpSubqueryConverter implements SubqueryConverter {
- public boolean canConvertSubquery() {
+ private class NoOpSubQueryConverter implements SubQueryConverter {
+ public boolean canConvertSubQuery() {
return false;
}
- public RexNode convertSubquery(
- SqlCall subquery,
+ public RexNode convertSubQuery(
+ SqlCall subQuery,
SqlToRelConverter parentConverter,
boolean isExists,
boolean isExplain) {
@@ -4518,7 +4522,7 @@ public class SqlToRelConverter {
return null;
case SELECT:
// rchen 2006-10-17:
- // for now do not detect aggregates in subqueries.
+ // for now do not detect aggregates in sub-queries.
return null;
}
final boolean prevInOver = inOver;
@@ -4750,7 +4754,7 @@ public class SqlToRelConverter {
/**
* Creates a LookupContext with multiple input relational expressions.
*
- * @param bb Context for translating this subquery
+ * @param bb Context for translating this sub-query
* @param rels Relational expressions
* @param systemFieldCount Number of system fields
*/
@@ -5045,7 +5049,7 @@ public class SqlToRelConverter {
boolean isConvertTableAccess();
/** Returns the {@code decorrelationEnabled} option. Controls whether to
- * disable subquery decorrelation when needed. e.g. if outer joins are not
+ * disable sub-query decorrelation when needed. e.g. if outer joins are not
* supported. */
boolean isDecorrelationEnabled();
@@ -5067,15 +5071,15 @@ public class SqlToRelConverter {
* {@link org.apache.calcite.rex.RexSubQuery}. */
boolean isExpand();
- /** Returns the {@code inSubqueryThreshold} option,
- * default {@link #DEFAULT_IN_SUBQUERY_THRESHOLD}. Controls the list size
+ /** Returns the {@code inSubQueryThreshold} option,
+ * default {@link #DEFAULT_IN_SUB_QUERY_THRESHOLD}. Controls the list size
* threshold under which {@link #convertInToOr} is used. Lists of this size
* or greater will instead be converted to use a join against an inline
* table ({@link org.apache.calcite.rel.logical.LogicalValues}) rather than
* a predicate. A threshold of 0 forces usage of an inline table in all
* cases; a threshold of {@link Integer#MAX_VALUE} forces usage of OR in all
* cases. */
- int getInSubqueryThreshold();
+ int getInSubQueryThreshold();
}
/** Builder for a {@link Config}. */
@@ -5086,7 +5090,7 @@ public class SqlToRelConverter {
private boolean createValuesRel = true;
private boolean explain;
private boolean expand = true;
- private int inSubqueryThreshold = DEFAULT_IN_SUBQUERY_THRESHOLD;
+ private int inSubQueryThreshold = DEFAULT_IN_SUB_QUERY_THRESHOLD;
private ConfigBuilder() {}
@@ -5098,7 +5102,7 @@ public class SqlToRelConverter {
this.createValuesRel = config.isCreateValuesRel();
this.explain = config.isExplain();
this.expand = config.isExpand();
- this.inSubqueryThreshold = config.getInSubqueryThreshold();
+ this.inSubQueryThreshold = config.getInSubQueryThreshold();
return this;
}
@@ -5132,8 +5136,13 @@ public class SqlToRelConverter {
return this;
}
- public ConfigBuilder withInSubqueryThreshold(int inSubqueryThreshold) {
- this.inSubqueryThreshold = inSubqueryThreshold;
+ @Deprecated // to be removed before 2.0
+ public ConfigBuilder withInSubqueryThreshold(int inSubQueryThreshold) {
+ return withInSubQueryThreshold(inSubQueryThreshold);
+ }
+
+ public ConfigBuilder withInSubQueryThreshold(int inSubQueryThreshold) {
+ this.inSubQueryThreshold = inSubQueryThreshold;
return this;
}
@@ -5141,7 +5150,7 @@ public class SqlToRelConverter {
public Config build() {
return new ConfigImpl(convertTableAccess, decorrelationEnabled,
trimUnusedFields, createValuesRel, explain, expand,
- inSubqueryThreshold);
+ inSubQueryThreshold);
}
}
@@ -5153,19 +5162,19 @@ public class SqlToRelConverter {
private final boolean trimUnusedFields;
private final boolean createValuesRel;
private final boolean explain;
- private final int inSubqueryThreshold;
+ private final int inSubQueryThreshold;
private final boolean expand;
private ConfigImpl(boolean convertTableAccess, boolean decorrelationEnabled,
boolean trimUnusedFields, boolean createValuesRel, boolean explain,
- boolean expand, int inSubqueryThreshold) {
+ boolean expand, int inSubQueryThreshold) {
this.convertTableAccess = convertTableAccess;
this.decorrelationEnabled = decorrelationEnabled;
this.trimUnusedFields = trimUnusedFields;
this.createValuesRel = createValuesRel;
this.explain = explain;
this.expand = expand;
- this.inSubqueryThreshold = inSubqueryThreshold;
+ this.inSubQueryThreshold = inSubQueryThreshold;
}
public boolean isConvertTableAccess() {
@@ -5192,8 +5201,8 @@ public class SqlToRelConverter {
return expand;
}
- public int getInSubqueryThreshold() {
- return inSubqueryThreshold;
+ public int getInSubQueryThreshold() {
+ return inSubQueryThreshold;
}
}
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/e38d51e8/core/src/main/java/org/apache/calcite/sql2rel/SubQueryConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SubQueryConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SubQueryConverter.java
new file mode 100644
index 0000000..574cd82
--- /dev/null
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SubQueryConverter.java
@@ -0,0 +1,53 @@
+/*
+ * 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.calcite.sql2rel;
+
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlCall;
+
+/**
+ * SubQueryConverter provides the interface for classes that convert sub-queries
+ * into equivalent expressions.
+ */
+public interface SubQueryConverter {
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * @return Whether the sub-query can be converted
+ */
+ boolean canConvertSubQuery();
+
+ /**
+ * Converts the sub-query to an equivalent expression.
+ *
+ * @param subQuery the SqlNode tree corresponding to a sub-query
+ * @param parentConverter sqlToRelConverter of the parent query
+ * @param isExists whether the sub-query is part of an EXISTS
+ * expression
+ * @param isExplain whether the sub-query is part of an EXPLAIN PLAN
+ * statement
+ * @return the equivalent expression or null if the sub-query couldn't be
+ * converted
+ */
+ RexNode convertSubQuery(
+ SqlCall subQuery,
+ SqlToRelConverter parentConverter,
+ boolean isExists,
+ boolean isExplain);
+}
+
+// End SubQueryConverter.java