Search in sources :

Example 1 with QueryCheckException

use of org.apache.jena.sparql.core.QueryCheckException in project jena by apache.

the class QueryUtils method checkParse.

public static void checkParse(Query query) {
    if (!SPARQLParserRegistry.get().containsFactory(query.getSyntax()))
        return;
    IndentedLineBuffer buff = new IndentedLineBuffer();
    query.serialize(buff, query.getSyntax());
    String tmp = buff.toString();
    Query query2 = null;
    try {
        String baseURI = null;
        if (!query.explicitlySetBaseURI())
            // Not in query - use the same one (e.g. file read from) .  
            baseURI = query.getBaseURI();
        query2 = QueryFactory.create(tmp, baseURI, query.getSyntax());
        if (query2 == null)
            return;
    } catch (UnsupportedOperationException ex) {
        // No parser after all.
        return;
    } catch (QueryException ex) {
        System.err.println(tmp);
        throw new QueryCheckException("could not parse output query", ex);
    }
    if (query.hashCode() != query2.hashCode())
        throw new QueryCheckException("reparsed query hashCode does not equal parsed input query \nQuery (hashCode: " + query.hashCode() + ")=\n" + query + "\n\nQuery2 (hashCode: " + query2.hashCode() + ")=\n" + query2);
    if (!query.equals(query2))
        throw new QueryCheckException("reparsed output does not equal parsed input");
}
Also used : QueryException(org.apache.jena.query.QueryException) Query(org.apache.jena.query.Query) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 2 with QueryCheckException

use of org.apache.jena.sparql.core.QueryCheckException in project jena by apache.

the class QueryUtils method checkOp.

public static void checkOp(Query query, boolean optimizeAlgebra) {
    IndentedLineBuffer buff = new IndentedLineBuffer();
    Op op = Algebra.compile(query);
    if (optimizeAlgebra)
        op = Algebra.optimize(op);
    WriterSSE.out(buff, op, query);
    String str = buff.toString();
    try {
        Op op2 = SSE.parseOp(str);
        if (op.hashCode() != op2.hashCode()) {
            op.hashCode();
            op2.hashCode();
            dump(op, op2);
            throw new QueryCheckException("reparsed algebra expression hashCode does not equal algebra from query");
        }
        if (!op.equals(op2)) {
            dump(op, op2);
            throw new QueryCheckException("reparsed algebra expression does not equal query algebra");
        }
    } catch (SSEParseException | BuildException ex) {
        System.err.println(str);
        throw ex;
    }
// Breakpoint
}
Also used : Op(org.apache.jena.sparql.algebra.Op) SSEParseException(org.apache.jena.sparql.sse.SSEParseException) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) BuildException(org.apache.jena.sparql.sse.builders.BuildException) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 3 with QueryCheckException

use of org.apache.jena.sparql.core.QueryCheckException in project jena by apache.

the class qparse method exec.

@Override
protected void exec() {
    try {
        Query query = modQuery.getQuery();
        try {
            LogCtl.disable(ParserBase.ParserLoggerName);
            QueryUtils.checkQuery(query, true);
        } catch (QueryCheckException ex) {
            System.err.println();
            System.err.println("**** Check failure: " + ex.getMessage());
            if (ex.getCause() != null)
                ex.getCause().printStackTrace(System.err);
        } finally {
            LogCtl.setLevel(ParserBase.ParserLoggerName, "INFO");
        }
        // Print the query out in some syntax
        if (printQuery) {
            divider();
            modOutput.output(query);
        }
        // Print internal forms.
        if (printOp) {
            divider();
            modOutput.outputOp(query, false);
        }
        if (printQuad) {
            divider();
            modOutput.outputQuad(query, false);
        }
        if (printOpt) {
            divider();
            modOutput.outputOp(query, true);
        }
        if (printQuadOpt) {
            divider();
            modOutput.outputQuad(query, true);
        }
        if (printPlan) {
            divider();
            // This forces internal query initialization - must be after QueryUtils.checkQuery
            QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.createGeneral());
            QueryOutputUtils.printPlan(query, qExec);
        }
    } catch (ARQInternalErrorException intEx) {
        System.err.println(intEx.getMessage());
        if (intEx.getCause() != null) {
            System.err.println("Cause:");
            intEx.getCause().printStackTrace(System.err);
            System.err.println();
        }
        intEx.printStackTrace(System.err);
    } catch (ResultSetException ex) {
        System.err.println(ex.getMessage());
        ex.printStackTrace(System.err);
    } catch (QueryException qEx) {
        //System.err.println(qEx.getMessage()) ;
        throw new CmdException("Query Exeception", qEx);
    } catch (JenaException ex) {
        ex.printStackTrace();
        throw ex;
    } catch (CmdException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new CmdException("Exception", ex);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) JenaException(org.apache.jena.shared.JenaException)

Aggregations

QueryCheckException (org.apache.jena.sparql.core.QueryCheckException)3 IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)2 CmdException (jena.cmd.CmdException)1 Query (org.apache.jena.query.Query)1 QueryException (org.apache.jena.query.QueryException)1 JenaException (org.apache.jena.shared.JenaException)1 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)1 Op (org.apache.jena.sparql.algebra.Op)1 ResultSetException (org.apache.jena.sparql.resultset.ResultSetException)1 SSEParseException (org.apache.jena.sparql.sse.SSEParseException)1 BuildException (org.apache.jena.sparql.sse.builders.BuildException)1