use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.
the class ReflexivePropertyVisitorTest method testReflexivePropertyDisabled.
@Test
public void testReflexivePropertyDisabled() throws Exception {
// Disable inference
final RdfCloudTripleStoreConfiguration disabledConf = conf.clone();
disabledConf.setInferReflexiveProperty(false);
// Define a reflexive property
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
when(inferenceEngine.isReflexiveProperty(HAS_FAMILY)).thenReturn(true);
// Construct a query, then make a copy and visit the copy
final Projection query = new Projection(new StatementPattern(new Var("s", ALICE), new Var("p", HAS_FAMILY), new Var("o")), new ProjectionElemList(new ProjectionElem("s", "subject")));
final Projection modifiedQuery = query.clone();
modifiedQuery.visit(new ReflexivePropertyVisitor(disabledConf, inferenceEngine));
// There should be no difference
Assert.assertEquals(query, modifiedQuery);
}
use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.
the class SomeValuesFromVisitorTest method testSomeValuesFromDisabled.
@Test
public void testSomeValuesFromDisabled() throws Exception {
// Disable someValuesOf inference
final AccumuloRdfConfiguration disabledConf = conf.clone();
disabledConf.setInferSomeValuesFrom(false);
// Configure a mock instance engine with an ontology:
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
Map<Resource, Set<URI>> personSVF = new HashMap<>();
personSVF.put(gradCourse, Sets.newHashSet(takesCourse));
personSVF.put(course, Sets.newHashSet(takesCourse));
personSVF.put(department, Sets.newHashSet(headOf));
personSVF.put(organization, Sets.newHashSet(worksFor, headOf));
when(inferenceEngine.getSomeValuesFromByRestrictionType(person)).thenReturn(personSVF);
// Query for a specific type visit -- should not change
StatementPattern originalSP = new StatementPattern(new Var("s"), new Var("p", RDF.TYPE), new Var("o", person));
final Projection originalQuery = new Projection(originalSP, new ProjectionElemList(new ProjectionElem("s", "subject")));
final Projection modifiedQuery = originalQuery.clone();
modifiedQuery.visit(new SomeValuesFromVisitor(disabledConf, inferenceEngine));
Assert.assertEquals(originalQuery, modifiedQuery);
}
use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.
the class RdfTestUtil method getProjection.
/**
* Get the first {@link Projection} node from a SPARQL query.
*
* @param sparql - The query that contains a single Projection node.
* @return The first {@link Projection} that is encountered.
* @throws Exception The query could not be parsed.
*/
@Nullable
public static Projection getProjection(final String sparql) throws Exception {
requireNonNull(sparql);
final AtomicReference<Projection> projection = new AtomicReference<>();
final ParsedQuery parsed = new SPARQLParser().parseQuery(sparql, null);
parsed.getTupleExpr().visit(new QueryModelVisitorBase<Exception>() {
@Override
public void meet(final Projection node) throws Exception {
projection.set(node);
}
});
return projection.get();
}
use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.
the class PrecompJoinOptimizerVarToConstTest method testThreeIndexGeoFreeCompareFilterMix.
@Test
public void testThreeIndexGeoFreeCompareFilterMix() throws Exception {
final SPARQLParser parser1 = new SPARQLParser();
final SPARQLParser parser2 = new SPARQLParser();
final SPARQLParser parser3 = new SPARQLParser();
final ParsedQuery pq1 = parser1.parseQuery(q25, null);
final ParsedQuery pq2 = parser2.parseQuery(q24, null);
final ParsedQuery pq3 = parser3.parseQuery(q26, null);
System.out.println("Query is " + pq1.getTupleExpr());
System.out.println("Indexes are " + pq2.getTupleExpr() + " and " + pq3.getTupleExpr());
final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup1);
list.add(extTup2);
final TupleExpr tup = pq1.getTupleExpr().clone();
final PCJOptimizer pcj = new PCJOptimizer(list, false, new AccumuloIndexSetProvider(new Configuration(), list));
pcj.optimize(tup, null, null);
System.out.println("Processed query is " + tup);
final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
final Set<StatementPattern> set = Sets.newHashSet();
Assert.assertEquals(2, eTupSet.size());
for (final QueryModelNode s : eTupSet) {
final Set<StatementPattern> tempSet = Sets.newHashSet(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
set.addAll(tempSet);
}
Assert.assertTrue(qSet.containsAll(set));
}
use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.
the class PrecompJoinOptimizerVarToConstTest method testGeoIndexFunction.
@Test
public void testGeoIndexFunction() throws Exception {
final SPARQLParser parser1 = new SPARQLParser();
final SPARQLParser parser2 = new SPARQLParser();
final ParsedQuery pq1 = parser1.parseQuery(q21, null);
final ParsedQuery pq2 = parser2.parseQuery(q23, null);
System.out.println("Query is " + pq1.getTupleExpr());
System.out.println("Index is " + pq2.getTupleExpr());
final SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup);
final TupleExpr tup = pq1.getTupleExpr().clone();
final PCJOptimizer pcj = new PCJOptimizer(list, false, new AccumuloIndexSetProvider(new Configuration(), list));
pcj.optimize(tup, null, null);
System.out.println("Processed query is " + tup);
final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
final Set<StatementPattern> set = Sets.newHashSet();
Assert.assertEquals(1, eTupSet.size());
for (final QueryModelNode s : eTupSet) {
final Set<StatementPattern> tempSet = Sets.newHashSet(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
set.addAll(tempSet);
}
Assert.assertTrue(qSet.containsAll(set));
}
Aggregations