/** * Check to see if the specified tail shares any variables with the * ancestry. */ protected boolean sharesVarsWithAncestry(final int tail) { final Set<IVariable<?>> tailVars = sa .getDefinitelyProducedBindings(nodes.get(tail), new LinkedHashSet<IVariable<?>>(), true/* recursive */); return !Collections.disjoint(ancestryVars, tailVars); }
/** * Check to see if the specified tail shares any variables with the * ancestry. */ protected boolean sharesVarsWithAncestry(final int tail) { final Set<IVariable<?>> tailVars = sa .getDefinitelyProducedBindings(nodes.get(tail), new LinkedHashSet<IVariable<?>>(), true/* recursive */); return !Collections.disjoint(ancestryVars, tailVars); }
/** * Report "MUST" bound bindings projected by the SERVICE. This involves * checking the graph pattern reported by * {@link ServiceNode#getGraphPattern()}. * <p> * Note: If the SERVICE URI is a variable, then it can only become bound * through some other operation. If the SERVICE variable never becomes * bound, then the SERVICE call can not run. */ // MUST : ServiceNode public Set<IVariable<?>> getDefinitelyProducedBindings( final ServiceNode node) { final Set<IVariable<?>> vars = new LinkedHashSet<IVariable<?>>(); final GraphPatternGroup<IGroupMemberNode> graphPattern = (GraphPatternGroup<IGroupMemberNode>) node .getGraphPattern(); if (graphPattern != null) { getDefinitelyProducedBindings(graphPattern, vars, true/* recursive */); } return vars; }
/** * Report "MUST" bound bindings projected by the SERVICE. This involves * checking the graph pattern reported by * {@link ServiceNode#getGraphPattern()}. * <p> * Note: If the SERVICE URI is a variable, then it can only become bound * through some other operation. If the SERVICE variable never becomes * bound, then the SERVICE call can not run. */ // MUST : ServiceNode public Set<IVariable<?>> getDefinitelyProducedBindings( final ServiceNode node) { final Set<IVariable<?>> vars = new LinkedHashSet<IVariable<?>>(); final GraphPatternGroup<IGroupMemberNode> graphPattern = (GraphPatternGroup<IGroupMemberNode>) node .getGraphPattern(); if (graphPattern != null) { getDefinitelyProducedBindings(graphPattern, vars, true/* recursive */); } return vars; }
/** * Get the named variables for a given tail. Is there a better way to do * this? * * @param tail * the tail * @return the named variables */ protected Set<String> getVars(int tail) { final IReorderableNode node = nodes.get(tail); // if (ASTStaticJoinOptimizer.log.isDebugEnabled()) { // ASTStaticJoinOptimizer.log.debug(node); // } final Set<IVariable<?>> vars = new LinkedHashSet<IVariable<?>>(); /* * Changed recursive to true so that we get the right produced * bindings out of UnionNodes so that they can be reordered * correctly. */ sa.getDefinitelyProducedBindings(node, vars, true); final Set<String> varNames = new LinkedHashSet<String>(); for (IVariable<?> v : vars) varNames.add(v.getName()); return varNames; }
/** * Get the named variables for a given tail. Is there a better way to do * this? * * @param tail * the tail * @return the named variables */ protected Set<String> getVars(int tail) { final IReorderableNode node = nodes.get(tail); // if (ASTStaticJoinOptimizer.log.isDebugEnabled()) { // ASTStaticJoinOptimizer.log.debug(node); // } final Set<IVariable<?>> vars = new LinkedHashSet<IVariable<?>>(); /* * Changed recursive to true so that we get the right produced * bindings out of UnionNodes so that they can be reordered * correctly. */ sa.getDefinitelyProducedBindings(node, vars, true); final Set<String> varNames = new LinkedHashSet<String>(); for (IVariable<?> v : vars) varNames.add(v.getName()); return varNames; }
final Set<IVariable<?>> vars) { getDefinitelyProducedBindings((IBindingProducerNode) group, vars, false/* recursive */);
final Set<IVariable<?>> boundByService = getDefinitelyProducedBindings(serviceNode);
final Set<IVariable<?>> vars) { getDefinitelyProducedBindings((IBindingProducerNode) group, vars, false/* recursive */);
final Set<IVariable<?>> boundByService = getDefinitelyProducedBindings(serviceNode);
getDefinitelyProducedBindings(child, childSet, recursive);
getDefinitelyProducedBindings(child, childSet, recursive);
expectedProjected.add(Var.var("y")); assertEquals(expectedProjected, sa.getDefinitelyProducedBindings(queryRoot)); sa.getDefinitelyProducedBindings(queryRoot.getWhereClause(), new LinkedHashSet<IVariable<?>>(), true/* recursive */));
/** * Unit test of static analysis for variables which must be bound by a * query. This involves checking the WHERE clause and the projection for the * query. * * @throws MalformedQueryException */ public void test_static_analysis01() throws MalformedQueryException { final String queryStr = "" + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"+ "select ?x where { ?x rdf:type foaf:Person }"; final QueryRoot queryRoot = new Bigdata2ASTSPARQLParser() .parseQuery2(queryStr, baseURI).getOriginalAST(); final StaticAnalysis sa = new StaticAnalysis(queryRoot); final Set<IVariable<?>> expected = new LinkedHashSet<IVariable<?>>(); expected.add(Var.var("x")); assertEquals(expected, sa.getDefinitelyProducedBindings(queryRoot)); assertEquals( expected, sa.getDefinitelyProducedBindings(queryRoot.getWhereClause(), new LinkedHashSet<IVariable<?>>(), true/* recursive */)); }
/** * Unit test of static analysis for variables which must be bound by a * query. This involves checking the WHERE clause and the projection for the * query. * * @throws MalformedQueryException */ public void test_static_analysis01() throws MalformedQueryException { final String queryStr = "" + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"+ "select ?x where { ?x rdf:type foaf:Person }"; final QueryRoot queryRoot = new Bigdata2ASTSPARQLParser() .parseQuery2(queryStr, baseURI).getOriginalAST(); final StaticAnalysis sa = new StaticAnalysis(queryRoot); final Set<IVariable<?>> expected = new LinkedHashSet<IVariable<?>>(); expected.add(Var.var("x")); assertEquals(expected, sa.getDefinitelyProducedBindings(queryRoot)); assertEquals( expected, sa.getDefinitelyProducedBindings(queryRoot.getWhereClause(), new LinkedHashSet<IVariable<?>>(), true/* recursive */)); }
expectedProjected.add(Var.var("y")); assertEquals(expectedProjected, sa.getDefinitelyProducedBindings(queryRoot)); sa.getDefinitelyProducedBindings(queryRoot.getWhereClause(), new LinkedHashSet<IVariable<?>>(), true/* recursive */));
getDefinitelyProducedBindings(node, vars, false/* recursive */);
/** * Unit test of static analysis for variables which must be bound by a * query. This involves checking the WHERE clause and the projection for the * query. * * @throws MalformedQueryException */ public void test_static_analysis01() throws MalformedQueryException { final String queryStr = "" + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"+ "select ?x where { ?x rdf:type foaf:Person }"; final QueryRoot queryRoot = new Bigdata2ASTSPARQLParser() .parseQuery2(queryStr, baseURI).getOriginalAST(); final StaticAnalysis sa = new StaticAnalysis(queryRoot); final Set<IVariable<?>> expected = new LinkedHashSet<IVariable<?>>(); expected.add(Var.var("x")); assertEquals(expected, sa.getDefinitelyProducedBindings(queryRoot)); assertEquals( expected, sa.getDefinitelyProducedBindings(queryRoot.getWhereClause(), new LinkedHashSet<IVariable<?>>(), true/* recursive */)); }
expectedProjected.add(Var.var("y")); assertEquals(expectedProjected, sa.getDefinitelyProducedBindings(queryRoot)); sa.getDefinitelyProducedBindings(queryRoot.getWhereClause(), new LinkedHashSet<IVariable<?>>(), true/* recursive */));
assertEquals(expected, sa.getDefinitelyProducedBindings(queryRoot)); assertEquals(expected, sa.getDefinitelyProducedBindings(whereClause, new LinkedHashSet<IVariable<?>>(), true/* recursive */));