Search in sources :

Example 41 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class NodeTransformExpr method transform.

/**
 * Transform node then create a {@link ExprVar} or {@link NodeValue}.
 */
private Expr transform(Node input) {
    Node n = transform.apply(input);
    if (n == null)
        throw new InternalErrorException("NodeTransform creates a null");
    if (!Var.isVar(n))
        return NodeValue.makeNode(n);
    String name = Var.alloc(n).getVarName();
    return new ExprVar(n.getName());
}
Also used : Node(org.apache.jena.graph.Node) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 42 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class RefEval method evalGraph.

static Table evalGraph(OpGraph opGraph, Evaluator evaluator) {
    ExecutionContext execCxt = evaluator.getExecContext();
    if (!Var.isVar(opGraph.getNode())) {
        DatasetGraph dsg = execCxt.getDataset();
        Node graphNode = opGraph.getNode();
        if (!dsg.containsGraph(graphNode))
            return new TableEmpty();
        Graph graph = execCxt.getDataset().getGraph(opGraph.getNode());
        if (// But contains was true?!!
        graph == null)
            throw new InternalErrorException("Graph was present, now it's not");
        ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
        Evaluator e2 = EvaluatorFactory.create(execCxt2);
        return eval(e2, opGraph.getSubOp());
    }
    // Graph node is a variable.
    Var gVar = Var.alloc(opGraph.getNode());
    Table current = null;
    for (Iterator<Node> iter = execCxt.getDataset().listGraphNodes(); iter.hasNext(); ) {
        Node gn = iter.next();
        Graph graph = execCxt.getDataset().getGraph(gn);
        ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
        Evaluator e2 = EvaluatorFactory.create(execCxt2);
        Table tableVarURI = TableFactory.create(gVar, gn);
        // Evaluate the pattern, join with this graph node possibility.
        // XXX If Var.ANON then no-opt.
        Table patternTable = eval(e2, opGraph.getSubOp());
        Table stepResult = evaluator.join(patternTable, tableVarURI);
        if (current == null)
            current = stepResult;
        else
            current = evaluator.union(current, stepResult);
    }
    if (current == null)
        // Nothing to loop over
        return new TableEmpty();
    return current;
}
Also used : ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) OpGraph(org.apache.jena.sparql.algebra.op.OpGraph) Graph(org.apache.jena.graph.Graph) Table(org.apache.jena.sparql.algebra.Table) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) TableEmpty(org.apache.jena.sparql.algebra.table.TableEmpty) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 43 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class JsonLDReader method createNode.

private Node createNode(Map<String, Object> map) {
    String type = (String) map.get("type");
    String lex = (String) map.get("value");
    if (type.equals(IRI))
        return createURI(lex);
    else if (type.equals(BLANK_NODE))
        return createBlankNode(lex);
    else if (type.equals(LITERAL)) {
        String lang = (String) map.get("language");
        String datatype = (String) map.get("datatype");
        if (Objects.equals(xsdString, datatype))
            // In RDF 1.1, simple literals and xsd:string are the same.
            // During migration, we prefer simple literals to xsd:strings.
            datatype = null;
        if (lang == null && datatype == null)
            return profile.createStringLiteral(lex, -1, -1);
        if (lang != null)
            return profile.createLangLiteral(lex, lang, -1, -1);
        RDFDatatype dt = NodeFactory.getType(datatype);
        return profile.createTypedLiteral(lex, dt, -1, -1);
    } else
        throw new InternalErrorException("Node is not a IRI, bNode or a literal: " + type);
}
Also used : InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) RDFDatatype(org.apache.jena.datatypes.RDFDatatype)

Example 44 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class BPTreeRangeIteratorMapper method loadStack.

private BPTreeRecords loadStack(BPTreeNode node) {
    AccessPath path = new AccessPath(null);
    node.bpTree.startReadBlkMgr();
    if (minRecord == null)
        node.internalMinRecord(path);
    else
        node.internalSearch(path, minRecord);
    List<AccessStep> steps = path.getPath();
    for (AccessStep step : steps) {
        BPTreeNode n = step.node;
        Iterator<BPTreePage> it = n.iterator(minRecord, maxRecord);
        if (it == null || !it.hasNext())
            continue;
        BPTreePage p = it.next();
        stack.push(it);
    }
    BPTreePage p = steps.get(steps.size() - 1).page;
    if (!(p instanceof BPTreeRecords))
        throw new InternalErrorException("Last path step not to a records block");
    node.bpTree.finishReadBlkMgr();
    return (BPTreeRecords) p;
}
Also used : InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) AccessStep(org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep)

Example 45 with InternalErrorException

use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.

the class BPTreeRangeIteratorMapper method next.

@Override
public X next() {
    if (!hasNext())
        throw new NoSuchElementException();
    X r = slot;
    if (r == null)
        throw new InternalErrorException("Null slot after hasNext is true");
    slot = null;
    return r;
}
Also used : InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Aggregations

InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)48 Node (org.apache.jena.graph.Node)14 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 AccessStep (org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep)3 Graph (org.apache.jena.graph.Graph)3 Triple (org.apache.jena.graph.Triple)3 Var (org.apache.jena.sparql.core.Var)3 StringReader (java.io.StringReader)2 DataAccessPoint (org.apache.jena.fuseki.server.DataAccessPoint)2 Dataset (org.apache.jena.query.Dataset)2 Model (org.apache.jena.rdf.model.Model)2 Lang (org.apache.jena.riot.Lang)2 RiotException (org.apache.jena.riot.RiotException)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 Table (org.apache.jena.sparql.algebra.Table)2 OpGraph (org.apache.jena.sparql.algebra.op.OpGraph)2 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)2 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2