Skip to content

Commit

Permalink
Move ComparisonExpression.Type to the top level
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Statkevich committed Nov 2, 2016
1 parent 1920e38 commit bb8df29
Show file tree
Hide file tree
Showing 26 changed files with 184 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

import static com.facebook.presto.sql.tree.BooleanLiteral.FALSE_LITERAL;
import static com.facebook.presto.sql.tree.BooleanLiteral.TRUE_LITERAL;
import static com.facebook.presto.sql.tree.ComparisonExpression.Type.IS_DISTINCT_FROM;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.IS_DISTINCT_FROM;
import static com.facebook.presto.util.ImmutableCollectors.toImmutableList;
import static com.facebook.presto.util.ImmutableCollectors.toImmutableSet;
import static java.util.Objects.requireNonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
import static com.facebook.presto.sql.analyzer.SemanticErrorCode.VIEW_PARSE_ERROR;
import static com.facebook.presto.sql.analyzer.SemanticErrorCode.WILDCARD_WITHOUT_FROM;
import static com.facebook.presto.sql.planner.ExpressionInterpreter.expressionOptimizer;
import static com.facebook.presto.sql.tree.ComparisonExpression.Type.EQUAL;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.EQUAL;
import static com.facebook.presto.sql.tree.ExplainType.Type.DISTRIBUTED;
import static com.facebook.presto.sql.tree.FrameBound.Type.CURRENT_ROW;
import static com.facebook.presto.sql.tree.FrameBound.Type.FOLLOWING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.facebook.presto.sql.tree.BetweenPredicate;
import com.facebook.presto.sql.tree.BooleanLiteral;
import com.facebook.presto.sql.tree.ComparisonExpression;
import com.facebook.presto.sql.tree.ComparisonExpressionType;
import com.facebook.presto.sql.tree.Expression;
import com.facebook.presto.sql.tree.InListExpression;
import com.facebook.presto.sql.tree.InPredicate;
Expand Down Expand Up @@ -65,12 +66,12 @@
import static com.facebook.presto.sql.planner.LiteralInterpreter.toExpression;
import static com.facebook.presto.sql.tree.BooleanLiteral.FALSE_LITERAL;
import static com.facebook.presto.sql.tree.BooleanLiteral.TRUE_LITERAL;
import static com.facebook.presto.sql.tree.ComparisonExpression.Type.EQUAL;
import static com.facebook.presto.sql.tree.ComparisonExpression.Type.GREATER_THAN;
import static com.facebook.presto.sql.tree.ComparisonExpression.Type.GREATER_THAN_OR_EQUAL;
import static com.facebook.presto.sql.tree.ComparisonExpression.Type.LESS_THAN;
import static com.facebook.presto.sql.tree.ComparisonExpression.Type.LESS_THAN_OR_EQUAL;
import static com.facebook.presto.sql.tree.ComparisonExpression.Type.NOT_EQUAL;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.EQUAL;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.GREATER_THAN;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.GREATER_THAN_OR_EQUAL;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.LESS_THAN;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.LESS_THAN_OR_EQUAL;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.NOT_EQUAL;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.getOnlyElement;
Expand Down Expand Up @@ -428,7 +429,7 @@ private Optional<NullableValue> coerce(NullableValue value, Type targetType)
return Optional.of(NullableValue.of(targetType, coercedValue));
}

private ExtractionResult createComparisonExtractionResult(ComparisonExpression.Type comparisonType, Symbol column, Type type, @Nullable Object value, boolean complement)
private ExtractionResult createComparisonExtractionResult(ComparisonExpressionType comparisonType, Symbol column, Type type, @Nullable Object value, boolean complement)
{
if (value == null) {
switch (comparisonType) {
Expand Down Expand Up @@ -467,7 +468,7 @@ else if (type.isComparable()) {
TRUE_LITERAL);
}

private static Domain extractOrderableDomain(ComparisonExpression.Type comparisonType, Type type, Object value, boolean complement)
private static Domain extractOrderableDomain(ComparisonExpressionType comparisonType, Type type, Object value, boolean complement)
{
checkArgument(value != null);
switch (comparisonType) {
Expand All @@ -491,7 +492,7 @@ private static Domain extractOrderableDomain(ComparisonExpression.Type compariso
}
}

private static Domain extractEquatableDomain(ComparisonExpression.Type comparisonType, Type type, Object value, boolean complement)
private static Domain extractEquatableDomain(ComparisonExpressionType comparisonType, Type type, Object value, boolean complement)
{
checkArgument(value != null);
switch (comparisonType) {
Expand All @@ -512,7 +513,7 @@ private Optional<Expression> coerceComparisonWithRounding(
SymbolReference fieldReference,
Type valueType,
Object value,
ComparisonExpression.Type comparisonType)
ComparisonExpressionType comparisonType)
{
requireNonNull(value, "value is null");
return floorValue(valueType, fieldType, value)
Expand All @@ -525,7 +526,7 @@ private Expression rewriteComparisonExpression(
Type valueType,
Object originalValue,
Object coercedValue,
ComparisonExpression.Type comparisonType)
ComparisonExpressionType comparisonType)
{
int originalComparedToCoerced = compareOriginalValueToCoerced(valueType, originalValue, fieldType, coercedValue);
boolean coercedValueIsEqualToOriginal = originalComparedToCoerced == 0;
Expand Down Expand Up @@ -700,10 +701,10 @@ private static Optional<NormalizedSimpleComparison> toNormalizedSimpleComparison
private static class NormalizedSimpleComparison
{
private final SymbolReference nameReference;
private final ComparisonExpression.Type comparisonType;
private final ComparisonExpressionType comparisonType;
private final NullableValue value;

public NormalizedSimpleComparison(SymbolReference nameReference, ComparisonExpression.Type comparisonType, NullableValue value)
public NormalizedSimpleComparison(SymbolReference nameReference, ComparisonExpressionType comparisonType, NullableValue value)
{
this.nameReference = requireNonNull(nameReference, "nameReference is null");
this.comparisonType = requireNonNull(comparisonType, "comparisonType is null");
Expand All @@ -715,7 +716,7 @@ public SymbolReference getNameReference()
return nameReference;
}

public ComparisonExpression.Type getComparisonType()
public ComparisonExpressionType getComparisonType()
{
return comparisonType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.facebook.presto.sql.planner.plan.UnionNode;
import com.facebook.presto.sql.planner.plan.WindowNode;
import com.facebook.presto.sql.tree.ComparisonExpression;
import com.facebook.presto.sql.tree.ComparisonExpressionType;
import com.facebook.presto.sql.tree.Expression;
import com.facebook.presto.sql.tree.SymbolReference;
import com.google.common.collect.ImmutableBiMap;
Expand Down Expand Up @@ -81,7 +82,7 @@ public static Expression extract(PlanNode node, Map<Symbol, Type> symbolTypes)
SymbolReference reference = entry.getKey().toSymbolReference();
Expression expression = entry.getValue();
// TODO: switch this to 'IS NOT DISTINCT FROM' syntax when EqualityInference properly supports it
return new ComparisonExpression(ComparisonExpression.Type.EQUAL, reference, expression);
return new ComparisonExpression(ComparisonExpressionType.EQUAL, reference, expression);
};

private final Map<Symbol, Type> symbolTypes;
Expand Down Expand Up @@ -224,7 +225,7 @@ public Expression visitJoin(JoinNode node, Void context)

List<Expression> joinConjuncts = new ArrayList<>();
for (JoinNode.EquiJoinClause clause : node.getCriteria()) {
joinConjuncts.add(new ComparisonExpression(ComparisonExpression.Type.EQUAL,
joinConjuncts.add(new ComparisonExpression(ComparisonExpressionType.EQUAL,
clause.getLeft().toSymbolReference(),
clause.getRight().toSymbolReference()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.facebook.presto.sql.planner;

import com.facebook.presto.sql.tree.ComparisonExpression;
import com.facebook.presto.sql.tree.ComparisonExpressionType;
import com.facebook.presto.sql.tree.Expression;
import com.facebook.presto.sql.tree.ExpressionTreeRewriter;
import com.facebook.presto.sql.tree.InListExpression;
Expand Down Expand Up @@ -189,13 +190,13 @@ public EqualityPartition generateEqualitiesPartitionedBy(Predicate<Symbol> symbo
Expression matchingCanonical = getCanonical(scopeExpressions);
if (scopeExpressions.size() >= 2) {
for (Expression expression : filter(scopeExpressions, not(equalTo(matchingCanonical)))) {
scopeEqualities.add(new ComparisonExpression(ComparisonExpression.Type.EQUAL, matchingCanonical, expression));
scopeEqualities.add(new ComparisonExpression(ComparisonExpressionType.EQUAL, matchingCanonical, expression));
}
}
Expression complementCanonical = getCanonical(scopeComplementExpressions);
if (scopeComplementExpressions.size() >= 2) {
for (Expression expression : filter(scopeComplementExpressions, not(equalTo(complementCanonical)))) {
scopeComplementEqualities.add(new ComparisonExpression(ComparisonExpression.Type.EQUAL, complementCanonical, expression));
scopeComplementEqualities.add(new ComparisonExpression(ComparisonExpressionType.EQUAL, complementCanonical, expression));
}
}

Expand All @@ -208,7 +209,7 @@ public EqualityPartition generateEqualitiesPartitionedBy(Predicate<Symbol> symbo
Expression connectingCanonical = getCanonical(connectingExpressions);
if (connectingCanonical != null) {
for (Expression expression : filter(connectingExpressions, not(equalTo(connectingCanonical)))) {
scopeStraddlingEqualities.add(new ComparisonExpression(ComparisonExpression.Type.EQUAL, connectingCanonical, expression));
scopeStraddlingEqualities.add(new ComparisonExpression(ComparisonExpressionType.EQUAL, connectingCanonical, expression));
}
}
}
Expand Down Expand Up @@ -255,7 +256,7 @@ public static Predicate<Expression> isInferenceCandidate()
expression = normalizeInPredicateToEquality(expression);
if (expression instanceof ComparisonExpression && DeterminismEvaluator.isDeterministic(expression) && !NullabilityAnalyzer.mayReturnNullOnNonNullInput(expression)) {
ComparisonExpression comparison = (ComparisonExpression) expression;
if (comparison.getType() == ComparisonExpression.Type.EQUAL) {
if (comparison.getType() == ComparisonExpressionType.EQUAL) {
// We should only consider equalities that have distinct left and right components
return !comparison.getLeft().equals(comparison.getRight());
}
Expand All @@ -274,7 +275,7 @@ private static Expression normalizeInPredicateToEquality(Expression expression)
if (inPredicate.getValueList() instanceof InListExpression) {
InListExpression valueList = (InListExpression) inPredicate.getValueList();
if (valueList.getValues().size() == 1) {
return new ComparisonExpression(ComparisonExpression.Type.EQUAL, inPredicate.getValue(), Iterables.getOnlyElement(valueList.getValues()));
return new ComparisonExpression(ComparisonExpressionType.EQUAL, inPredicate.getValue(), Iterables.getOnlyElement(valueList.getValues()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.facebook.presto.sql.tree.Cast;
import com.facebook.presto.sql.tree.CoalesceExpression;
import com.facebook.presto.sql.tree.ComparisonExpression;
import com.facebook.presto.sql.tree.ComparisonExpressionType;
import com.facebook.presto.sql.tree.DefaultTraversalVisitor;
import com.facebook.presto.sql.tree.DereferenceExpression;
import com.facebook.presto.sql.tree.ExistsPredicate;
Expand Down Expand Up @@ -763,15 +764,15 @@ protected Object visitArithmeticBinary(ArithmeticBinaryExpression node, Object c
@Override
protected Object visitComparisonExpression(ComparisonExpression node, Object context)
{
ComparisonExpression.Type type = node.getType();
ComparisonExpressionType type = node.getType();

Object left = process(node.getLeft(), context);
if (left == null && type != ComparisonExpression.Type.IS_DISTINCT_FROM) {
if (left == null && type != ComparisonExpressionType.IS_DISTINCT_FROM) {
return null;
}

Object right = process(node.getRight(), context);
if (type == ComparisonExpression.Type.IS_DISTINCT_FROM) {
if (type == ComparisonExpressionType.IS_DISTINCT_FROM) {
if (left == null && right == null) {
return false;
}
Expand Down Expand Up @@ -995,7 +996,7 @@ protected Object visitLikePredicate(LikePredicate node, Object context)
if (pattern instanceof Slice && escape == null) {
String stringPattern = ((Slice) pattern).toStringUtf8();
if (!stringPattern.contains("%") && !stringPattern.contains("_")) {
return new ComparisonExpression(ComparisonExpression.Type.EQUAL,
return new ComparisonExpression(ComparisonExpressionType.EQUAL,
toExpression(value, expressionTypes.get(node.getValue())),
toExpression(pattern, expressionTypes.get(node.getPattern())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import com.facebook.presto.sql.planner.plan.ValuesNode;
import com.facebook.presto.sql.planner.plan.WindowNode;
import com.facebook.presto.sql.tree.ComparisonExpression;
import com.facebook.presto.sql.tree.ComparisonExpressionType;
import com.facebook.presto.sql.tree.Expression;
import com.facebook.presto.sql.tree.FunctionCall;
import com.facebook.presto.sql.tree.SymbolReference;
Expand Down Expand Up @@ -417,7 +418,7 @@ public Void visitJoin(JoinNode node, Integer indent)
{
List<Expression> joinExpressions = new ArrayList<>();
for (JoinNode.EquiJoinClause clause : node.getCriteria()) {
joinExpressions.add(new ComparisonExpression(ComparisonExpression.Type.EQUAL,
joinExpressions.add(new ComparisonExpression(ComparisonExpressionType.EQUAL,
clause.getLeft().toSymbolReference(),
clause.getRight().toSymbolReference()));
}
Expand Down Expand Up @@ -475,7 +476,7 @@ public Void visitIndexJoin(IndexJoinNode node, Integer indent)
{
List<Expression> joinExpressions = new ArrayList<>();
for (IndexJoinNode.EquiJoinClause clause : node.getCriteria()) {
joinExpressions.add(new ComparisonExpression(ComparisonExpression.Type.EQUAL,
joinExpressions.add(new ComparisonExpression(ComparisonExpressionType.EQUAL,
clause.getProbe().toSymbolReference(),
clause.getIndex().toSymbolReference()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.facebook.presto.sql.tree.Cast;
import com.facebook.presto.sql.tree.CoalesceExpression;
import com.facebook.presto.sql.tree.ComparisonExpression;
import com.facebook.presto.sql.tree.ComparisonExpressionType;
import com.facebook.presto.sql.tree.DefaultTraversalVisitor;
import com.facebook.presto.sql.tree.Except;
import com.facebook.presto.sql.tree.Expression;
Expand Down Expand Up @@ -213,7 +214,7 @@ protected RelationPlan visitJoin(Join node, Void context)

List<Expression> leftComparisonExpressions = new ArrayList<>();
List<Expression> rightComparisonExpressions = new ArrayList<>();
List<ComparisonExpression.Type> joinConditionComparisonTypes = new ArrayList<>();
List<ComparisonExpressionType> joinConditionComparisonTypes = new ArrayList<>();

for (Expression conjunct : ExpressionUtils.extractConjuncts(criteria)) {
conjunct = ExpressionUtils.normalize(conjunct);
Expand All @@ -226,7 +227,7 @@ protected RelationPlan visitJoin(Join node, Void context)
if (conjunct instanceof ComparisonExpression) {
Expression firstExpression = ((ComparisonExpression) conjunct).getLeft();
Expression secondExpression = ((ComparisonExpression) conjunct).getRight();
ComparisonExpression.Type comparisonType = ((ComparisonExpression) conjunct).getType();
ComparisonExpressionType comparisonType = ((ComparisonExpression) conjunct).getType();
Set<QualifiedName> firstDependencies = DependencyExtractor.extractNames(firstExpression, analysis.getColumnReferences());
Set<QualifiedName> secondDependencies = DependencyExtractor.extractNames(secondExpression, analysis.getColumnReferences());

Expand Down Expand Up @@ -258,7 +259,7 @@ else if (firstDependencies.stream().allMatch(right.canResolvePredicate()) && sec
rightPlanBuilder = rightPlanBuilder.appendProjections(rightComparisonExpressions, symbolAllocator, idAllocator);

for (int i = 0; i < leftComparisonExpressions.size(); i++) {
if (joinConditionComparisonTypes.get(i) == ComparisonExpression.Type.EQUAL) {
if (joinConditionComparisonTypes.get(i) == ComparisonExpressionType.EQUAL) {
Symbol leftSymbol = leftPlanBuilder.translate(leftComparisonExpressions.get(i));
Symbol rightSymbol = rightPlanBuilder.translate(rightComparisonExpressions.get(i));

Expand Down Expand Up @@ -336,7 +337,7 @@ else if (firstDependencies.stream().allMatch(right.canResolvePredicate()) && sec

private boolean isEqualComparisonExpression(Expression conjunct)
{
return conjunct instanceof ComparisonExpression && ((ComparisonExpression) conjunct).getType() == ComparisonExpression.Type.EQUAL;
return conjunct instanceof ComparisonExpression && ((ComparisonExpression) conjunct).getType() == ComparisonExpressionType.EQUAL;
}

private RelationPlan planCrossJoinUnnest(RelationPlan leftPlan, Join joinNode, Unnest node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import static com.facebook.presto.sql.analyzer.SemanticExceptions.throwNotSupportedException;
import static com.facebook.presto.sql.planner.ExpressionNodeInliner.replaceExpression;
import static com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher.searchFrom;
import static com.facebook.presto.sql.tree.ComparisonExpression.Type.GREATER_THAN;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.GREATER_THAN;
import static com.facebook.presto.sql.util.AstUtils.nodeContains;
import static com.facebook.presto.util.ImmutableCollectors.toImmutableList;
import static com.facebook.presto.util.ImmutableCollectors.toImmutableMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
import static com.facebook.presto.sql.planner.plan.AggregationNode.Step;
import static com.facebook.presto.sql.tree.BooleanLiteral.TRUE_LITERAL;
import static com.facebook.presto.sql.tree.ComparisonExpression.Type.EQUAL;
import static com.facebook.presto.sql.tree.ComparisonExpression.Type.GREATER_THAN_OR_EQUAL;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.EQUAL;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.GREATER_THAN_OR_EQUAL;
import static com.facebook.presto.util.ImmutableCollectors.toImmutableList;
import static com.google.common.collect.Iterables.concat;
import static java.util.Objects.requireNonNull;
Expand Down
Loading

0 comments on commit bb8df29

Please sign in to comment.