### Question:
HiveExpressions { static Expression simplifyPartitionFilter(Expression expr, Set<String> partitionColumnNames) { try { Expression partitionPredicatesOnly = ExpressionVisitors.visit(expr, new RemoveNonPartitionPredicates(partitionColumnNames)); return ExpressionVisitors.visit(partitionPredicatesOnly, new RewriteUnsupportedOperators()); } catch (Exception e) { throw new RuntimeException("Error while processing expression: " + expr, e); } } private  HiveExpressions();   }### Answer:
@Test public void testSimplifyRemoveNonPartitionColumns() { Expression input = and(and(equal("pCol", 1), equal("nonpCol", 2)), isNull("nonpCol")); Expression expected = equal("pCol", 1); Assert.assertEquals(expected.toString(), simplifyPartitionFilter(input, ImmutableSet.of("pcol")).toString()); }
@Test public void testSimplifyRemoveNot() { Expression input = not(and(equal("pCol", 1), equal("pCol", 2))); Expression expected = or(notEqual("pCol", 1), notEqual("pCol", 2)); Assert.assertEquals(expected.toString(), simplifyPartitionFilter(input, ImmutableSet.of("pcol")).toString()); }
@Test public void testSimplifyRemoveIsNull() { Expression input = isNull("pcol"); Expression expected = alwaysFalse(); Assert.assertEquals(expected.toString(), simplifyPartitionFilter(input, ImmutableSet.of("pcol")).toString()); }
@Test public void testSimplifyRemoveNotNull() { Expression input = notNull("pcol"); Expression expected = alwaysTrue(); Assert.assertEquals(expected.toString(), simplifyPartitionFilter(input, ImmutableSet.of("pcol")).toString()); }
@Test public void testSimplifyExpandIn() { Expression input = in("pcol", 1, 2, 3); Expression expected = or(or(equal("pcol", 1), equal("pcol", 2)), equal("pcol", 3)); Assert.assertEquals(expected.toString(), simplifyPartitionFilter(input, ImmutableSet.of("pcol")).toString()); }
@Test public void testSimplifyExpandNotIn() { Expression input = notIn("pcol", 1, 2, 3); Expression expected = and(and(notEqual("pcol", 1), notEqual("pcol", 2)), notEqual("pcol", 3)); Assert.assertEquals(expected.toString(), simplifyPartitionFilter(input, ImmutableSet.of("pcol")).toString()); }
@Test public void testSimplifyRemoveAlwaysTrueChildren() { Expression input = and(alwaysTrue(), equal("pcol", 1)); Expression expected = equal("pcol", 1); Assert.assertEquals(expected.toString(), simplifyPartitionFilter(input, ImmutableSet.of("pcol")).toString()); input = or(alwaysTrue(), equal("pcol", 1)); expected = alwaysTrue(); Assert.assertEquals(expected.toString(), simplifyPartitionFilter(input, ImmutableSet.of("pcol")).toString()); }
@Test public void testSimplifyRemoveAlwaysFalseChildren() { Expression input = and(alwaysFalse(), equal("pcol", 1)); Expression expected = alwaysFalse(); Assert.assertEquals(expected.toString(), simplifyPartitionFilter(input, ImmutableSet.of("pcol")).toString()); input = or(alwaysFalse(), equal("pcol", 1)); expected = equal("pcol", 1); Assert.assertEquals(expected.toString(), simplifyPartitionFilter(input, ImmutableSet.of("pcol")).toString()); }