Java Code Examples for org.openrdf.query.QueryEvaluationException#printStackTrace()
The following examples show how to use
org.openrdf.query.QueryEvaluationException#printStackTrace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 6 votes |
@Test public void testSES1991STRUUIDEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?uid WHERE {?s ?p ?o . BIND(STRUUID() as ?uid) } LIMIT 2"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); Literal uid1 = (Literal)result.next().getValue("uid"); Literal uid2 = (Literal)result.next().getValue("uid"); assertNotNull(uid1); assertFalse(uid1.equals(uid2)); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 2
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 6 votes |
@Test public void testSES1991NOWEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?d WHERE {?s ?p ?o . BIND(NOW() as ?d) } LIMIT 2"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); Literal d1 = (Literal)result.next().getValue("d"); Literal d2 = (Literal)result.next().getValue("d"); assertNotNull(d1); assertEquals(d1, d2); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 3
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 6 votes |
@Test public void testSES2024PropertyPathAnonVarSharing() throws Exception { loadTestData("/testdata-query/dataset-ses2024.trig"); String query = "PREFIX : <http://example.org/> SELECT * WHERE { ?x1 :p/:lit ?l1 . ?x1 :diff ?x2 . ?x2 :p/:lit ?l2 . }" ; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); BindingSet bs = result.next(); Literal l1 = (Literal)bs.getValue("l1"); Literal l2 = (Literal)bs.getValue("l2"); assertNotNull(l1); assertFalse(l1.equals(l2)); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 4
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testNullContext1() throws Exception { loadTestData("/testdata-query/dataset-query.trig"); StringBuilder query = new StringBuilder(); query.append(" SELECT * "); query.append(" FROM DEFAULT "); query.append(" WHERE { ?s ?p ?o } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); while (result.hasNext()) { BindingSet bs = result.next(); assertNotNull(bs); Resource s = (Resource)bs.getValue("s"); assertNotNull(s); assertFalse(bob.equals(s)); // should not be present in default // graph assertFalse(alice.equals(s)); // should not be present in default // graph } result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 5
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testSES1991UUIDEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?uid WHERE {?s ?p ?o . BIND(UUID() as ?uid) } LIMIT 2"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); URI uuid1 = (URI)result.next().getValue("uid"); URI uuid2 = (URI)result.next().getValue("uid"); assertNotNull(uuid1); assertNotNull(uuid2); assertFalse(uuid1.equals(uuid2)); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 6
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test /** * @see http://www.openrdf.org/issues/browse/SES-1091 * @throws Exception */ public void testArbitraryLengthPathWithFilter3() throws Exception { loadTestData("/testdata-query/alp-testdata.ttl"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("SELECT ?parent ?child "); query.append("WHERE { ?child rdfs:subClassOf+ ?parent . FILTER (?child = <http://example.org/C>) }"); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); int count = 0; while (result.hasNext()) { count++; BindingSet bs = result.next(); assertTrue(bs.hasBinding("child")); assertTrue(bs.hasBinding("parent")); } assertEquals(2, count); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 7
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test /** * @see http://www.openrdf.org/issues/browse/SES-1091 * @throws Exception */ public void testArbitraryLengthPathWithFilter1() throws Exception { loadTestData("/testdata-query/alp-testdata.ttl"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("SELECT ?parent ?child "); query.append("WHERE { ?child a owl:Class . ?child rdfs:subClassOf+ ?parent . FILTER (?parent = owl:Thing) }"); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); int count = 0; while (result.hasNext()) { count++; BindingSet bs = result.next(); assertTrue(bs.hasBinding("child")); assertTrue(bs.hasBinding("parent")); } assertEquals(4, count); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 8
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testPropertyPathInTree() throws Exception { loadTestData("/testdata-query/dataset-query.trig"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append(" SELECT ?node ?name "); query.append(" FROM ex:tree-graph "); query.append(" WHERE { ?node ex:hasParent+ ex:b . ?node ex:name ?name . }"); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); while (result.hasNext()) { BindingSet bs = result.next(); assertNotNull(bs); System.out.println(bs); } result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 9
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testSES1898LeftJoinSemantics2() throws Exception { loadTestData("/testdata-query/dataset-ses1898.trig"); StringBuilder query = new StringBuilder(); query.append(" PREFIX : <http://example.org/> "); query.append(" SELECT * WHERE { "); query.append(" ?s :p1 ?v1 . "); query.append(" ?s :p3 ?v2 . "); query.append(" OPTIONAL {?s :p2 ?v2 } ."); query.append(" } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); int count = 0; while (result.hasNext()) { result.next(); count++; } assertEquals(1, count); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 10
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testSES1898LeftJoinSemantics1() throws Exception { loadTestData("/testdata-query/dataset-ses1898.trig"); StringBuilder query = new StringBuilder(); query.append(" PREFIX : <http://example.org/> "); query.append(" SELECT * WHERE { "); query.append(" ?s :p1 ?v1 . "); query.append(" OPTIONAL {?s :p2 ?v2 } ."); query.append(" ?s :p3 ?v2 . "); query.append(" } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); int count = 0; while (result.hasNext()) { result.next(); count++; } assertEquals(0, count); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 11
Source File: CumulusRDFSailConnection.java From cumulusrdf with Apache License 2.0 | 5 votes |
@Override protected CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluateInternal(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings, boolean includeInferred) throws SailException { // Lock stLock = _sail.getStatementsReadLock(); // Clone the tuple expression to allow for more aggressive optimizations tupleExpr = tupleExpr.clone(); if (!(tupleExpr instanceof QueryRoot)) { // Add a dummy root node to the tuple expressions to allow the // optimizers to modify the actual root node tupleExpr = new QueryRoot(tupleExpr); } TripleSource tripleSource = new CumulusRDFTripleSource(); EvaluationStrategy strategy = new RangeEvaluationStrategy(tripleSource, dataset); new BindingAssigner().optimize(tupleExpr, dataset, bindings); new ConstantOptimizer(strategy).optimize(tupleExpr, dataset, bindings); new CompareOptimizer().optimize(tupleExpr, dataset, bindings); new ConjunctiveConstraintSplitter().optimize(tupleExpr, dataset, bindings); new DisjunctiveConstraintOptimizer().optimize(tupleExpr, dataset, bindings); new SameTermFilterOptimizer().optimize(tupleExpr, dataset, bindings); new QueryModelNormalizer().optimize(tupleExpr, dataset, bindings); new CumulusQueryOptimizer(_crdf.isRangeIndexesSupportEnabled()).optimize(tupleExpr, dataset, bindings); new QueryJoinOptimizer(_select_est).optimize(tupleExpr, dataset, bindings); // new FilterOptimizer().optimize(tupleExpr, dataset, bindings); new IterativeEvaluationOptimizer().optimize(tupleExpr, dataset, bindings); new OrderLimitOptimizer().optimize(tupleExpr, dataset, bindings); try { return strategy.evaluate(tupleExpr, EmptyBindingSet.getInstance()); } catch (QueryEvaluationException e) { e.printStackTrace(); throw new SailException(e); } }
Example 12
Source File: SparqlServiceIntegrationTest.java From sparql-playground with GNU General Public License v2.0 | 5 votes |
private long countResults(TupleQueryResult results) { try { long counter = 0; while (results.hasNext()) { results.next(); counter++; } return counter; } catch (QueryEvaluationException e) { e.printStackTrace(); return 0; } }
Example 13
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 4 votes |
@Test public void testSameTermRepeatInUnion() throws Exception { loadTestData("/testdata-query/dataset-query.trig"); StringBuilder query = new StringBuilder(); query.append("PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n"); query.append("SELECT * {\n"); query.append(" {\n"); query.append(" ?sameTerm foaf:mbox ?mbox\n"); query.append(" FILTER sameTerm(?sameTerm,$william)\n"); query.append(" } UNION {\n"); query.append(" ?x foaf:knows ?sameTerm\n"); query.append(" FILTER sameTerm(?sameTerm,$william)\n"); query.append(" }\n"); query.append("}"); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); tq.setBinding("william", conn.getValueFactory().createURI("http://example.org/william")); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); int count = 0; while (result.hasNext()) { BindingSet bs = result.next(); count++; assertNotNull(bs); System.out.println(bs); Value mbox = bs.getValue("mbox"); Value x = bs.getValue("x"); assertTrue(mbox instanceof Literal || x instanceof URI); } result.close(); assertEquals(3, count); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 14
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 4 votes |
@Test public void testSameTermRepeatInUnionAndOptional() throws Exception { loadTestData("/testdata-query/dataset-query.trig"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("SELECT * {\n"); query.append(" {\n"); query.append(" ex:a ?p ?prop1\n"); query.append(" FILTER (?p = ex:prop1)\n"); query.append(" } UNION {\n"); query.append(" ?s ex:p ex:A ; "); query.append(" { "); query.append(" { "); query.append(" ?s ?p ?l ."); query.append(" FILTER(?p = rdfs:label) "); query.append(" } "); query.append(" OPTIONAL { "); query.append(" ?s ?p ?opt1 . "); query.append(" FILTER (?p = ex:prop1) "); query.append(" } "); query.append(" OPTIONAL { "); query.append(" ?s ?p ?opt2 . "); query.append(" FILTER (?p = ex:prop2) "); query.append(" } "); query.append(" }"); query.append(" }\n"); query.append("}"); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); int count = 0; while (result.hasNext()) { BindingSet bs = result.next(); count++; assertNotNull(bs); System.out.println(bs); Value prop1 = bs.getValue("prop1"); Value l = bs.getValue("l"); assertTrue(prop1 instanceof Literal || l instanceof Literal); if (l instanceof Literal) { Value opt1 = bs.getValue("opt1"); assertNull(opt1); Value opt2 = bs.getValue("opt2"); assertNull(opt2); } } result.close(); assertEquals(2, count); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 15
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 4 votes |
@Test public void testSES1081SameTermWithValues() throws Exception { loadTestData("/testdata-query/dataset-ses1081.trig"); StringBuilder query = new StringBuilder(); query.append("PREFIX ex: <http://example.org/>\n"); query.append(" SELECT * \n"); query.append(" WHERE { \n "); query.append(" ?s ex:p ?a . \n"); query.append(" FILTER sameTerm(?a, ?e) \n "); query.append(" VALUES ?e { ex:b } \n "); query.append(" } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); int count = 0; while (result.hasNext()) { BindingSet bs = result.next(); count++; assertNotNull(bs); Value s = bs.getValue("s"); Value a = bs.getValue("a"); assertNotNull(s); assertNotNull(a); assertEquals(f.createURI("http://example.org/a"), s); assertEquals(f.createURI("http://example.org/b"), a); } result.close(); assertEquals(1, count); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 16
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 4 votes |
@Test public void testFilterRegexBoolean() throws Exception { loadTestData("/testdata-query/dataset-query.trig"); // test case for issue SES-1050 StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append(" SELECT *"); query.append(" WHERE { "); query.append(" ?x foaf:name ?name ; "); query.append(" foaf:mbox ?mbox . "); query.append(" FILTER(EXISTS { "); query.append(" FILTER(REGEX(?name, \"Bo\") && REGEX(?mbox, \"bob\")) "); // query.append(" FILTER(REGEX(?mbox, \"bob\")) "); query.append(" } )"); query.append(" } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); assertTrue(result.hasNext()); int count = 0; while (result.hasNext()) { BindingSet bs = result.next(); count++; System.out.println(bs); } assertEquals(1, count); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 17
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 4 votes |
@Test public void testGroupConcatNonDistinct() throws Exception { loadTestData("/testdata-query/dataset-query.trig"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("SELECT (GROUP_CONCAT(?l) AS ?concat)"); query.append("WHERE { ex:groupconcat-test ?p ?l . }"); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); while (result.hasNext()) { BindingSet bs = result.next(); assertNotNull(bs); Value concat = bs.getValue("concat"); assertTrue(concat instanceof Literal); String lexValue = ((Literal)concat).getLabel(); int occ = countCharOccurrences(lexValue, 'a'); assertEquals(1, occ); occ = countCharOccurrences(lexValue, 'b'); assertEquals(2, occ); occ = countCharOccurrences(lexValue, 'c'); assertEquals(2, occ); occ = countCharOccurrences(lexValue, 'd'); assertEquals(1, occ); } result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 18
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 4 votes |
@Test public void testSES1121VarNamesInOptionals() throws Exception { // Verifying that variable names have no influence on order of optionals // in query. See SES-1121. loadTestData("/testdata-query/dataset-ses1121.trig"); StringBuilder query1 = new StringBuilder(); query1.append(getNamespaceDeclarations()); query1.append(" SELECT DISTINCT *\n"); query1.append(" WHERE { GRAPH ?g { \n"); query1.append(" OPTIONAL { ?var35 ex:p ?b . } \n "); query1.append(" OPTIONAL { ?b ex:q ?c . } \n "); query1.append(" } \n"); query1.append(" } \n"); StringBuilder query2 = new StringBuilder(); query2.append(getNamespaceDeclarations()); query2.append(" SELECT DISTINCT *\n"); query2.append(" WHERE { GRAPH ?g { \n"); query2.append(" OPTIONAL { ?var35 ex:p ?b . } \n "); query2.append(" OPTIONAL { ?b ex:q ?var2 . } \n "); query2.append(" } \n"); query2.append(" } \n"); TupleQuery tq1 = conn.prepareTupleQuery(QueryLanguage.SPARQL, query1.toString()); TupleQuery tq2 = conn.prepareTupleQuery(QueryLanguage.SPARQL, query2.toString()); try { TupleQueryResult result1 = tq1.evaluate(); assertNotNull(result1); TupleQueryResult result2 = tq2.evaluate(); assertNotNull(result2); List<BindingSet> qr1 = QueryResults.asList(result1); List<BindingSet> qr2 = QueryResults.asList(result2); // System.out.println(qr1); // System.out.println(qr2); // if optionals are not kept in same order, query results will be // different size. assertEquals(qr1.size(), qr2.size()); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 19
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 4 votes |
@Test public void testSameTermRepeatInOptional() throws Exception { loadTestData("/testdata-query/dataset-query.trig"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append(" SELECT ?l ?opt1 ?opt2 "); query.append(" FROM ex:optional-sameterm-graph "); query.append(" WHERE { "); query.append(" ?s ex:p ex:A ; "); query.append(" { "); query.append(" { "); query.append(" ?s ?p ?l ."); query.append(" FILTER(?p = rdfs:label) "); query.append(" } "); query.append(" OPTIONAL { "); query.append(" ?s ?p ?opt1 . "); query.append(" FILTER (?p = ex:prop1) "); query.append(" } "); query.append(" OPTIONAL { "); query.append(" ?s ?p ?opt2 . "); query.append(" FILTER (?p = ex:prop2) "); query.append(" } "); query.append(" }"); query.append(" } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); int count = 0; while (result.hasNext()) { BindingSet bs = result.next(); count++; assertNotNull(bs); System.out.println(bs); Value l = bs.getValue("l"); assertTrue(l instanceof Literal); assertEquals("label", ((Literal)l).getLabel()); Value opt1 = bs.getValue("opt1"); assertNull(opt1); Value opt2 = bs.getValue("opt2"); assertNull(opt2); } result.close(); assertEquals(1, count); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 20
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 4 votes |
@Test public void testGroupConcatDistinct() throws Exception { loadTestData("/testdata-query/dataset-query.trig"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("SELECT (GROUP_CONCAT(DISTINCT ?l) AS ?concat)"); query.append("WHERE { ex:groupconcat-test ?p ?l . }"); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); while (result.hasNext()) { BindingSet bs = result.next(); assertNotNull(bs); Value concat = bs.getValue("concat"); assertTrue(concat instanceof Literal); String lexValue = ((Literal)concat).getLabel(); int occ = countCharOccurrences(lexValue, 'a'); assertEquals(1, occ); occ = countCharOccurrences(lexValue, 'b'); assertEquals(1, occ); occ = countCharOccurrences(lexValue, 'c'); assertEquals(1, occ); occ = countCharOccurrences(lexValue, 'd'); assertEquals(1, occ); } result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }