private UnaryTupleOperator projection() { if (!mProjectionPatterns.isEmpty()) { return multiProjection(); } else { Extension aExt = null; ProjectionElemList aList = new ProjectionElemList(); for (String aVar : mProjectionVars) { aList.addElement(new ProjectionElem(aVar)); } Projection aProjection = new Projection(); aProjection.setProjectionElemList(aList); if (aExt != null) { aProjection.setArg(aExt); } return aProjection; } }
private UnaryTupleOperator projection() { if (!mProjectionPatterns.isEmpty()) { return multiProjection(); } else { Extension aExt = null; ProjectionElemList aList = new ProjectionElemList(); for (String aVar : mProjectionVars) { aList.addElement(new ProjectionElem(aVar)); } Projection aProjection = new Projection(); aProjection.setProjectionElemList(aList); if (aExt != null) { aProjection.setArg(aExt); } return aProjection; } }
private UnaryTupleOperator projection() { if (!mProjectionPatterns.isEmpty()) { return multiProjection(); } else { Extension aExt = null; ProjectionElemList aList = new ProjectionElemList(); for (String aVar : mProjectionVars) { aList.addElement(new ProjectionElem(aVar)); } Projection aProjection = new Projection(); aProjection.setProjectionElemList(aList); if (aExt != null) { aProjection.setArg(aExt); } return aProjection; } }
private Projection visitResultVariables(Resource resultVars, Map<String, ProjectionElem> previousProjElems) throws RDF4JException { ProjectionElemList projElemList = new ProjectionElemList(); Iteration<? extends Resource, QueryEvaluationException> iter = TripleSources.listResources( resultVars, store); while (iter.hasNext()) { Resource r = iter.next(); ProjectionElem projElem = visitResultVariable(r, previousProjElems); projElemList.addElement(projElem); } Projection proj = new Projection(); proj.setProjectionElemList(projElemList); tupleRoot = proj; return proj; }
private ProjectionElemList visitTemplate(Resource r) throws RDF4JException { ProjectionElemList projElems = new ProjectionElemList(); Value subj = TripleSources.singleValue(r, SP.SUBJECT_PROPERTY, store); projElems.addElement(createProjectionElem(subj, "subject", null)); Value pred = TripleSources.singleValue(r, SP.PREDICATE_PROPERTY, store); projElems.addElement(createProjectionElem(pred, "predicate", null)); Value obj = TripleSources.singleValue(r, SP.OBJECT_PROPERTY, store); projElems.addElement(createProjectionElem(obj, "object", null)); return projElems; }
@Override public TupleExpr visit(ASTDescribe node, Object data) throws VisitorException { TupleExpr tupleExpr = (TupleExpr)data; if (tupleExpr == null) { tupleExpr = new SingletonSet(); } Extension e = new Extension(); ProjectionElemList projectionElements = new ProjectionElemList(); for (int i = 0; i < node.jjtGetNumChildren(); i++) { ValueExpr resource = (ValueExpr)node.jjtGetChild(i).jjtAccept(this, null); if (resource instanceof Var) { projectionElements.addElement(new ProjectionElem(((Var)resource).getName())); } else { String alias = "_describe_" + UUID.randomUUID().toString().replaceAll("-", "_"); ExtensionElem elem = new ExtensionElem(resource, alias); e.addElement(elem); projectionElements.addElement(new ProjectionElem(alias)); } } if (!e.getElements().isEmpty()) { e.setArg(tupleExpr); tupleExpr = e; } Projection p = new Projection(tupleExpr, projectionElements); return new DescribeOperator(p); }
@Override public TupleExpr visit(ASTDescribe node, Object data) throws VisitorException { TupleExpr tupleExpr = (TupleExpr)data; if (tupleExpr == null) { tupleExpr = new SingletonSet(); } Extension e = new Extension(); ProjectionElemList projectionElements = new ProjectionElemList(); for (int i = 0; i < node.jjtGetNumChildren(); i++) { ValueExpr resource = (ValueExpr)node.jjtGetChild(i).jjtAccept(this, null); if (resource instanceof Var) { projectionElements.addElement(new ProjectionElem(((Var)resource).getName())); } else { String alias = "_describe_" + UUID.randomUUID().toString().replaceAll("-", "_"); ExtensionElem elem = new ExtensionElem(resource, alias); e.addElement(elem); projectionElements.addElement(new ProjectionElem(alias)); } } if (!e.getElements().isEmpty()) { e.setArg(tupleExpr); tupleExpr = e; } Projection p = new Projection(tupleExpr, projectionElements); return new DescribeOperator(p); }
@Override public TupleExpr visit(ASTDescribe node, Object data) throws VisitorException { TupleExpr tupleExpr = (TupleExpr)data; if (tupleExpr == null) { tupleExpr = new SingletonSet(); } Extension e = new Extension(); ProjectionElemList projectionElements = new ProjectionElemList(); for (int i = 0; i < node.jjtGetNumChildren(); i++) { ValueExpr resource = (ValueExpr)node.jjtGetChild(i).jjtAccept(this, null); if (resource instanceof Var) { projectionElements.addElement(new ProjectionElem(((Var)resource).getName())); } else { String alias = "_describe_" + UUID.randomUUID().toString().replaceAll("-", "_"); ExtensionElem elem = new ExtensionElem(resource, alias); e.addElement(elem); projectionElements.addElement(new ProjectionElem(alias)); } } if (!e.getElements().isEmpty()) { e.setArg(tupleExpr); tupleExpr = e; } Projection p = new Projection(tupleExpr, projectionElements); return new DescribeOperator(p); }
private Projection visitResultNodes(Resource resultNodes) throws RDF4JException { ProjectionElemList projElemList = new ProjectionElemList(); Iteration<? extends Resource, QueryEvaluationException> iter = TripleSources.listResources( resultNodes, store); while (iter.hasNext()) { Resource r = iter.next(); ProjectionElem projElem = visitResultNode(r); projElemList.addElement(projElem); } Projection proj = new Projection(); proj.setProjectionElemList(projElemList); tupleRoot = new DescribeOperator(proj); return proj; }
@Test public void testEmptyProjection() throws Exception { StatementPattern isClass = new StatementPattern(constant(UNDERGRAD), constant(RDF.TYPE), constant(OWL.CLASS)); QueryRoot queryTree = new QueryRoot(new Projection(isClass, new ProjectionElemList())); SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection); queryTree.visit(visitor); Assert.assertTrue(queryTree.getArg() instanceof Projection); Projection projectNode = (Projection) queryTree.getArg(); Assert.assertTrue(projectNode.getArg() instanceof AggregationPipelineQueryNode); AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) projectNode.getArg(); Assert.assertEquals(Sets.newHashSet(), pipelineNode.getAssuredBindingNames()); }
ProjectionElemList projElemList = new ProjectionElemList();
ProjectionElemList projElemList = new ProjectionElemList();
ProjectionElemList projElemList = new ProjectionElemList();
ProjectionElemList pelist = new ProjectionElemList(); for (String name : union.getAssuredBindingNames()) { ProjectionElem pe = new ProjectionElem(name);
ProjectionElemList pelist = new ProjectionElemList(); for (String name : union.getAssuredBindingNames()) { ProjectionElem pe = new ProjectionElem(name);
@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()); }
@Test public void testProjection() 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 projectionElements = new ProjectionElemList( new ProjectionElem("p", "relation"), new ProjectionElem("course")); QueryRoot queryTree = new QueryRoot(new Projection( new Join(new Join(isCourse, hasEdge), isUndergrad), projectionElements)); SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection); queryTree.visit(visitor); Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode); AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg(); Assert.assertEquals(Sets.newHashSet("relation", "course"), pipelineNode.getAssuredBindingNames()); }
ProjectionElemList aList = new ProjectionElemList();
ProjectionElemList aList = new ProjectionElemList();
ProjectionElemList aList = new ProjectionElemList();