protected List<Var> getStatementPatternVars(TupleExpr tupleExpr) { List<StatementPattern> stPatterns = StatementPatternCollector.process(tupleExpr); List<Var> varList = new ArrayList<Var>(stPatterns.size() * 4); for (StatementPattern sp : stPatterns) { sp.getVars(varList); } return varList; }
protected List<Var> getStatementPatternVars(TupleExpr tupleExpr) { List<StatementPattern> stPatterns = StatementPatternCollector.process(tupleExpr); List<Var> varList = new ArrayList<Var>(stPatterns.size() * 4); for (StatementPattern sp : stPatterns) { sp.getVars(varList); } return varList; }
protected List<Var> getStatementPatternVars(TupleExpr tupleExpr) { List<StatementPattern> stPatterns = StatementPatternCollector.process(tupleExpr); List<Var> varList = new ArrayList<Var>(stPatterns.size() * 4); for (StatementPattern sp : stPatterns) { sp.getVars(varList); } return varList; }
protected List<Var> getStatementPatternVars(TupleExpr tupleExpr) { if(tupleExpr == null) return null; List<StatementPattern> stPatterns = StatementPatternCollector.process(tupleExpr); List<Var> varList = new ArrayList<Var>(stPatterns.size() * 4); for (StatementPattern sp : stPatterns) { sp.getVars(varList); } return varList; }
public CloseableIteration<BindingSet, QueryEvaluationException> queryDocIndex(final String sparqlQuery, final Collection<BindingSet> constraints) throws TableNotFoundException, QueryEvaluationException { final SPARQLParser parser = new SPARQLParser(); ParsedQuery pq1 = null; try { pq1 = parser.parseQuery(sparqlQuery, null); } catch (final MalformedQueryException e) { e.printStackTrace(); throw new QueryEvaluationException("Malformed query. query=" + sparqlQuery, e); } final TupleExpr te1 = pq1.getTupleExpr(); final List<StatementPattern> spList1 = StatementPatternCollector.process(te1); if(StarQuery.isValidStarQuery(spList1)) { final StarQuery sq1 = new StarQuery(spList1); return queryDocIndex(sq1, constraints); } else { throw new IllegalArgumentException("Invalid star query!"); } }
List<StatementPattern> statementPatterns = StatementPatternCollector.process(constructExpr);
List<StatementPattern> statementPatterns = StatementPatternCollector.process(constructExpr);
List<StatementPattern> statementPatterns = StatementPatternCollector.process(constructExpr);
List<StatementPattern> statementPatterns = StatementPatternCollector.process(constructExpr);
List<StatementPattern> statementPatterns = StatementPatternCollector.process(constructExpr);
@Test public void testConstructGraphSerializer() throws MalformedQueryException { String query = "select ?x where { ?x <uri:talksTo> <uri:Bob>. ?y <uri:worksAt> ?z }"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq = parser.parseQuery(query, null); List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); ConstructGraph graph = new ConstructGraph(patterns); String constructString = ConstructGraphSerializer.toConstructString(graph); ConstructGraph deserialized = ConstructGraphSerializer.toConstructGraph(constructString); assertEquals(graph, deserialized); }
@Test public void testConstructGraphSerializerBlankNode() throws MalformedQueryException { String query = "select ?x where { _:b <uri:talksTo> ?x. _:b <uri:worksAt> ?y }"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq = parser.parseQuery(query, null); List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); ConstructGraph graph = new ConstructGraph(patterns); String constructString = ConstructGraphSerializer.toConstructString(graph); ConstructGraph deserialized = ConstructGraphSerializer.toConstructGraph(constructString); assertEquals(graph, deserialized); }
@Test public void testConstructProjectionProjectSubj() throws MalformedQueryException, UnsupportedEncodingException { String query = "select ?x where { ?x <uri:talksTo> <uri:Bob> }"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq = parser.parseQuery(query, null); List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); ConstructProjection projection = new ConstructProjection(patterns.get(0)); QueryBindingSet bs = new QueryBindingSet(); bs.addBinding("x", VF.createIRI("uri:Joe")); VisibilityBindingSet vBs = new VisibilityBindingSet(bs, "FOUO"); RyaStatement statement = projection.projectBindingSet(vBs, new HashMap<>()); RyaStatement expected = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), new RyaIRI("uri:Bob")); expected.setColumnVisibility("FOUO".getBytes("UTF-8")); expected.setTimestamp(statement.getTimestamp()); assertEquals(expected, statement); }
List<StatementPattern> deletePatterns = StatementPatternCollector.process(deleteClause);
@Test public void testConstructProjectionBNodes() throws MalformedQueryException { String query = "select ?o where { _:b <uri:talksTo> ?o }"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq = parser.parseQuery(query, null); List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); ConstructProjection projection = new ConstructProjection(patterns.get(0)); QueryBindingSet bs = new QueryBindingSet(); bs.addBinding("o", VF.createIRI("uri:Bob")); VisibilityBindingSet vBs = new VisibilityBindingSet(bs); BNode bNode = VF.createBNode(); Map<String, BNode> bNodeMap = new HashMap<>(); bNodeMap.put(VarNameUtils.prependAnonymous("1"), bNode); RyaStatement statement = projection.projectBindingSet(vBs,bNodeMap); RyaStatement expected = new RyaStatement(RdfToRyaConversions.convertResource(bNode), new RyaIRI("uri:talksTo"), new RyaIRI("uri:Bob")); expected.setTimestamp(statement.getTimestamp()); expected.setColumnVisibility(new byte[0]); assertEquals(expected, statement); }
@Test public void testConstructProjectionProjPred() throws MalformedQueryException { String query = "select ?p where { <uri:Joe> ?p <uri:Bob> }"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq = parser.parseQuery(query, null); List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); ConstructProjection projection = new ConstructProjection(patterns.get(0)); QueryBindingSet bs = new QueryBindingSet(); bs.addBinding("p", VF.createIRI("uri:worksWith")); VisibilityBindingSet vBs = new VisibilityBindingSet(bs); RyaStatement statement = projection.projectBindingSet(vBs, new HashMap<>()); RyaStatement expected = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:worksWith"), new RyaIRI("uri:Bob")); expected.setTimestamp(statement.getTimestamp()); expected.setColumnVisibility(new byte[0]); assertEquals(expected, statement); }
@Test public void testConstructGraph() throws MalformedQueryException, UnsupportedEncodingException { String query = "select ?x where { ?x <uri:talksTo> <uri:Bob>. ?y <uri:worksAt> ?z }"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq = parser.parseQuery(query, null); List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); ConstructGraph graph = new ConstructGraph(patterns); QueryBindingSet bs = new QueryBindingSet(); bs.addBinding("x", VF.createIRI("uri:Joe")); bs.addBinding("y", VF.createIRI("uri:Bob")); bs.addBinding("z", VF.createIRI("uri:BurgerShack")); VisibilityBindingSet vBs = new VisibilityBindingSet(bs,"FOUO"); Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs); RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), new RyaIRI("uri:Bob")); RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Bob"), new RyaIRI("uri:worksAt"), new RyaIRI("uri:BurgerShack")); Set<RyaStatement> expected = Sets.newHashSet(Arrays.asList(statement1, statement2)); expected.forEach(x-> x.setColumnVisibility("FOUO".getBytes())); ConstructGraphTestUtils.ryaStatementSetsEqualIgnoresTimestamp(expected, statements); }
List<StatementPattern> insertPatterns = StatementPatternCollector.process(insertClause);
List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); ConstructGraph graph = new ConstructGraph(patterns);
@Test public void constructQueryMetadataTest() throws MalformedQueryException { final String query = "select ?x ?y where {?x <uri:p1> ?y. ?y <uri:p2> <uri:o1> }"; final SPARQLParser parser = new SPARQLParser(); final ParsedQuery pq = parser.parseQuery(query, null); final List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO(); // Create the object that will be serialized. final ConstructQueryMetadata.Builder builder = ConstructQueryMetadata.builder(); builder.setNodeId("nodeId"); builder.setChildNodeId("childNodeId"); builder.setParentNodeId("parentNodeId"); builder.setVarOrder(new VariableOrder("a;b;c")); builder.setConstructGraph(new ConstructGraph(patterns)); final ConstructQueryMetadata originalMetadata = builder.build(); try(FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) { // Write it to the Fluo table. try(Transaction tx = fluoClient.newTransaction()) { dao.write(tx, originalMetadata); tx.commit(); } // Read it from the Fluo table. ConstructQueryMetadata storedMetdata = null; try(Snapshot sx = fluoClient.newSnapshot()) { storedMetdata = dao.readConstructQueryMetadata(sx, "nodeId"); } // Ensure the deserialized object is the same as the serialized one. assertEquals(originalMetadata, storedMetdata); } }