@Override
    public Result apply(ApplyNode applyNode, Captures captures, Context context)
    {
        if (applyNode.getSubqueryAssignments().size() != 1) {
            return Result.empty();
        }

        RowExpression expression = getOnlyElement(applyNode.getSubqueryAssignments().getExpressions());
        if (!(expression instanceof InSubqueryExpression)) {
            return Result.empty();
        }
        InSubqueryExpression inPredicate = (InSubqueryExpression) expression;

        VariableReferenceExpression semiJoinVariable = getOnlyElement(applyNode.getSubqueryAssignments().getVariables());

        SemiJoinNode replacement = new SemiJoinNode(
                applyNode.getSourceLocation(),
                context.getIdAllocator().getNextId(),
                applyNode.getInput(),
                applyNode.getSubquery(),
                inPredicate.getValue(),
                inPredicate.getSubquery(),
                semiJoinVariable,
                Optional.empty(),
                Optional.empty(),
                Optional.empty(),
                ImmutableMap.of());

        return Result.ofPlanNode(replacement);
    }
@Test
    public void testDoesNotFireOnNonInPredicateSubquery()
    {
        tester().assertThat(new TransformUncorrelatedInPredicateSubqueryToSemiJoin())
                .on(p -> p.apply(
                        assignment(p.variable("x"), new ExistsExpression(Optional.empty(), TRUE_CONSTANT)),
                        emptyList(),
                        p.values(),
                        p.values()))
                .doesNotFire();
    }