use of org.openrdf.query.algebra.MultiProjection in project incubator-rya by apache.
the class SparqlFluoQueryBuilder method getConstructGraphVarOrder.
private static VariableOrder getConstructGraphVarOrder(final Reduced node) {
// get child node
final QueryModelNode child = node.getArg();
Preconditions.checkArgument(child instanceof Projection || child instanceof MultiProjection);
final UnaryTupleOperator unary = (UnaryTupleOperator) child;
// get ProjectionElemList to build ConstructGraph
final List<ProjectionElemList> projections = new ArrayList<>();
if (unary instanceof Projection) {
projections.add(((Projection) unary).getProjectionElemList());
} else {
projections.addAll(((MultiProjection) unary).getProjections());
}
return getConstructGraphVarOrder(projections);
}
use of org.openrdf.query.algebra.MultiProjection in project incubator-rya by apache.
the class ConstructConsequentVisitorTest method testMultiProjection.
@Test
public void testMultiProjection() {
Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new ValueConstant(RDF.TYPE), "rdftype"), new ExtensionElem(new ValueConstant(OWL.OBJECTPROPERTY), "owlprop"), new ExtensionElem(new ValueConstant(OWL.EQUIVALENTCLASS), "owleqcls"), new ExtensionElem(new ValueConstant(OWL.CLASS), "owlclass"));
MultiProjection projection = new MultiProjection(extension, Arrays.asList(new ProjectionElemList(new ProjectionElem("cls", "subject"), new ProjectionElem("rdftype", "predicate"), new ProjectionElem("owlclass", "object")), new ProjectionElemList(new ProjectionElem("prop", "subject"), new ProjectionElem("rdftype", "predicate"), new ProjectionElem("owlprop", "object")), new ProjectionElemList(new ProjectionElem("owleqcls", "predicate"), new ProjectionElem("cls", "object"))));
ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
projection.visit(visitor);
Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(RDF.TYPE), o(OWL.CLASS)), new StatementPattern(s(null), p(RDF.TYPE), o(OWL.OBJECTPROPERTY)), new StatementPattern(s(null), p(OWL.EQUIVALENTCLASS), o(null)));
Assert.assertEquals(expected, visitor.getConsequents());
}
use of org.openrdf.query.algebra.MultiProjection in project incubator-rya by apache.
the class SparqlToPipelineTransformVisitorTest method testMultiProjection.
@Test
public void testMultiProjection() throws Exception {
StatementPattern isUndergrad = new StatementPattern(new Var("x"), constant(RDF.TYPE), constant(UNDERGRAD));
StatementPattern isCourse = new StatementPattern(new Var("course"), constant(RDF.TYPE), constant(COURSE));
StatementPattern hasEdge = new StatementPattern(new Var("x"), new Var("p"), new Var("course"));
ProjectionElemList courseHasRelation = new ProjectionElemList(new ProjectionElem("p", "relation"), new ProjectionElem("course"));
ProjectionElemList studentHasRelation = new ProjectionElemList(new ProjectionElem("p", "relation"), new ProjectionElem("x", "student"));
QueryRoot queryTree = new QueryRoot(new MultiProjection(new Join(new Join(isCourse, hasEdge), isUndergrad), Arrays.asList(courseHasRelation, studentHasRelation)));
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
Assert.assertEquals(Sets.newHashSet("relation"), pipelineNode.getAssuredBindingNames());
Assert.assertEquals(Sets.newHashSet("relation", "course", "student"), pipelineNode.getBindingNames());
}
Aggregations