use of io.prestosql.sql.tree.ComparisonExpression in project hetu-core by openlookeng.
the class TransformUnCorrelatedInPredicateSubQuerySelfJoinToAggregate method getAllSymbols.
private static void getAllSymbols(Expression expression, List<SymbolReference> symbols) {
if (expression instanceof LogicalBinaryExpression) {
LogicalBinaryExpression logicalBinaryExpression = (LogicalBinaryExpression) expression;
getAllSymbols(logicalBinaryExpression.getLeft(), symbols);
getAllSymbols(logicalBinaryExpression.getRight(), symbols);
} else if (expression instanceof ComparisonExpression) {
ComparisonExpression comparisonExpression = (ComparisonExpression) expression;
getAllSymbols(comparisonExpression.getLeft(), symbols);
getAllSymbols(comparisonExpression.getRight(), symbols);
} else if (expression instanceof SymbolReference) {
symbols.add((SymbolReference) expression);
}
}
use of io.prestosql.sql.tree.ComparisonExpression in project hetu-core by openlookeng.
the class TransformUnCorrelatedInPredicateSubQuerySelfJoinToAggregate method isSelfJoin.
private static boolean isSelfJoin(ProjectNode projectNode, Expression predicate, JoinNode joinNode, Lookup lookup) {
PlanNode left = lookup.resolve(joinNode.getLeft());
PlanNode right = lookup.resolve(joinNode.getRight());
// TODO FIX FOR framenwork changes
if (joinNode.getType() == JoinNode.Type.INNER && left instanceof TableScanNode && right instanceof TableScanNode && ((TableScanNode) left).getTable().getFullyQualifiedName().equals(((TableScanNode) right).getTable().getFullyQualifiedName())) {
if (!(predicate instanceof LogicalBinaryExpression && ((LogicalBinaryExpression) predicate).getLeft() instanceof ComparisonExpression && ((LogicalBinaryExpression) predicate).getRight() instanceof ComparisonExpression)) {
return false;
}
SymbolReference projected = SymbolUtils.toSymbolReference(getOnlyElement(projectNode.getOutputSymbols()));
ComparisonExpression leftPredicate = (ComparisonExpression) ((LogicalBinaryExpression) predicate).getLeft();
ComparisonExpression rightPredicate = (ComparisonExpression) ((LogicalBinaryExpression) predicate).getRight();
if (lookup.resolve(projectNode.getSource()) instanceof CTEScanNode) {
CTEScanNode cteScanNode = (CTEScanNode) lookup.resolve(projectNode.getSource());
ProjectNode childProjectOfCte = (ProjectNode) lookup.resolve(cteScanNode.getSource());
RowExpression projectedExpresssion = (childProjectOfCte.getAssignments().get(getOnlyElement(projectNode.getOutputSymbols())));
for (Symbol symbol : lookup.resolve(childProjectOfCte.getSource()).getOutputSymbols()) {
if (symbol.getName().equals(((SymbolReference) OriginalExpressionUtils.castToExpression(projectedExpresssion)).getName())) {
projected = SymbolUtils.toSymbolReference(symbol);
}
}
}
if (leftPredicate.getChildren().contains(projected) && leftPredicate.getOperator() == ComparisonExpression.Operator.EQUAL && rightPredicate.getOperator() == ComparisonExpression.Operator.NOT_EQUAL) {
return true;
} else if (rightPredicate.getChildren().contains(projected) && rightPredicate.getOperator() == ComparisonExpression.Operator.EQUAL && leftPredicate.getOperator() == ComparisonExpression.Operator.NOT_EQUAL) {
return true;
}
}
return false;
}
use of io.prestosql.sql.tree.ComparisonExpression in project hetu-core by openlookeng.
the class SetOperationNodeTranslator method makeSetContainmentPlan.
public TranslationResult makeSetContainmentPlan(SetOperationNode node) {
checkArgument(!(node instanceof UnionNode), "Cannot simplify a UnionNode");
List<Symbol> markers = allocateSymbols(node.getSources().size(), MARKER, BOOLEAN);
// identity projection for all the fields in each of the sources plus marker columns
List<PlanNode> withMarkers = appendMarkers(markers, node.getSources(), node);
// add a union over all the rewritten sources. The outputs of the union have the same name as the
// original intersect node
List<Symbol> outputs = node.getOutputSymbols();
UnionNode union = union(withMarkers, ImmutableList.copyOf(concat(outputs, markers)));
// add count aggregations and filter rows where any of the counts is >= 1
List<Symbol> aggregationOutputs = allocateSymbols(markers.size(), "count", BIGINT);
AggregationNode aggregation = computeCounts(union, outputs, markers, aggregationOutputs);
List<Expression> presentExpression = aggregationOutputs.stream().map(symbol -> new ComparisonExpression(GREATER_THAN_OR_EQUAL, toSymbolReference(symbol), GENERIC_LITERAL)).collect(toImmutableList());
return new TranslationResult(aggregation, presentExpression);
}
use of io.prestosql.sql.tree.ComparisonExpression in project hetu-core by openlookeng.
the class TablePushdown method needNewInnerJoinFilter.
/**
* @param originalJoinNode the original JoinNode captured by the rule
* @param childOfInnerJoin the child of the InnerJoinNode that has to be moved(the outer Table)
* @return boolean signifying if the table being pushed down will need a join filter for the new join
*/
private boolean needNewInnerJoinFilter(JoinNode originalJoinNode, PlanNode childOfInnerJoin) {
if (originalJoinNode.getFilter().isPresent()) {
ComparisonExpression originalJoinNodeFilter = (ComparisonExpression) castToExpression(originalJoinNode.getFilter().get());
List<Symbol> innerJoinChildOPSymbols = childOfInnerJoin.getOutputSymbols();
SymbolReference originalFilterSymbolRefLeft = (SymbolReference) originalJoinNodeFilter.getLeft();
SymbolReference originalFilterSymbolRefRight = (SymbolReference) originalJoinNodeFilter.getRight();
for (Symbol symbol : innerJoinChildOPSymbols) {
if (symbol.toString().equalsIgnoreCase(originalFilterSymbolRefLeft.toString()) || symbol.toString().equalsIgnoreCase(originalFilterSymbolRefRight.toString())) {
return true;
}
}
}
return false;
}
use of io.prestosql.sql.tree.ComparisonExpression in project hetu-core by openlookeng.
the class TransformCorrelatedInPredicateToJoin method buildInPredicateEquivalent.
private PlanNode buildInPredicateEquivalent(ApplyNode apply, InPredicate inPredicate, Symbol inPredicateOutputSymbol, Decorrelated decorrelated, PlanNodeIdAllocator idAllocator, PlanSymbolAllocator planSymbolAllocator) {
Expression correlationCondition = and(decorrelated.getCorrelatedPredicates());
PlanNode decorrelatedBuildSource = decorrelated.getDecorrelatedNode();
AssignUniqueId probeSide = new AssignUniqueId(idAllocator.getNextId(), apply.getInput(), planSymbolAllocator.newSymbol("unique", BIGINT));
Symbol buildSideKnownNonNull = planSymbolAllocator.newSymbol("buildSideKnownNonNull", BIGINT);
ProjectNode buildSide = new ProjectNode(idAllocator.getNextId(), decorrelatedBuildSource, Assignments.builder().putAll(identityAsSymbolReferences(decorrelatedBuildSource.getOutputSymbols())).put(buildSideKnownNonNull, castToRowExpression(bigint(0))).build());
Symbol probeSideSymbol = SymbolUtils.from(inPredicate.getValue());
Symbol buildSideSymbol = SymbolUtils.from(inPredicate.getValueList());
Expression joinExpression = and(or(new IsNullPredicate(toSymbolReference(probeSideSymbol)), new ComparisonExpression(ComparisonExpression.Operator.EQUAL, toSymbolReference(probeSideSymbol), toSymbolReference(buildSideSymbol)), new IsNullPredicate(toSymbolReference(buildSideSymbol))), correlationCondition);
JoinNode leftOuterJoin = leftOuterJoin(idAllocator, probeSide, buildSide, joinExpression);
Symbol matchConditionSymbol = planSymbolAllocator.newSymbol("matchConditionSymbol", BOOLEAN);
Expression matchCondition = and(isNotNull(probeSideSymbol), isNotNull(buildSideSymbol));
Symbol nullMatchConditionSymbol = planSymbolAllocator.newSymbol("nullMatchConditionSymbol", BOOLEAN);
Expression nullMatchCondition = and(isNotNull(buildSideKnownNonNull), not(matchCondition));
ProjectNode preProjection = new ProjectNode(idAllocator.getNextId(), leftOuterJoin, Assignments.builder().putAll(AssignmentUtils.identityAsSymbolReferences(leftOuterJoin.getOutputSymbols())).put(matchConditionSymbol, castToRowExpression(matchCondition)).put(nullMatchConditionSymbol, castToRowExpression(nullMatchCondition)).build());
Symbol countMatchesSymbol = planSymbolAllocator.newSymbol("countMatches", BIGINT);
Symbol countNullMatchesSymbol = planSymbolAllocator.newSymbol("countNullMatches", BIGINT);
AggregationNode aggregation = new AggregationNode(idAllocator.getNextId(), preProjection, ImmutableMap.<Symbol, AggregationNode.Aggregation>builder().put(countMatchesSymbol, countWithFilter(matchConditionSymbol)).put(countNullMatchesSymbol, countWithFilter(nullMatchConditionSymbol)).build(), singleGroupingSet(probeSide.getOutputSymbols()), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty(), AggregationNode.AggregationType.HASH, Optional.empty());
// TODO since we care only about "some count > 0", we could have specialized node instead of leftOuterJoin that does the job without materializing join results
SearchedCaseExpression inPredicateEquivalent = new SearchedCaseExpression(ImmutableList.of(new WhenClause(isGreaterThan(countMatchesSymbol, 0), booleanConstant(true)), new WhenClause(isGreaterThan(countNullMatchesSymbol, 0), booleanConstant(null))), Optional.of(booleanConstant(false)));
return new ProjectNode(idAllocator.getNextId(), aggregation, Assignments.builder().putAll(identityAsSymbolReferences(apply.getInput().getOutputSymbols())).put(inPredicateOutputSymbol, castToRowExpression(inPredicateEquivalent)).build());
}
Aggregations