AggregationPipelineQueryNode extends ExternalSet { public boolean filter(final ValueExpr condition) { if (condition instanceof Compare) { final Compare compare = (Compare) condition; final Compare.CompareOp operator = compare.getOperator(); final Object leftArg = valueFieldExpr(compare.getLeftArg()); final Object rightArg = valueFieldExpr(compare.getRightArg()); if (leftArg == null || rightArg == null) { return false; } final String opFunc; switch (operator) { case EQ: opFunc = "$eq"; break; case NE: opFunc = "$ne"; break; case LT: opFunc = "$lt"; break; case LE: opFunc = "$le"; break; case GT: opFunc = "$gt"; break; case GE: opFunc = "$ge"; break; default: return false; } final Document compareDoc = new Document(opFunc, Arrays.asList(leftArg, rightArg)); pipeline.add(Aggregates.project(Projections.fields( Projections.computed("FILTER", compareDoc), Projections.include(VALUES, HASHES, TYPES, LEVEL, TIMESTAMP)))); pipeline.add(Aggregates.match(new Document("FILTER", true))); pipeline.add(Aggregates.project(Projections.fields( Projections.include(VALUES, HASHES, TYPES, LEVEL, TIMESTAMP)))); return true; } return false; } AggregationPipelineQueryNode(final MongoCollection<Document> collection, final StatementPattern baseSP);   AggregationPipelineQueryNode(final MongoCollection<Document> collection,
            final List<Bson> pipeline, final Set<String> assuredBindingNames,
            final Set<String> bindingNames, final BiMap<String, String> varToOriginalName); @Override boolean equals(final Object o); @Override int hashCode(); @Override CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings); @Override Set<String> getAssuredBindingNames(); @Override Set<String> getBindingNames(); @Override AggregationPipelineQueryNode clone(); @Override String getSignature(); boolean joinWith(final StatementPattern sp); boolean project(final Iterable<ProjectionElemList> projections); boolean extend(final Iterable<ExtensionElem> extensionElements); boolean filter(final ValueExpr condition); boolean distinct(); void requireSourceDerivationDepth(final int requiredLevel); void requireSourceTimestamp(final long t); List<Bson> getTriplePipeline(final long timestamp, final boolean requireNew);  }
@Test public void testFilter() { final AggregationPipelineQueryNode base = new AggregationPipelineQueryNode( collection, new LinkedList<>(), Sets.newHashSet("x", "y"), Sets.newHashSet("x", "y", "opt"), HashBiMap.create()); AggregationPipelineQueryNode node = base.clone(); boolean success = node.filter(new Compare(new Var("x"), new Var("y"), Compare.CompareOp.EQ)); Assert.assertTrue(success); Assert.assertEquals(Sets.newHashSet("x", "y", "opt"), node.getBindingNames()); Assert.assertEquals(Sets.newHashSet("x", "y"), node.getAssuredBindingNames()); Assert.assertEquals(3, node.getPipeline().size()); node = base.clone(); success = node.filter(new IsLiteral(new Var("opt"))); Assert.assertFalse(success); Assert.assertEquals(Sets.newHashSet("x", "y", "opt"), node.getBindingNames()); Assert.assertEquals(Sets.newHashSet("x", "y"), node.getAssuredBindingNames()); Assert.assertEquals(0, node.getPipeline().size()); }