Search in sources :

Example 11 with ARQInternalErrorException

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;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Example 12 with ARQInternalErrorException

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);
    }
}
Also used : Node(org.apache.jena.graph.Node) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) MessageDigest(java.security.MessageDigest) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 13 with ARQInternalErrorException

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();
}
Also used : Var(org.apache.jena.sparql.core.Var) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Example 14 with 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);
    }
}
Also used : CmdException(jena.cmd.CmdException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) RiotException(org.apache.jena.riot.RiotException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) TerminationException(jena.cmd.TerminationException) JenaException(org.apache.jena.shared.JenaException) RiotNotFoundException(org.apache.jena.riot.RiotNotFoundException) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) JenaException(org.apache.jena.shared.JenaException) TerminationException(jena.cmd.TerminationException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) TransactionalNull(org.apache.jena.sparql.core.TransactionalNull) Transactional(org.apache.jena.sparql.core.Transactional)

Example 15 with ARQInternalErrorException

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);
    }
}
Also used : TerminationException(jena.cmd.TerminationException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ResultSet(org.apache.jena.query.ResultSet) NotFoundException(org.apache.jena.shared.NotFoundException)

Aggregations

ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)34 Node (org.apache.jena.graph.Node)6 NodeValue (org.apache.jena.sparql.expr.NodeValue)6 ArrayList (java.util.ArrayList)5 Binding (org.apache.jena.sparql.engine.binding.Binding)5 Var (org.apache.jena.sparql.core.Var)4 BigDecimal (java.math.BigDecimal)3 BasicPattern (org.apache.jena.sparql.core.BasicPattern)3 ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)3 BigInteger (java.math.BigInteger)2 CmdException (jena.cmd.CmdException)2 TerminationException (jena.cmd.TerminationException)2 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)2 Graph (org.apache.jena.graph.Graph)2 RDFNode (org.apache.jena.rdf.model.RDFNode)2 JenaException (org.apache.jena.shared.JenaException)2 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)2