@Test public void testExtend() { final AggregationPipelineQueryNode base = new AggregationPipelineQueryNode( collection, new LinkedList<>(), Sets.newHashSet("x", "y"), Sets.newHashSet("x", "y", "opt"), HashBiMap.create()); List<ExtensionElem> extensionElements = Arrays.asList( new ExtensionElem(new Var("x"), "subject"), new ExtensionElem(new ValueConstant(RDF.TYPE), "predicate"), new ExtensionElem(new Var("y"), "object")); AggregationPipelineQueryNode node = base.clone(); boolean success = node.extend(extensionElements); Assert.assertTrue(success); Assert.assertEquals(1, node.getPipeline().size()); Assert.assertEquals(Sets.newHashSet("x", "y", "subject", "predicate", "object"), node.getAssuredBindingNames()); Assert.assertEquals(Sets.newHashSet("x", "y", "subject", "predicate", "object", "opt"), node.getBindingNames()); extensionElements = Arrays.asList( new ExtensionElem(new Var("x"), "subject"), new ExtensionElem(new Not(new ValueConstant(VF.createLiteral(true))), "notTrue")); node = base.clone(); success = node.extend(extensionElements); Assert.assertFalse(success); Assert.assertEquals(base, node); }
public boolean extend(final Iterable<ExtensionElem> extensionElements) { final List<Bson> valueFields = new LinkedList<>(); final List<Bson> hashFields = new LinkedList<>(); final List<Bson> typeFields = new LinkedList<>(); for (final String varName : bindingNames) { valueFields.add(Projections.include(varName)); hashFields.add(Projections.include(varName)); typeFields.add(Projections.include(varName)); } final Set<String> newVarNames = new HashSet<>(); for (final ExtensionElem elem : extensionElements) { String name = elem.getName(); if (!isValidFieldName(name)) { name = replace(name); } final ValueExpr expr = elem.getExpr(); final Object valueField; final Object hashField; final Object typeField; if (expr instanceof Var) { final String varName = ((Var) expr).getName(); valueField = "$" + varName; hashField = "$" + varName; typeField = "$" + varName; } else if (expr instanceof ValueConstant) { final Value val = ((ValueConstant) expr).getValue(); valueField = new Document("$literal", val.stringValue()); hashField = new Document("$literal", SimpleMongoDBStorageStrategy.hash(val.stringValue())); if (val instanceof Literal) { typeField = new Document("$literal", ((Literal) val).getDatatype().stringValue()); } else { typeField = null; } } else { return false; } valueFields.add(Projections.computed(name, valueField)); hashFields.add(Projections.computed(name, hashField)); if (typeField != null) { typeFields.add(Projections.computed(name, typeField)); } newVarNames.add(name); } assuredBindingNames.addAll(newVarNames); bindingNames.addAll(newVarNames); final Bson projectOpts = Projections.fields( Projections.computed(VALUES, Projections.fields(valueFields)), Projections.computed(HASHES, Projections.fields(hashFields)), Projections.computed(TYPES, Projections.fields(typeFields)), Projections.include(LEVEL), Projections.include(TIMESTAMP)); pipeline.add(Aggregates.project(projectOpts)); return true; }
AggregationPipelineQueryNode extends ExternalSet { public boolean extend(final Iterable<ExtensionElem> extensionElements) { final List<Bson> valueFields = new LinkedList<>(); final List<Bson> hashFields = new LinkedList<>(); final List<Bson> typeFields = new LinkedList<>(); for (final String varName : bindingNames) { valueFields.add(Projections.include(varName)); hashFields.add(Projections.include(varName)); typeFields.add(Projections.include(varName)); } final Set<String> newVarNames = new HashSet<>(); for (final ExtensionElem elem : extensionElements) { String name = elem.getName(); if (!isValidFieldName(name)) { name = replace(name); } final ValueExpr expr = elem.getExpr(); final Object valueField; final Object hashField; final Object typeField; if (expr instanceof Var) { final String varName = ((Var) expr).getName(); valueField = "$" + varName; hashField = "$" + varName; typeField = "$" + varName; } else if (expr instanceof ValueConstant) { final Value val = ((ValueConstant) expr).getValue(); valueField = new Document("$literal", val.stringValue()); hashField = new Document("$literal", SimpleMongoDBStorageStrategy.hash(val.stringValue())); if (val instanceof Literal) { typeField = new Document("$literal", ((Literal) val).getDatatype().stringValue()); } else { typeField = null; } } else { return false; } valueFields.add(Projections.computed(name, valueField)); hashFields.add(Projections.computed(name, hashField)); if (typeField != null) { typeFields.add(Projections.computed(name, typeField)); } newVarNames.add(name); } assuredBindingNames.addAll(newVarNames); bindingNames.addAll(newVarNames); final Bson projectOpts = Projections.fields( Projections.computed(VALUES, Projections.fields(valueFields)), Projections.computed(HASHES, Projections.fields(hashFields)), Projections.computed(TYPES, Projections.fields(typeFields)), Projections.include(LEVEL), Projections.include(TIMESTAMP)); pipeline.add(Aggregates.project(projectOpts)); return true; } }
AggregationPipelineQueryNode extends ExternalSet { public boolean extend(final Iterable<ExtensionElem> extensionElements) { final List<Bson> valueFields = new LinkedList<>(); final List<Bson> hashFields = new LinkedList<>(); final List<Bson> typeFields = new LinkedList<>(); for (final String varName : bindingNames) { valueFields.add(Projections.include(varName)); hashFields.add(Projections.include(varName)); typeFields.add(Projections.include(varName)); } final Set<String> newVarNames = new HashSet<>(); for (final ExtensionElem elem : extensionElements) { String name = elem.getName(); if (!isValidFieldName(name)) { name = replace(name); } final ValueExpr expr = elem.getExpr(); final Object valueField; final Object hashField; final Object typeField; if (expr instanceof Var) { final String varName = ((Var) expr).getName(); valueField = "$" + varName; hashField = "$" + varName; typeField = "$" + varName; } else if (expr instanceof ValueConstant) { final Value val = ((ValueConstant) expr).getValue(); valueField = new Document("$literal", val.stringValue()); hashField = new Document("$literal", SimpleMongoDBStorageStrategy.hash(val.stringValue())); if (val instanceof Literal) { typeField = new Document("$literal", ((Literal) val).getDatatype().stringValue()); } else { typeField = null; } } else { return false; } valueFields.add(Projections.computed(name, valueField)); hashFields.add(Projections.computed(name, hashField)); if (typeField != null) { typeFields.add(Projections.computed(name, typeField)); } newVarNames.add(name); } assuredBindingNames.addAll(newVarNames); bindingNames.addAll(newVarNames); final Bson projectOpts = Projections.fields( Projections.computed(VALUES, Projections.fields(valueFields)), Projections.computed(HASHES, Projections.fields(hashFields)), Projections.computed(TYPES, Projections.fields(typeFields)), Projections.include(LEVEL), Projections.include(TIMESTAMP)); pipeline.add(Aggregates.project(projectOpts)); return true; } 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); }
AggregationPipelineQueryNode extends ExternalSet { public boolean extend(final Iterable<ExtensionElem> extensionElements) { final List<Bson> valueFields = new LinkedList<>(); final List<Bson> hashFields = new LinkedList<>(); final List<Bson> typeFields = new LinkedList<>(); for (final String varName : bindingNames) { valueFields.add(Projections.include(varName)); hashFields.add(Projections.include(varName)); typeFields.add(Projections.include(varName)); } final Set<String> newVarNames = new HashSet<>(); for (final ExtensionElem elem : extensionElements) { String name = elem.getName(); if (!isValidFieldName(name)) { name = replace(name); } final ValueExpr expr = elem.getExpr(); final Object valueField; final Object hashField; final Object typeField; if (expr instanceof Var) { final String varName = ((Var) expr).getName(); valueField = "$" + varName; hashField = "$" + varName; typeField = "$" + varName; } else if (expr instanceof ValueConstant) { final Value val = ((ValueConstant) expr).getValue(); valueField = new Document("$literal", val.stringValue()); hashField = new Document("$literal", SimpleMongoDBStorageStrategy.hash(val.stringValue())); if (val instanceof Literal) { typeField = new Document("$literal", ((Literal) val).getDatatype().stringValue()); } else { typeField = null; } } else { return false; } valueFields.add(Projections.computed(name, valueField)); hashFields.add(Projections.computed(name, hashField)); if (typeField != null) { typeFields.add(Projections.computed(name, typeField)); } newVarNames.add(name); } assuredBindingNames.addAll(newVarNames); bindingNames.addAll(newVarNames); final Bson projectOpts = Projections.fields( Projections.computed(VALUES, Projections.fields(valueFields)), Projections.computed(HASHES, Projections.fields(hashFields)), Projections.computed(TYPES, Projections.fields(typeFields)), Projections.include(LEVEL), Projections.include(TIMESTAMP)); pipeline.add(Aggregates.project(projectOpts)); return true; } 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); }
AggregationPipelineQueryNode extends ExternalSet { public boolean extend(final Iterable<ExtensionElem> extensionElements) { final List<Bson> valueFields = new LinkedList<>(); final List<Bson> hashFields = new LinkedList<>(); final List<Bson> typeFields = new LinkedList<>(); for (final String varName : bindingNames) { valueFields.add(Projections.include(varName)); hashFields.add(Projections.include(varName)); typeFields.add(Projections.include(varName)); } final Set<String> newVarNames = new HashSet<>(); for (final ExtensionElem elem : extensionElements) { String name = elem.getName(); if (!isValidFieldName(name)) { name = replace(name); } final ValueExpr expr = elem.getExpr(); final Object valueField; final Object hashField; final Object typeField; if (expr instanceof Var) { final String varName = ((Var) expr).getName(); valueField = "$" + varName; hashField = "$" + varName; typeField = "$" + varName; } else if (expr instanceof ValueConstant) { final Value val = ((ValueConstant) expr).getValue(); valueField = new Document("$literal", val.stringValue()); hashField = new Document("$literal", SimpleMongoDBStorageStrategy.hash(val.stringValue())); if (val instanceof Literal) { typeField = new Document("$literal", ((Literal) val).getDatatype().stringValue()); } else { typeField = null; } } else { return false; } valueFields.add(Projections.computed(name, valueField)); hashFields.add(Projections.computed(name, hashField)); if (typeField != null) { typeFields.add(Projections.computed(name, typeField)); } newVarNames.add(name); } assuredBindingNames.addAll(newVarNames); bindingNames.addAll(newVarNames); final Bson projectOpts = Projections.fields( Projections.computed(VALUES, Projections.fields(valueFields)), Projections.computed(HASHES, Projections.fields(hashFields)), Projections.computed(TYPES, Projections.fields(typeFields)), Projections.include(LEVEL), Projections.include(TIMESTAMP)); pipeline.add(Aggregates.project(projectOpts)); return true; } 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);  }