use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.
the class XSDFuncOp method compareDateTimeFO.
/** Strict F&O handling of compare date(times).
* But that means applying the "local" timezone if there is no TZ.
* The data may have come from different timezones to the query.
*/
private static int compareDateTimeFO(NodeValue nv1, NodeValue nv2) {
XMLGregorianCalendar dt1 = nv1.getDateTime();
XMLGregorianCalendar dt2 = nv2.getDateTime();
int x = compareXSDDateTime(dt1, dt2);
if (x == XSDDateTime.INDETERMINATE) {
NodeValue nv3 = (nv1.isDate()) ? fixupDate(nv1) : fixupDateTime(nv1);
if (nv3 != null) {
XMLGregorianCalendar dt3 = nv3.getDateTime();
x = compareXSDDateTime(dt3, dt2);
if (x == XSDDateTime.INDETERMINATE)
throw new ARQInternalErrorException("Still get indeterminate comparison");
return x;
}
nv3 = (nv2.isDate()) ? fixupDate(nv2) : fixupDateTime(nv2);
if (nv3 != null) {
XMLGregorianCalendar dt3 = nv3.getDateTime();
x = compareXSDDateTime(dt1, dt3);
if (x == XSDDateTime.INDETERMINATE)
throw new ARQInternalErrorException("Still get indeterminate comparison");
return x;
}
throw new ARQInternalErrorException("Failed to fixup dateTimes");
}
return x;
}
use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.
the class ExprDigest method eval.
@Override
public NodeValue eval(NodeValue v) {
if (lastSeen != null && lastSeen.equals(v))
return lastCalc;
Node n = v.asNode();
if (!n.isLiteral())
throw new ExprEvalException("Not a literal: " + v);
if (n.getLiteralLanguage() != null && !n.getLiteralLanguage().equals(""))
throw new ExprEvalException("Can't make a digest of an RDF term with a language tag");
// Literal, no language tag.
if (n.getLiteralDatatype() != null && !XSDDatatype.XSDstring.equals(n.getLiteralDatatype()))
throw new ExprEvalException("Not a simple literal nor an XSD string");
try {
MessageDigest digest = getDigest();
String x = n.getLiteralLexicalForm();
byte[] b = x.getBytes(StandardCharsets.UTF_8);
byte[] d = digest.digest(b);
String y = Bytes.asHexLC(d);
NodeValue result = NodeValue.makeString(y);
// Cache
lastSeen = v;
lastCalc = result;
return result;
} catch (Exception ex2) {
throw new ARQInternalErrorException(ex2);
}
}
use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.
the class ExprLib method isAssignmentSafeEquality.
/**
* @param graphHasStringEquality True if the graph triple matching equates xsd:string and plain literal
* @param graphHasNumercialValueEquality True if the graph triple matching equates numeric values
*/
public static boolean isAssignmentSafeEquality(Expr expr, boolean graphHasStringEquality, boolean graphHasNumercialValueEquality) {
if (!(expr instanceof E_Equals) && !(expr instanceof E_SameTerm))
return false;
// Corner case: sameTerm is false for string/plain literal,
// but true in the graph.
ExprFunction2 eq = (ExprFunction2) expr;
Expr left = eq.getArg1();
Expr right = eq.getArg2();
Var var = null;
NodeValue constant = null;
if (left.isVariable() && right.isConstant()) {
var = left.asVar();
constant = right.getConstant();
} else if (right.isVariable() && left.isConstant()) {
var = right.asVar();
constant = left.getConstant();
}
// Not between a variable and a constant
if (var == null || constant == null)
return false;
if (!constant.isLiteral())
// URIs, bNodes. Any bNode will have come from a substitution - not legal syntax in filters
return true;
if (expr instanceof E_SameTerm) {
if (graphHasStringEquality && constant.isString())
// Graph is not same term
return false;
if (graphHasNumercialValueEquality && constant.isNumber())
return false;
return true;
}
// Final check for "=" where a FILTER = can do value matching when the graph does not.
if (expr instanceof E_Equals) {
if (!graphHasStringEquality && constant.isString())
return false;
if (!graphHasNumercialValueEquality && constant.isNumber())
return false;
return true;
}
// Unreachable.
throw new ARQInternalErrorException();
}
use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.
the class query method queryExec.
protected void queryExec(boolean timed, ResultsFormat fmt) {
try {
Query query = modQuery.getQuery();
if (isVerbose()) {
IndentedWriter out = new IndentedWriter(System.out, true);
query.serialize(out);
out.flush();
System.out.println();
}
if (isQuiet())
LogCtl.setError(SysRIOT.riotLoggerName);
Dataset dataset = getDataset(query);
// The default policy is to create an empty one - convenience for VALUES and BIND providing the data.
if (dataset == null && !query.hasDatasetDescription()) {
System.err.println("Dataset not specified in query nor provided on command line.");
throw new TerminationException(1);
}
Transactional transactional = (dataset != null && dataset.supportsTransactionAbort()) ? dataset : new TransactionalNull();
Txn.executeRead(transactional, () -> {
modTime.startTimer();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
try {
QueryExecUtils.executeQuery(query, qe, fmt);
} catch (QueryCancelledException ex) {
System.out.flush();
System.err.println("Query timed out");
}
long time = modTime.endTimer();
if (timed) {
totalTime += time;
System.err.println("Time: " + modTime.timeStr(time) + " sec");
}
} 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 (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 (JenaException | CmdException ex) {
throw ex;
} catch (Exception ex) {
throw new CmdException("Exception", ex);
}
}
use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.
the class ModResultsIn method getResultSet.
public ResultSet getResultSet() {
if (resultSet != null)
return resultSet;
if (resultsFilename == null) {
System.err.println("No result file name");
throw new TerminationException(1);
}
try {
if (resultsFilename.equals("-"))
return ResultSetFactory.load(System.in, inputFormat);
ResultSet rs = ResultSetFactory.load(resultsFilename, inputFormat);
if (rs == null) {
System.err.println("Failed to read the result set");
throw new TerminationException(9);
}
resultSet = rs;
return resultSet;
} catch (NotFoundException ex) {
System.err.println("File not found: " + resultsFilename);
throw new TerminationException(9);
} 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);
throw new TerminationException(99);
}
}
Aggregations