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 @@ -33,16 +33,15 @@ public EnumerableProject(
RelTraitSet traitSet,
RelNode child,
List<? extends RexNode> exps,
RelDataType rowType,
int flags) {
super(cluster, traitSet, child, exps, rowType, flags);
RelDataType rowType) {
super(cluster, traitSet, child, exps, rowType);
assert getConvention() instanceof EnumerableConvention;
}

public EnumerableProject copy(RelTraitSet traitSet, RelNode input,
List<RexNode> exps, RelDataType rowType) {
return new EnumerableProject(getCluster(), traitSet, input,
exps, rowType, flags);
exps, rowType);
}

public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.convert.ConverterRule;
import org.apache.calcite.rel.core.Project;
import org.apache.calcite.rel.logical.LogicalProject;

/**
Expand All @@ -41,8 +40,7 @@ public RelNode convert(RelNode rel) {
project.getInput().getTraitSet()
.replace(EnumerableConvention.INSTANCE)),
project.getProjects(),
project.getRowType(),
Project.Flags.BOXED);
project.getRowType());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.calcite.linq4j.tree.BlockStatement;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.Project;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rex.RexNode;
Expand Down Expand Up @@ -54,8 +53,7 @@ public RelNode createProject(RelNode child,
: SqlValidatorUtil.uniquify(fieldNames,
SqlValidatorUtil.F_SUGGESTER));
return new EnumerableProject(cluster,
child.getTraitSet(), child, exprs, rowType,
Project.Flags.BOXED);
child.getTraitSet(), child, exprs, rowType);
}
};

Expand Down
25 changes: 7 additions & 18 deletions core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public RelNode convert(RelNode rel) {

return new JdbcCalc(rel.getCluster(), rel.getTraitSet().replace(out),
convert(calc.getInput(), calc.getTraitSet().replace(out)),
calc.getProgram(), Project.Flags.BOXED);
calc.getProgram());
}
}

Expand All @@ -364,19 +364,12 @@ public RelNode convert(RelNode rel) {
public static class JdbcCalc extends SingleRel implements JdbcRel {
private final RexProgram program;

/**
* Values defined in {@link org.apache.calcite.rel.core.Project.Flags}.
*/
protected final int flags;

public JdbcCalc(RelOptCluster cluster,
RelTraitSet traitSet,
RelNode child,
RexProgram program,
int flags) {
RexProgram program) {
super(cluster, traitSet, child);
assert getConvention() instanceof JdbcConvention;
this.flags = flags;
this.program = program;
this.rowType = program.getOutputRowType();
}
Expand All @@ -398,8 +391,7 @@ public RelOptCost computeSelfCost(RelOptPlanner planner) {
}

public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
return new JdbcCalc(getCluster(), traitSet, sole(inputs), program,
flags);
return new JdbcCalc(getCluster(), traitSet, sole(inputs), program);
}

public JdbcImplementor.Result implement(JdbcImplementor implementor) {
Expand Down Expand Up @@ -444,8 +436,7 @@ public RelNode convert(RelNode rel) {
project.getInput(),
project.getInput().getTraitSet().replace(out)),
project.getProjects(),
project.getRowType(),
Project.Flags.BOXED);
project.getRowType());
}
}

Expand All @@ -459,16 +450,14 @@ public JdbcProject(
RelTraitSet traitSet,
RelNode child,
List<RexNode> exps,
RelDataType rowType,
int flags) {
super(cluster, traitSet, child, exps, rowType, flags);
RelDataType rowType) {
super(cluster, traitSet, child, exps, rowType);
assert getConvention() instanceof JdbcConvention;
}

@Override public JdbcProject copy(RelTraitSet traitSet, RelNode input,
List<RexNode> exps, RelDataType rowType) {
return new JdbcProject(getCluster(), traitSet, input, exps, rowType,
flags);
return new JdbcProject(getCluster(), traitSet, input, exps, rowType);
}

@Override public RelOptCost computeSelfCost(RelOptPlanner planner) {
Expand Down
12 changes: 5 additions & 7 deletions core/src/main/java/org/apache/calcite/interpreter/Bindables.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,25 +220,23 @@ public RelNode convert(RelNode rel) {
project.getInput().getTraitSet()
.replace(BindableConvention.INSTANCE)),
project.getProjects(),
project.getRowType(),
Project.Flags.BOXED);
project.getRowType()
);
}
}

/** Implementation of {@link org.apache.calcite.rel.core.Project} in
* bindable calling convention. */
public static class BindableProject extends Project implements BindableRel {
public BindableProject(RelOptCluster cluster, RelTraitSet traitSet,
RelNode child, List<? extends RexNode> exps, RelDataType rowType,
int flags) {
super(cluster, traitSet, child, exps, rowType, flags);
RelNode child, List<? extends RexNode> exps, RelDataType rowType) {
super(cluster, traitSet, child, exps, rowType);
assert getConvention() instanceof BindableConvention;
}

public BindableProject copy(RelTraitSet traitSet, RelNode input,
List<RexNode> exps, RelDataType rowType) {
return new BindableProject(getCluster(), traitSet, input, exps, rowType,
flags);
return new BindableProject(getCluster(), traitSet, input, exps, rowType);
}

public Class<Object[]> getElementType() {
Expand Down
9 changes: 2 additions & 7 deletions core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2295,10 +2295,6 @@ public static void splitFilters(
public static boolean checkProjAndChildInputs(
Project project,
boolean checkNames) {
if (!project.isBoxed()) {
return false;
}

int n = project.getProjects().size();
RelDataType inputType = project.getInput().getRowType();
if (inputType.getFieldList().size() != n) {
Expand Down Expand Up @@ -2501,7 +2497,7 @@ public static LogicalProject project(
names.add(field.getName());
}
return new LogicalProject(
child.getCluster(), child, nodes, names, LogicalProject.Flags.BOXED);
child.getCluster(), child, nodes, names);
}

/** Returns whether relational expression {@code target} occurs within a
Expand Down Expand Up @@ -2708,8 +2704,7 @@ public static RelNode createProject(
: collationList.get(0)),
child,
exprs,
rowType,
Project.Flags.BOXED);
rowType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ private static RelNode fromMutable(MutableRel node) {
return new LogicalProject(node.cluster,
node.cluster.traitSetOf(RelCollationImpl.EMPTY),
fromMutable(project.input),
project.projects, project.rowType, Project.Flags.BOXED);
project.projects, project.rowType);
case FILTER:
final MutableFilter filter = (MutableFilter) node;
return new LogicalFilter(node.cluster, fromMutable(filter.input),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public RelNode translate(Expression expression) {
toRex(
child,
(FunctionExpression) call.expressions.get(0)),
null,
LogicalProject.Flags.BOXED);
null);

case WHERE:
child = translate(call.targetExpression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.calcite.linq4j.function.Predicate2;
import org.apache.calcite.linq4j.tree.FunctionExpression;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.Project;
import org.apache.calcite.rel.logical.LogicalFilter;
import org.apache.calcite.rel.logical.LogicalProject;
import org.apache.calcite.rel.logical.LogicalTableScan;
Expand Down Expand Up @@ -515,8 +514,7 @@ public <TResult> Queryable<TResult> select(
translator.cluster,
child,
nodes,
null,
Project.Flags.BOXED));
null));
return null;
}

Expand Down
43 changes: 2 additions & 41 deletions core/src/main/java/org/apache/calcite/rel/core/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ public abstract class Project extends SingleRel {

protected final ImmutableList<RexNode> exps;

/**
* Values defined in {@link Flags}.
*/
protected int flags;

protected final ImmutableList<RelCollation> collationList;

//~ Constructors -----------------------------------------------------------
Expand All @@ -84,21 +79,17 @@ public abstract class Project extends SingleRel {
* @param input input relational expression
* @param exps List of expressions for the input columns
* @param rowType output row type
* @param flags Flags; values as in {@link Project.Flags},
* usually {@link Project.Flags#BOXED}
*/
protected Project(
RelOptCluster cluster,
RelTraitSet traits,
RelNode input,
List<? extends RexNode> exps,
RelDataType rowType,
int flags) {
RelDataType rowType) {
super(cluster, traits, input);
assert rowType != null;
this.exps = ImmutableList.copyOf(exps);
this.rowType = rowType;
this.flags = flags;
final RelCollation collation =
traits.getTrait(RelCollationTraitDef.INSTANCE);
this.collationList =
Expand All @@ -114,7 +105,7 @@ protected Project(
protected Project(RelInput input) {
this(input.getCluster(), input.getTraitSet(), input.getInput(),
input.getExpressionList("exprs"),
input.getRowType("exprs", "fields"), Flags.BOXED);
input.getRowType("exprs", "fields"));
}

//~ Methods ----------------------------------------------------------------
Expand Down Expand Up @@ -144,10 +135,6 @@ public List<RelCollation> getCollationList() {
return collationList;
}

public boolean isBoxed() {
return (flags & Flags.BOXED) == Flags.BOXED;
}

@Override public List<RexNode> getChildExps() {
return exps;
}
Expand Down Expand Up @@ -179,10 +166,6 @@ public final List<Pair<RexNode, String>> getNamedProjects() {
return Pair.zip(getProjects(), getRowType().getFieldNames());
}

public int getFlags() {
return flags;
}

public boolean isValid(boolean fail) {
if (!super.isValid(fail)) {
assert !fail;
Expand All @@ -205,12 +188,6 @@ public boolean isValid(boolean fail) {
assert !fail;
return false;
}
if (!isBoxed()) {
if (exps.size() != 1) {
assert !fail;
return false;
}
}
if (collationList == null) {
assert !fail;
return false;
Expand Down Expand Up @@ -357,22 +334,6 @@ public boolean isMapping() {

//~ Inner Classes ----------------------------------------------------------

/** A collection of integer constants that describe the kind of project. */
public static class Flags {
public static final int ANON_FIELDS = 2;

/**
* Whether the resulting row is to be a synthetic class whose fields are
* the aliases of the fields. <code>boxed</code> must be true unless
* there is only one field: <code>select {dept.deptno} from dept</code>
* is boxed, <code>select dept.deptno from dept</code> is not.
*/
public static final int BOXED = 1;
public static final int NONE = 0;
}

//~ Inner Classes ----------------------------------------------------------

/**
* Visitor which walks over a program and checks validity.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ public final class LogicalProject extends Project {
* @param child input relational expression
* @param exps set of expressions for the input columns
* @param fieldNames aliases of the expressions
* @param flags Flags; values as in {@link Project.Flags},
* usually {@link Project.Flags#BOXED}
*/
public LogicalProject(
RelOptCluster cluster,
RelNode child,
List<RexNode> exps,
List<String> fieldNames,
int flags) {
List<String> fieldNames) {
this(
cluster,
cluster.traitSetOf(RelCollationImpl.EMPTY),
Expand All @@ -61,8 +58,7 @@ public LogicalProject(
RexUtil.createStructType(
cluster.getTypeFactory(),
exps,
fieldNames),
flags);
fieldNames));
}

/**
Expand All @@ -73,17 +69,14 @@ public LogicalProject(
* @param child input relational expression
* @param exps List of expressions for the input columns
* @param rowType output row type
* @param flags Flags; values as in {@link Project.Flags},
* usually {@link Project.Flags#BOXED}
*/
public LogicalProject(
RelOptCluster cluster,
RelTraitSet traitSet,
RelNode child,
List<? extends RexNode> exps,
RelDataType rowType,
int flags) {
super(cluster, traitSet, child, exps, rowType, flags);
RelDataType rowType) {
super(cluster, traitSet, child, exps, rowType);
assert traitSet.containsIfApplicable(Convention.NONE);
}

Expand All @@ -98,8 +91,7 @@ public LogicalProject(RelInput input) {

@Override public LogicalProject copy(RelTraitSet traitSet, RelNode input,
List<RexNode> exps, RelDataType rowType) {
return new LogicalProject(getCluster(), traitSet, input, exps, rowType,
flags);
return new LogicalProject(getCluster(), traitSet, input, exps, rowType);
}

@Override public RelNode accept(RelShuttle shuttle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ public void onMatch(RelOptRuleCall call) {
project.getTraitSet(),
project.getInput(),
expList,
project.getRowType(),
LogicalProject.Flags.BOXED));
project.getRowType()));

// New plan is absolutely better than old plan.
call.getPlanner().setImportance(project, 0.0);
Expand Down
Loading