/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.prestosql.sql.planner.iterative.rule;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.prestosql.sql.planner.assertions.PlanMatchPattern;
import io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest;
import io.prestosql.sql.planner.plan.Assignments;
import io.prestosql.sql.tree.ExistsPredicate;
import org.testng.annotations.Test;

import static io.prestosql.sql.planner.assertions.PlanMatchPattern.project;
import static io.prestosql.sql.planner.assertions.PlanMatchPattern.values;
import static io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL;

public class TestRemoveRedundantExists
        extends BaseRuleTest
{
    @Test
    public void testExistsFalse()
    {
        tester().assertThat(new RemoveRedundantExists())
                .on(p -> p.apply(Assignments.of(p.symbol("exists"), new ExistsPredicate(TRUE_LITERAL)),
                        ImmutableList.of(),
                        p.values(1),
                        p.values(0)))
                .matches(
                        project(
                                ImmutableMap.of("exists", PlanMatchPattern.expression("false")),
                                values()));
    }

    @Test
    public void testExistsTrue()
    {
        tester().assertThat(new RemoveRedundantExists())
                .on(p -> p.apply(Assignments.of(p.symbol("exists"), new ExistsPredicate(TRUE_LITERAL)),
                        ImmutableList.of(),
                        p.values(1),
                        p.values(1)))
                .matches(
                        project(
                                ImmutableMap.of("exists", PlanMatchPattern.expression("true")),
                                values()));
    }

    @Test
    public void testDoesNotFire()
    {
        tester().assertThat(new RemoveRedundantExists())
                .on(p -> p.apply(Assignments.of(p.symbol("exists"), new ExistsPredicate(TRUE_LITERAL)),
                        ImmutableList.of(),
                        p.values(1),
                        p.tableScan(ImmutableList.of(), ImmutableMap.of())))
                .doesNotFire();
    }
}

@@ -704,69 +704,8 @@
 ap;%0A
-import io.prestosql.sql.planner.assertions.PlanMatchPattern;%0A
 impo
@@ -762,24 +762,24 @@
 seRuleTest;%0A
+
 import io.pr
@@ -899,16 +899,95 @@
 .Test;%0A%0A
+import static io.prestosql.sql.planner.assertions.PlanMatchPattern.expression;%0A
 import s
@@ -1712,33 +1712,16 @@
 xists%22, 
-PlanMatchPattern.
 expressi
@@ -2165,32 +2165,32 @@
        project(%0A
+
                 
@@ -2231,33 +2231,16 @@
 xists%22, 
-PlanMatchPattern.
 expressi

Add static import