Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.CorrelationId;
import org.apache.calcite.rel.core.Project;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.util.Pair;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Implementation of {@link org.apache.calcite.rel.core.Project}
Expand All @@ -42,13 +46,15 @@
public class CassandraProject extends Project implements CassandraRel {
public CassandraProject(RelOptCluster cluster, RelTraitSet traitSet,
RelNode input, List<? extends RexNode> projects, RelDataType rowType) {
super(cluster, traitSet, ImmutableList.of(), input, projects, rowType);
super(cluster, traitSet, ImmutableList.of(), input, projects, rowType, ImmutableSet.of());
assert getConvention() == CassandraRel.CONVENTION;
assert getConvention() == input.getConvention();
}

@Override public Project copy(RelTraitSet traitSet, RelNode input,
List<RexNode> projects, RelDataType rowType) {
List<RexNode> projects, RelDataType rowType, Set<CorrelationId> variablesSet) {
Preconditions.checkArgument(variablesSet.isEmpty(),
"Correlated scalar subqueries are not supported");
return new CassandraProject(getCluster(), traitSet, input, projects,
rowType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ public interface CassandraFilterRuleConfig extends RelRule.Config {
public static class CassandraProjectRule extends CassandraConverterRule {
/** Default configuration. */
private static final Config DEFAULT_CONFIG = Config.INSTANCE
.withConversion(LogicalProject.class, Convention.NONE,
.withConversion(LogicalProject.class, p -> p.getCorrelVariable() == null
&& p.getVariablesSet().isEmpty(), Convention.NONE,
CassandraRel.CONVENTION, "CassandraProjectRule")
.withRuleFactory(CassandraProjectRule::new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.RelCollationTraitDef;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.CorrelationId;
import org.apache.calcite.rel.core.Project;
import org.apache.calcite.rel.metadata.RelMdCollation;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
Expand All @@ -28,11 +29,14 @@
import org.apache.calcite.util.Pair;
import org.apache.calcite.util.Util;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.List;
import java.util.Set;

/** Implementation of {@link org.apache.calcite.rel.core.Project} in
* {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */
Expand All @@ -54,7 +58,7 @@ public EnumerableProject(
RelNode input,
List<? extends RexNode> projects,
RelDataType rowType) {
super(cluster, traitSet, ImmutableList.of(), input, projects, rowType);
super(cluster, traitSet, ImmutableList.of(), input, projects, rowType, ImmutableSet.of());
assert getConvention() instanceof EnumerableConvention;
}

Expand All @@ -80,7 +84,9 @@ public static EnumerableProject create(final RelNode input,
}

@Override public EnumerableProject copy(RelTraitSet traitSet, RelNode input,
List<RexNode> projects, RelDataType rowType) {
List<RexNode> projects, RelDataType rowType, Set<CorrelationId> variablesSet) {
Preconditions.checkArgument(variablesSet.isEmpty(),
"Correlated scalar subqueries are not supported");
return new EnumerableProject(getCluster(), traitSet, input,
projects, rowType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class EnumerableProjectRule extends ConverterRule {
/** Default configuration. */
static final Config DEFAULT_CONFIG = Config.INSTANCE
.as(Config.class)
.withConversion(LogicalProject.class, p -> !p.containsOver(),
.withConversion(LogicalProject.class, p -> !p.containsOver()
&& p.getCorrelVariable() == null && p.getVariablesSet().isEmpty(),
Convention.NONE, EnumerableConvention.INSTANCE,
"EnumerableProjectRule")
.withRuleFactory(EnumerableProjectRule::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.sql.validate.SqlValidatorUtil;

import com.google.common.base.Preconditions;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.List;
Expand Down Expand Up @@ -68,7 +70,10 @@ private static class ProjectFactoryImpl
implements org.apache.calcite.rel.core.RelFactories.ProjectFactory {
@Override public RelNode createProject(RelNode input, List<RelHint> hints,
List<? extends RexNode> childExprs,
@Nullable List<? extends @Nullable String> fieldNames) {
@Nullable List<? extends @Nullable String> fieldNames,
Set<CorrelationId> variablesSet) {
Preconditions.checkArgument(variablesSet.isEmpty(),
"Correlated scalar subqueries are not supported");
final RelDataType rowType =
RexUtil.createStructType(input.getCluster().getTypeFactory(), childExprs,
fieldNames, SqlValidatorUtil.F_SUGGESTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
Expand All @@ -96,7 +97,9 @@ private JdbcRules() {
protected static final Logger LOGGER = CalciteTrace.getPlannerTracer();

static final RelFactories.ProjectFactory PROJECT_FACTORY =
(input, hints, projects, fieldNames) -> {
(input, hints, projects, fieldNames, variablesSet) -> {
Preconditions.checkArgument(variablesSet.isEmpty(),
"JdbcProject does not allow variables");
final RelOptCluster cluster = input.getCluster();
final RelDataType rowType =
RexUtil.createStructType(cluster.getTypeFactory(), projects,
Expand Down Expand Up @@ -532,7 +535,7 @@ public JdbcProject(
RelNode input,
List<? extends RexNode> projects,
RelDataType rowType) {
super(cluster, traitSet, ImmutableList.of(), input, projects, rowType);
super(cluster, traitSet, ImmutableList.of(), input, projects, rowType, ImmutableSet.of());
assert getConvention() instanceof JdbcConvention;
}

Expand All @@ -544,7 +547,9 @@ public JdbcProject(RelOptCluster cluster, RelTraitSet traitSet,
}

@Override public JdbcProject copy(RelTraitSet traitSet, RelNode input,
List<RexNode> projects, RelDataType rowType) {
List<RexNode> projects, RelDataType rowType, Set<CorrelationId> variablesSet) {
Preconditions.checkArgument(variablesSet.isEmpty(),
"Correlated scalar subqueries are not supported");
return new JdbcProject(getCluster(), traitSet, input, projects, rowType);
}

Expand Down
10 changes: 7 additions & 3 deletions core/src/main/java/org/apache/calcite/interpreter/Bindables.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Value;
Expand Down Expand Up @@ -376,7 +377,8 @@ public static BindableFilter create(final RelNode input,
public static class BindableProjectRule extends ConverterRule {
/** Default configuration. */
public static final Config DEFAULT_CONFIG = Config.INSTANCE
.withConversion(LogicalProject.class, p -> !p.containsOver(),
.withConversion(LogicalProject.class, p -> !p.containsOver()
&& p.getCorrelVariable() == null && p.getVariablesSet().isEmpty(),
Convention.NONE, BindableConvention.INSTANCE,
"BindableProjectRule")
.withRuleFactory(BindableProjectRule::new);
Expand All @@ -403,12 +405,14 @@ protected BindableProjectRule(Config config) {
public static class BindableProject extends Project implements BindableRel {
public BindableProject(RelOptCluster cluster, RelTraitSet traitSet,
RelNode input, List<? extends RexNode> projects, RelDataType rowType) {
super(cluster, traitSet, ImmutableList.of(), input, projects, rowType);
super(cluster, traitSet, ImmutableList.of(), input, projects, rowType, ImmutableSet.of());
assert getConvention() instanceof BindableConvention;
}

@Override public BindableProject copy(RelTraitSet traitSet, RelNode input,
List<RexNode> projects, RelDataType rowType) {
List<RexNode> projects, RelDataType rowType, Set<CorrelationId> variablesSet) {
Preconditions.checkArgument(variablesSet.isEmpty(),
"Correlated scalar subqueries are not supported");
return new BindableProject(getCluster(), traitSet, input,
projects, rowType);
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ public static RelNode createCastRel(
List<RexNode> castExps;
RelNode input;
List<RelHint> hints = ImmutableList.of();
Set<CorrelationId> variablesSet = ImmutableSet.of();
if (rel instanceof Project) {
// No need to create another project node if the rel
// is already a project.
Expand All @@ -894,6 +895,7 @@ public static RelNode createCastRel(
castRowType,
((Project) rel).getProjects());
input = rel.getInput(0);
variablesSet = project.getVariablesSet();
hints = project.getHints();
} else {
castExps = RexUtil.generateCastExpressions(
Expand All @@ -905,11 +907,11 @@ public static RelNode createCastRel(
if (rename) {
// Use names and types from castRowType.
return projectFactory.createProject(input, hints, castExps,
castRowType.getFieldNames());
castRowType.getFieldNames(), variablesSet);
} else {
// Use names from rowType, types from castRowType.
return projectFactory.createProject(input, hints, castExps,
rowType.getFieldNames());
rowType.getFieldNames(), variablesSet);
}
}

Expand Down
3 changes: 0 additions & 3 deletions core/src/main/java/org/apache/calcite/rel/RelNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ public interface RelNode extends RelOptNode, Cloneable {
* expression but also used and therefore not available to parents of this
* relational expression.
*
* <p>Note: only {@link org.apache.calcite.rel.core.Correlate} should set
* variables.
*
* @return Names of variables which are set in this relational
* expression
*/
Expand Down
Loading