Search in sources :

Example 26 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class OpExecutorTDB1 method reorder.

private static BasicPattern reorder(BasicPattern pattern, QueryIterPeek peek, ReorderTransformation transform) {
    if (transform != null) {
        if (!peek.hasNext())
            throw new ARQInternalErrorException("Peek iterator is already empty");
        BasicPattern pattern2 = Substitute.substitute(pattern, peek.peek());
        // Calculate the reordering based on the substituted pattern.
        ReorderProc proc = transform.reorderIndexes(pattern2);
        // Then reorder original patten
        pattern = proc.reorder(pattern);
    }
    return pattern;
}
Also used : ReorderProc(org.apache.jena.sparql.engine.optimizer.reorder.ReorderProc) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 27 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class ParserBase method stripSign.

protected Node stripSign(Node node) {
    if (!node.isLiteral())
        return node;
    String lex = node.getLiteralLexicalForm();
    String lang = node.getLiteralLanguage();
    RDFDatatype dt = node.getLiteralDatatype();
    if (!lex.startsWith("-") && !lex.startsWith("+"))
        throw new ARQInternalErrorException("Literal does not start with a sign: " + lex);
    lex = lex.substring(1);
    return NodeFactory.createLiteral(lex, lang, dt);
}
Also used : ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) RDFDatatype(org.apache.jena.datatypes.RDFDatatype)

Example 28 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class strjoin method exec.

@Override
public final NodeValue exec(List<NodeValue> args) {
    if (args == null)
        // The contract on the function interface is that this should not happen.
        throw new ARQInternalErrorException(Lib.className(this) + ": Null args list");
    Iterator<NodeValue> iter = args.iterator();
    String sep = iter.next().asString();
    List<String> x = new ArrayList<>();
    iter.forEachRemaining(arg -> x.add(arg.asString()));
    return NodeValue.makeString(String.join(sep, x));
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ArrayList(java.util.ArrayList)

Example 29 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class FN_Matches method exec.

@Override
public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) {
    if (myArgs != args)
        throw new ARQInternalErrorException("matches: Arguments have changed since checking");
    Expr expr = args.get(0);
    E_Regex regexEval = regex;
    if (regexEval == null) {
        Expr e1 = args.get(1);
        Expr e2 = null;
        if (args.size() == 3)
            e2 = args.get(2);
        String pattern = e1.eval(binding, env).getString();
        String flags = (e2 == null) ? null : e2.eval(binding, env).getString();
        regexEval = new E_Regex(expr, pattern, flags);
        // Cache if the pattern is fixed and the flags are fixed or non-existant
        if (e1 instanceof NodeValue && (e2 == null || e2 instanceof NodeValue))
            regex = regexEval;
    }
    NodeValue nv = regexEval.eval(binding, env);
    return nv;
}
Also used : ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Example 30 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class Math_pow method exec.

@Override
public NodeValue exec(NodeValue v1, NodeValue v2) {
    switch(XSDFuncOp.classifyNumeric("pow", v1, v2)) {
        case OP_INTEGER:
            BigInteger x = v1.getInteger();
            int y = v2.getInteger().intValue();
            if (y >= 0)
                return NodeValue.makeInteger(x.pow(y));
        // Anything else -> double
        case OP_DECIMAL:
        case OP_FLOAT:
        case OP_DOUBLE:
            double d1 = v1.getDouble();
            double d2 = v2.getDouble();
            if (d1 == 1 && d2 == Double.POSITIVE_INFINITY) {
                if (v1.isInteger())
                    return NodeValue.nvONE;
                else
                    return NodeValue.makeDouble(1);
            }
            return NodeValue.makeDouble(Math.pow(v1.getDouble(), v2.getDouble()));
        default:
            throw new ARQInternalErrorException("Unrecognized numeric operation : " + v1);
    }
}
Also used : ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) BigInteger(java.math.BigInteger)

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