Java Code Examples for org.eclipse.rdf4j.query.MalformedQueryException#printStackTrace()

The following examples show how to use org.eclipse.rdf4j.query.MalformedQueryException#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: AccumuloDocIdIndexer.java    From rya with Apache License 2.0 6 votes vote down vote up
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!");
    }

}
 
Example 2
Source File: TupleExecutionPlanGeneratorTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testTwoNodeOrder() {

    SPARQLParser parser = new SPARQLParser();

    ParsedQuery pq1 = null;
    ParsedQuery pq2 = null;

    try {
        pq1 = parser.parseQuery(q7, null);
        pq2 = parser.parseQuery(q8, null);
    } catch (MalformedQueryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Set<TupleExpr> tupSet = Sets.newHashSet();
    tupSet.add(pq1.getTupleExpr());

    TupleExecutionPlanGenerator tep = new TupleExecutionPlanGenerator();
    Iterator<TupleExpr> processedTups = tep.getPlans(tupSet.iterator());

    List<TupleExpr> processedTupList = Lists.newArrayList();

    int size = 0;

    while(processedTups.hasNext()) {
        Assert.assertTrue(processedTups.hasNext());
        processedTupList.add(processedTups.next());
        size++;
    }

    Assert.assertEquals(2, size);

    Assert.assertEquals(pq1.getTupleExpr(), processedTupList.get(0));
    Assert.assertEquals(pq2.getTupleExpr(), processedTupList.get(1));

}
 
Example 3
Source File: TupleExecutionPlanGeneratorTest.java    From rya with Apache License 2.0 4 votes vote down vote up
@Test
public void testThreeNodeOrder() {

    SPARQLParser parser = new SPARQLParser();

    ParsedQuery pq1 = null;
    ParsedQuery pq2 = null;
    ParsedQuery pq3 = null;
    ParsedQuery pq4 = null;
    ParsedQuery pq5 = null;
    ParsedQuery pq6 = null;

    try {
        pq1 = parser.parseQuery(q1, null);
        pq2 = parser.parseQuery(q2, null);
        pq3 = parser.parseQuery(q3, null);
        pq4 = parser.parseQuery(q4, null);
        pq5 = parser.parseQuery(q5, null);
        pq6 = parser.parseQuery(q6, null);
    } catch (MalformedQueryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Set<TupleExpr> tupSet = Sets.newHashSet();
    tupSet.add(pq1.getTupleExpr());

    TupleExecutionPlanGenerator tep = new TupleExecutionPlanGenerator();
    Iterator<TupleExpr> processedTups= tep.getPlans(tupSet.iterator());

    List<TupleExpr> processedTupList = Lists.newArrayList();

    int size = 0;

    while(processedTups.hasNext()) {
        Assert.assertTrue(processedTups.hasNext());
        processedTupList.add(processedTups.next());
        size++;
    }

    Assert.assertTrue(!processedTups.hasNext());
    Assert.assertEquals(6, size);

    Assert.assertEquals(pq1.getTupleExpr(), processedTupList.get(1));
    Assert.assertEquals(pq2.getTupleExpr(), processedTupList.get(2));
    Assert.assertEquals(pq3.getTupleExpr(), processedTupList.get(4));
    Assert.assertEquals(pq4.getTupleExpr(), processedTupList.get(0));
    Assert.assertEquals(pq5.getTupleExpr(), processedTupList.get(3));
    Assert.assertEquals(pq6.getTupleExpr(), processedTupList.get(5));

}
 
Example 4
Source File: TupleExecutionPlanGeneratorTest.java    From rya with Apache License 2.0 4 votes vote down vote up
@Test
public void testThreeNodeOrderFilter() {

    SPARQLParser parser = new SPARQLParser();

    ParsedQuery pq1 = null;
    ParsedQuery pq2 = null;
    ParsedQuery pq3 = null;
    ParsedQuery pq4 = null;
    ParsedQuery pq5 = null;
    ParsedQuery pq6 = null;
    ParsedQuery pq7 = null;

    try {
        pq1 = parser.parseQuery(q9, null);
        pq2 = parser.parseQuery(q10, null);
        pq3 = parser.parseQuery(q11, null);
        pq4 = parser.parseQuery(q12, null);
        pq5 = parser.parseQuery(q13, null);
        pq6 = parser.parseQuery(q14, null);
        pq7 = parser.parseQuery(q15, null);
    } catch (MalformedQueryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    System.out.println(pq1.getTupleExpr());

    Set<TupleExpr> tupSet = Sets.newHashSet();
    tupSet.add(pq7.getTupleExpr());

    TupleExecutionPlanGenerator tep = new TupleExecutionPlanGenerator();
    Iterator<TupleExpr> processedTups= tep.getPlans(tupSet.iterator());

    List<TupleExpr> processedTupList = Lists.newArrayList();

    int size = 0;

    while(processedTups.hasNext()) {

        Assert.assertTrue(processedTups.hasNext());
        TupleExpr te = processedTups.next();
        processedTupList.add(te);
        System.out.println("Processed tups are " + te);
        size++;
    }

    Assert.assertTrue(!processedTups.hasNext());
    Assert.assertEquals(6, size);

    Assert.assertEquals(pq1.getTupleExpr(), processedTupList.get(1));
    Assert.assertEquals(pq2.getTupleExpr(), processedTupList.get(2));
    Assert.assertEquals(pq3.getTupleExpr(), processedTupList.get(4));
    Assert.assertEquals(pq4.getTupleExpr(), processedTupList.get(0));
    Assert.assertEquals(pq5.getTupleExpr(), processedTupList.get(3));
    Assert.assertEquals(pq6.getTupleExpr(), processedTupList.get(5));

}
 
Example 5
Source File: ValidIndexCombinationGeneratorTest.java    From rya with Apache License 2.0 4 votes vote down vote up
@Test
public void singleIndex() {
	String q1 = ""//
			+ "SELECT ?f ?m ?d " //
			+ "{" //
			+ "  ?f a ?m ."//
			+ "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."//
			+ "  ?d <uri:talksTo> ?f . "//
			+ "  ?f <uri:hangOutWith> ?m ." //
			+ "  ?m <uri:hangOutWith> ?d ." //
			+ "  ?f <uri:associatesWith> ?m ." //
			+ "  ?m <uri:associatesWith> ?d ." //
			+ "}";//

	SPARQLParser parser = new SPARQLParser();
	ParsedQuery pq1 = null;
	SimpleExternalTupleSet extTup1 = null;

	try {
		pq1 = parser.parseQuery(q1, null);
		extTup1 = new SimpleExternalTupleSet(
				(Projection) pq1.getTupleExpr());

	} catch (MalformedQueryException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	List<ExternalTupleSet> indexList = Lists.newArrayList();
	indexList.add(extTup1);
	ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(
			pq1.getTupleExpr());
	Iterator<List<ExternalTupleSet>> combos = vic
			.getValidIndexCombos(indexList);
	int size = 0;
	while (combos.hasNext()) {
		combos.hasNext();
		size++;
		combos.next();
		combos.hasNext();
	}
	Assert.assertTrue(!combos.hasNext());
	Assert.assertEquals(1, size);
}