Skip to content
Open
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
2 changes: 1 addition & 1 deletion data/conf/hive-log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ logger.CalcitePlanner.name = org.apache.calcite.plan.RelOptPlanner
logger.CalcitePlanner.level = INFO

# Change logger level to DEBUG, to see all application of CBO rules and the operators they produce
logger.CBORuleLogger.name = org.apache.hadoop.hive.ql.optimizer.calcite.RuleEventLogger
logger.CBORuleLogger.name = org.apache.calcite.plan.RuleEventLogger
logger.CBORuleLogger.level = OFF
logger.CBORuleLogger.filter.marker.type = MarkerFilter
logger.CBORuleLogger.filter.marker.marker = FULL_PLAN
Expand Down
68 changes: 0 additions & 68 deletions ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/Bug.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,78 +42,10 @@ public final class Bug {
*/
public static final boolean CALCITE_4166_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-4499">issue
* CALCITE-4499</a> is fixed.
*/
public static final boolean CALCITE_4499_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-4200">issue
* CALCITE-4200</a> is fixed.
*/
public static final boolean CALCITE_4200_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-4513">issue
* CALCITE-4513</a> is fixed.
*/
public static final boolean CALCITE_4513_FIXED=false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-4574">CALCITE-4574</a> is fixed.
*/
public static final boolean CALCITE_4574_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-4704">CALCITE-4704</a> is fixed.
*/
public static final boolean CALCITE_4704_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-5293">CALCITE-5293</a> is fixed.
*/
public static final boolean CALCITE_5293_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-5294">CALCITE-5294</a> is fixed.
*/
public static final boolean CALCITE_5294_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-5337">CALCITE-5337</a> is fixed.
*/
public static final boolean CALCITE_5337_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-5669">CALCITE-5669</a> is fixed.
*/
public static final boolean CALCITE_5669_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-5669">CALCITE-5985</a> is fixed.
*/
public static final boolean CALCITE_5985_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-6513">CALCITE-6513</a> is fixed.
*/
public static final boolean CALCITE_6513_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-6704">CALCITE-6704</a> is fixed.
*/
public static final boolean CALCITE_6704_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-6513">CALCITE-6737</a> is fixed.
*/
public static final boolean CALCITE_6737_FIXED = false;

/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-6954">CALCITE-6954</a> is fixed.
*/
public static final boolean CALCITE_6954_FIXED = false;
/**
* Whether <a href="https://issues.apache.org/jira/browse/CALCITE-6832">CALCITE-6832</a> is fixed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,13 @@
*/
package org.apache.hadoop.hive.ql.optimizer.calcite;

import com.google.common.collect.Iterables;
import org.apache.calcite.avatica.util.TimeUnitRange;
import org.apache.calcite.plan.Context;
import org.apache.calcite.plan.Contexts;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptSchema;
import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.CorrelationId;
import org.apache.calcite.rel.core.Join;
import org.apache.calcite.rel.core.JoinRelType;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.rex.RexCorrelVariable;
import org.apache.calcite.rex.RexInputRef;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexShuttle;
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.server.CalciteServerStatement;
Expand All @@ -44,14 +34,8 @@
import org.apache.calcite.tools.Frameworks;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.tools.RelBuilderFactory;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.Litmus;
import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFloorDate;

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

/**
* Builder for relational expressions in Hive.
*
Expand Down Expand Up @@ -90,7 +74,7 @@ public static RelBuilderFactory proto(final Context context) {
return new RelBuilderFactory() {
@Override
public RelBuilder create(RelOptCluster cluster, RelOptSchema schema) {
Context confContext = Contexts.of(Config.DEFAULT.withPruneInputOfAggregate(Bug.CALCITE_4513_FIXED)
Context confContext = Contexts.of(Config.DEFAULT.withPruneInputOfAggregate(false) // TODO clarify CALCITE_4513
.withSimplifyValues(false)); // disabled to avoid simplifications that can create non-empty HiveValues
return new HiveRelBuilder(Contexts.chain(context, confContext), cluster, schema);
}
Expand Down Expand Up @@ -133,88 +117,4 @@ public static SqlFunction getFloorSqlFunction(TimeUnitRange flag) {
}
return SqlStdOperatorTable.FLOOR;
}

/** Creates a {@link Join} with correlating variables. */
@Override
public RelBuilder join(JoinRelType joinType, RexNode condition,
Set<CorrelationId> variablesSet) {
if (Bug.CALCITE_4574_FIXED) {
throw new IllegalStateException("Method overriding should be removed once CALCITE-4574 is fixed");
}
RelNode right = this.peek(0);
RelNode left = this.peek(1);
final boolean correlate = variablesSet.size() == 1;
RexNode postCondition = literal(true);
if (correlate) {
final CorrelationId id = Iterables.getOnlyElement(variablesSet);
if (!RelOptUtil.notContainsCorrelation(left, id, Litmus.IGNORE)) {
throw new IllegalArgumentException("variable " + id
+ " must not be used by left input to correlation");
}
// Correlate does not have an ON clause.
switch (joinType) {
case LEFT:
case SEMI:
case ANTI:
// For a LEFT/SEMI/ANTI, predicate must be evaluated first.
filter(condition.accept(new Shifter(left, id, right)));
right = this.peek(0);
break;
case INNER:
// For INNER, we can defer.
postCondition = condition;
break;
default:
throw new IllegalArgumentException("Correlated " + joinType + " join is not supported");
}
final ImmutableBitSet requiredColumns = RelOptUtil.correlationColumns(id, right);
List<RexNode> leftFields = this.fields(2, 0);
List<RexNode> requiredFields = new ArrayList<>();
for (int i = 0; i < leftFields.size(); i++) {
if (requiredColumns.get(i)) {
requiredFields.add(leftFields.get(i));
}
}
correlate(joinType, id, requiredFields);
filter(postCondition);
} else {
// When there is no correlation use the default logic which works OK for now
// Cannot copy-paste the respective code here cause we don't have access to stack,
// Frame etc. and we might lose existing aliases in the builder
assert variablesSet.isEmpty();
super.join(joinType,condition, variablesSet);
}
return this;
}

/** Shuttle that shifts a predicate's inputs to the left, replacing early
* ones with references to a
* {@link 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;
if (Bug.CALCITE_4574_FIXED) {
throw new IllegalStateException("Class should be redundant once CALCITE-4574 is fixed");
}
}

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);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -728,20 +728,6 @@ public static PKFKJoinInfo extractPKFKJoin(
return cannotExtract;
}

public static RexNode pushPastProjectUnlessBloat(RexNode node, Project project, int bloat) {
if (Bug.CALCITE_6513_FIXED) {
throw new IllegalStateException("Method is redundant when the fix for CALCITE-6513 is merged into Calcite. " +
"Use RelOptUtil.pushPastProjectUnlessBloat");
}

List<RexNode> newConditions =
RelOptUtil.pushPastProjectUnlessBloat(Collections.singletonList(node), project, bloat);
if (newConditions == null || newConditions.size() != 1) {
return null;
}
return newConditions.get(0);
}

public static class PKFKJoinInfo {
public final boolean isPkFkJoin;
public final Pair<ImmutableBitSet, ImmutableBitSet> pkFkJoinColumns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,13 @@
package org.apache.hadoop.hive.ql.optimizer.calcite;

import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.util.ConversionUtil;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.nio.charset.Charset;
import java.util.List;

public class HiveTypeFactory extends JavaTypeFactoryImpl {
public HiveTypeFactory() {
super(new HiveTypeSystemImpl());
if (Bug.CALCITE_6954_FIXED) {
throw new IllegalStateException("Class redundant once fix is merged");
}
}

@Override
protected @Nullable RelDataType leastRestrictiveArrayMultisetType(final List<RelDataType> types,
final SqlTypeName sqlTypeName) {
RelDataType type = super.leastRestrictiveArrayMultisetType(types, sqlTypeName);
if (type != null) {
return canonize(type);
}
return null;
}

@Override
protected @Nullable RelDataType leastRestrictiveMapType(final List<RelDataType> types,
final SqlTypeName sqlTypeName) {
RelDataType type = super.leastRestrictiveMapType(types, sqlTypeName);
if (type != null) {
return canonize(type);
}
return null;
}

@Override
Expand Down

This file was deleted.

Loading
Loading