use of io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN in project trino by trinodb.
the class TestRemoveUnreferencedScalarSubqueries method testDoNotRemoveInputOfLeftOrFullJoinWhenSubqueryPotentiallyEmpty.
@Test
public void testDoNotRemoveInputOfLeftOrFullJoinWhenSubqueryPotentiallyEmpty() {
tester().assertThat(new RemoveUnreferencedScalarSubqueries()).on(p -> {
Symbol b = p.symbol("b");
return p.correlatedJoin(emptyList(), p.values(emptyList(), ImmutableList.of(emptyList())), LEFT, TRUE_LITERAL, p.filter(new ComparisonExpression(LESS_THAN, b.toSymbolReference(), new LongLiteral("3")), p.values(2, b)));
}).doesNotFire();
tester().assertThat(new RemoveUnreferencedScalarSubqueries()).on(p -> {
Symbol b = p.symbol("b");
return p.correlatedJoin(emptyList(), p.values(emptyList(), ImmutableList.of(emptyList())), FULL, TRUE_LITERAL, p.filter(new ComparisonExpression(LESS_THAN, b.toSymbolReference(), new LongLiteral("3")), p.values(2, b)));
}).doesNotFire();
}
use of io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN in project trino by trinodb.
the class TestTransformCorrelatedJoinToJoin method testRewriteInnerCorrelatedJoin.
@Test
public void testRewriteInnerCorrelatedJoin() {
tester().assertThat(new TransformCorrelatedJoinToJoin(tester().getPlannerContext())).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
return p.correlatedJoin(ImmutableList.of(a), p.values(a), p.filter(new ComparisonExpression(GREATER_THAN, b.toSymbolReference(), a.toSymbolReference()), p.values(b)));
}).matches(join(JoinNode.Type.INNER, ImmutableList.of(), Optional.of("b > a"), values("a"), filter(TRUE_LITERAL, values("b"))));
tester().assertThat(new TransformCorrelatedJoinToJoin(tester().getPlannerContext())).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
return p.correlatedJoin(ImmutableList.of(a), p.values(a), INNER, new ComparisonExpression(LESS_THAN, b.toSymbolReference(), new LongLiteral("3")), p.filter(new ComparisonExpression(GREATER_THAN, b.toSymbolReference(), a.toSymbolReference()), p.values(b)));
}).matches(join(JoinNode.Type.INNER, ImmutableList.of(), Optional.of("b > a AND b < 3"), values("a"), filter(TRUE_LITERAL, values("b"))));
}
use of io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN in project trino by trinodb.
the class ExtractSpatialJoins method tryCreateSpatialJoin.
private static Result tryCreateSpatialJoin(Context context, JoinNode joinNode, Expression filter, PlanNodeId nodeId, List<Symbol> outputSymbols, ComparisonExpression spatialComparison, PlannerContext plannerContext, SplitManager splitManager, PageSourceManager pageSourceManager, TypeAnalyzer typeAnalyzer) {
PlanNode leftNode = joinNode.getLeft();
PlanNode rightNode = joinNode.getRight();
List<Symbol> leftSymbols = leftNode.getOutputSymbols();
List<Symbol> rightSymbols = rightNode.getOutputSymbols();
Expression radius;
Optional<Symbol> newRadiusSymbol;
ComparisonExpression newComparison;
if (spatialComparison.getOperator() == LESS_THAN || spatialComparison.getOperator() == LESS_THAN_OR_EQUAL) {
// ST_Distance(a, b) <= r
radius = spatialComparison.getRight();
Set<Symbol> radiusSymbols = extractUnique(radius);
if (radiusSymbols.isEmpty() || (rightSymbols.containsAll(radiusSymbols) && containsNone(leftSymbols, radiusSymbols))) {
newRadiusSymbol = newRadiusSymbol(context, radius);
newComparison = new ComparisonExpression(spatialComparison.getOperator(), spatialComparison.getLeft(), toExpression(newRadiusSymbol, radius));
} else {
return Result.empty();
}
} else {
// r >= ST_Distance(a, b)
radius = spatialComparison.getLeft();
Set<Symbol> radiusSymbols = extractUnique(radius);
if (radiusSymbols.isEmpty() || (rightSymbols.containsAll(radiusSymbols) && containsNone(leftSymbols, radiusSymbols))) {
newRadiusSymbol = newRadiusSymbol(context, radius);
newComparison = new ComparisonExpression(spatialComparison.getOperator().flip(), spatialComparison.getRight(), toExpression(newRadiusSymbol, radius));
} else {
return Result.empty();
}
}
Expression newFilter = replaceExpression(filter, ImmutableMap.of(spatialComparison, newComparison));
PlanNode newRightNode = newRadiusSymbol.map(symbol -> addProjection(context, rightNode, symbol, radius)).orElse(rightNode);
JoinNode newJoinNode = new JoinNode(joinNode.getId(), joinNode.getType(), leftNode, newRightNode, joinNode.getCriteria(), joinNode.getLeftOutputSymbols(), joinNode.getRightOutputSymbols(), joinNode.isMaySkipOutputDuplicates(), Optional.of(newFilter), joinNode.getLeftHashSymbol(), joinNode.getRightHashSymbol(), joinNode.getDistributionType(), joinNode.isSpillable(), joinNode.getDynamicFilters(), joinNode.getReorderJoinStatsAndCost());
return tryCreateSpatialJoin(context, newJoinNode, newFilter, nodeId, outputSymbols, (FunctionCall) newComparison.getLeft(), Optional.of(newComparison.getRight()), plannerContext, splitManager, pageSourceManager, typeAnalyzer);
}
use of io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN in project trino by trinodb.
the class TestTransformCorrelatedJoinToJoin method testRewriteLeftCorrelatedJoin.
@Test
public void testRewriteLeftCorrelatedJoin() {
tester().assertThat(new TransformCorrelatedJoinToJoin(tester().getPlannerContext())).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
return p.correlatedJoin(ImmutableList.of(a), p.values(a), LEFT, TRUE_LITERAL, p.filter(new ComparisonExpression(GREATER_THAN, b.toSymbolReference(), a.toSymbolReference()), p.values(b)));
}).matches(join(JoinNode.Type.LEFT, ImmutableList.of(), Optional.of("b > a"), values("a"), filter(TRUE_LITERAL, values("b"))));
tester().assertThat(new TransformCorrelatedJoinToJoin(tester().getPlannerContext())).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
return p.correlatedJoin(ImmutableList.of(a), p.values(a), LEFT, new ComparisonExpression(LESS_THAN, b.toSymbolReference(), new LongLiteral("3")), p.filter(new ComparisonExpression(GREATER_THAN, b.toSymbolReference(), a.toSymbolReference()), p.values(b)));
}).matches(join(JoinNode.Type.LEFT, ImmutableList.of(), Optional.of("b > a AND b < 3"), values("a"), filter(TRUE_LITERAL, values("b"))));
}
Aggregations