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");
}
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
}
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);
}
}
Aggregations