Search in sources :

Example 36 with Table

use of org.apache.jena.sparql.algebra.Table in project jena by apache.

the class NodeTransformOp method transform.

@Override
public Op transform(OpTable opTable) {
    if (opTable.isJoinIdentity())
        return opTable;
    Table table = opTable.getTable();
    if (table.isEmpty())
        return opTable;
    if (TableUnit.isTableUnit(table))
        return opTable;
    if (table.getVars().size() == 0)
        return opTable;
    Table table2 = NodeTransformLib.transform(table, transform);
    return OpTable.create(table2);
}
Also used : Table(org.apache.jena.sparql.algebra.Table)

Example 37 with Table

use of org.apache.jena.sparql.algebra.Table in project jena by apache.

the class labelSearch method exec.

/* This be called once, with unevaluated arguments.
     * To do a rewrite of part of a query, we must use the fundamental PropertyFunction
     * interface to be called once with the input iterator.
     * Must not return null nor throw an exception.  Instead, return a QueryIterNullIterator
     * indicating no matches.  
     */
@Override
public QueryIterator exec(QueryIterator input, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
    // No real need to check the pattern arguments because
    // the replacement triple pattern and regex will cope
    // but we illustrate testing here.
    Node nodeVar = argSubject.getArg();
    String pattern = NodeUtils.stringLiteral(argObject.getArg());
    if (pattern == null) {
        Log.warn(this, "Pattern must be a plain literal or xsd:string: " + argObject.getArg());
        return QueryIterNullIterator.create(execCxt);
    }
    if (false)
        // Old (ARQ 1) way - not recommended.
        return buildSyntax(input, nodeVar, pattern, execCxt);
    // Better 
    // Build a SPARQL algebra expression
    // Hidden variable
    Var var2 = createNewVar();
    BasicPattern bp = new BasicPattern();
    Triple t = new Triple(nodeVar, RDFS.label.asNode(), var2);
    bp.add(t);
    OpBGP op = new OpBGP(bp);
    Expr regex = new E_Regex(new ExprVar(var2.getName()), pattern, "i");
    Op filter = OpFilter.filter(regex, op);
    // ---- Evaluation
    if (true) {
        // Use the reference query engine
        // Create a table for the input stream (so it uses working memory at this point, 
        // which is why this is not the preferred way).  
        // Then join to expression for this stage.
        Table table = TableFactory.create(input);
        Op op2 = OpJoin.create(OpTable.create(table), filter);
        return Algebra.exec(op2, execCxt.getDataset());
    }
    // Use the default, optimizing query engine.
    return QC.execute(filter, input, execCxt);
}
Also used : Triple(org.apache.jena.graph.Triple) E_Regex(org.apache.jena.sparql.expr.E_Regex) ExprVar(org.apache.jena.sparql.expr.ExprVar) Op(org.apache.jena.sparql.algebra.Op) Table(org.apache.jena.sparql.algebra.Table) OpTable(org.apache.jena.sparql.algebra.op.OpTable) Expr(org.apache.jena.sparql.expr.Expr) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Aggregations

Table (org.apache.jena.sparql.algebra.Table)37 Var (org.apache.jena.sparql.core.Var)4 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)4 Binding (org.apache.jena.sparql.engine.binding.Binding)4 Node (org.apache.jena.graph.Node)3 Op (org.apache.jena.sparql.algebra.Op)3 Graph (org.apache.jena.graph.Graph)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 OpGraph (org.apache.jena.sparql.algebra.op.OpGraph)2 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)2 BasicPattern (org.apache.jena.sparql.core.BasicPattern)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)2 Test (org.junit.Test)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)1 Triple (org.apache.jena.graph.Triple)1 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)1 OpTable (org.apache.jena.sparql.algebra.op.OpTable)1 TableN (org.apache.jena.sparql.algebra.table.TableN)1 QueryIterConcat (org.apache.jena.sparql.engine.iterator.QueryIterConcat)1