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 visitTemplates(Resource templates) throws RDF4JException { List<ProjectionElemList> projElemLists = new ArrayList<ProjectionElemList>(); Iteration<? extends Resource, QueryEvaluationException> iter = TripleSources.listResources(templates, store); while (iter.hasNext()) { Resource r = iter.next(); ProjectionElemList projElems = visitTemplate(r); projElemLists.add(projElems); } UnaryTupleOperator expr; if (projElemLists.size() > 1) { MultiProjection proj = new MultiProjection(); proj.setProjections(projElemLists); expr = proj; } else { Projection proj = new Projection(); proj.setProjectionElemList(projElemLists.get(0)); expr = proj; } Reduced reduced = new Reduced(); reduced.setArg(expr); tupleRoot = reduced; return expr; }
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; }
@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; }
result = new Projection(result, projElemList); result = new Projection(result, projections.get(0));
result = new Projection(result, projList.get(0));
result = new Distinct(new Projection(union, pelist, false));
result = new Projection(result, projList.get(0));
result = new Distinct(new Projection(union, pelist, false));
result = new Distinct(new Projection(union, pelist, false));
result = new Projection(result, projElemList);
result = new Projection(result, projElemList);
result = new Projection(result, projElemList);
@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()); }
@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()); }