Search in sources :

Example 36 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class ScopeBase method toString.

@Override
public String toString() {
    String str = "";
    String sep = "";
    for (Var v : frame.keySet()) {
        SqlColumn c = frame.get(v);
        str = str + sep + v + ":" + c;
        sep = " ";
    }
    if (parent != null)
        str = str + "=>" + parent.toString();
    return str;
}
Also used : Var(org.apache.jena.sparql.core.Var) SqlColumn(org.apache.jena.sdb.core.sqlexpr.SqlColumn)

Example 37 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class ScopeRename method findScopes.

@Override
public Set<ScopeEntry> findScopes() {
    Set<ScopeEntry> x = new HashSet<ScopeEntry>();
    for (Var v : frame.keySet()) {
        ScopeEntry e = findScopeForVar(v);
        x.add(e);
    }
    return x;
//        Set<ScopeEntry> x = scope.findScopes() ;
//        x = toSet(map(x, converter)) ;
//        return x ;
}
Also used : Var(org.apache.jena.sparql.core.Var) HashSet(java.util.HashSet)

Example 38 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class SlotCompiler method processSlot.

public final void processSlot(SDBRequest request, SqlTable table, SqlExprList conditions, Node node, String colName) {
    SqlColumn thisCol = new SqlColumn(table, colName);
    if (!node.isVariable()) {
        constantSlot(request, node, thisCol, conditions);
        return;
    }
    Var var = Var.alloc(node);
    if (table.getIdScope().hasColumnForVar(var)) {
        ScopeEntry e = table.getIdScope().findScopeForVar(var);
        SqlColumn otherCol = e.getColumn();
        SqlExpr c = new S_Equal(otherCol, thisCol);
        conditions.add(c);
        c.addNote("processVar: " + node);
        return;
    }
    table.setIdColumnForVar(var, thisCol);
}
Also used : ScopeEntry(org.apache.jena.sdb.core.ScopeEntry) Var(org.apache.jena.sparql.core.Var) SqlExpr(org.apache.jena.sdb.core.sqlexpr.SqlExpr) S_Equal(org.apache.jena.sdb.core.sqlexpr.S_Equal) SqlColumn(org.apache.jena.sdb.core.sqlexpr.SqlColumn)

Example 39 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class GenerateSQLVisitor method visit.

@Override
public void visit(SqlCoalesce sqlNode) {
    out.print("SELECT ");
    boolean first = true;
    SqlJoin join = sqlNode.getJoinNode();
    // Rough draft code.
    for (Var v : sqlNode.getCoalesceVars()) {
        if (!first)
            out.print(", ");
        SqlColumn col = sqlNode.getIdScope().findScopeForVar(v).getColumn();
        SqlColumn leftCol = join.getLeft().getIdScope().findScopeForVar(v).getColumn();
        SqlColumn rightCol = join.getRight().getIdScope().findScopeForVar(v).getColumn();
        out.print("COALESCE(");
        out.print(leftCol.getFullColumnName());
        out.print(", ");
        out.print(rightCol.getFullColumnName());
        out.print(")");
        out.print(aliasToken());
        out.print(col.getColumnName());
        first = false;
    }
    for (Var v : sqlNode.getNonCoalesceVars()) {
        if (!first)
            out.print(", ");
        first = false;
        // Need generated names.
        SqlColumn colSub = join.getIdScope().findScopeForVar(v).getColumn();
        SqlColumn col = sqlNode.getIdScope().findScopeForVar(v).getColumn();
        out.print(colSub.getFullColumnName());
        out.print(aliasToken());
        out.print(col.getColumnName());
    }
    out.ensureStartOfLine();
    // INC
    out.incIndent();
    out.println("FROM");
    join.visit(this);
    out.ensureStartOfLine();
// Alias and annotations handled by outputNode
}
Also used : Var(org.apache.jena.sparql.core.Var) SqlColumn(org.apache.jena.sdb.core.sqlexpr.SqlColumn)

Example 40 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class SqlRename method merge.

// Map all vars in the scope to names in the rename.
private void merge(Scope scope, ScopeBase newScope, Generator gen) {
    String x = "";
    String sep = "";
    for (ScopeEntry e : scope.findScopes()) {
        SqlColumn oldCol = e.getColumn();
        Var v = e.getVar();
        String colName = gen.next();
        SqlColumn newCol = new SqlColumn(vTable, colName);
        columns.add(new ColAlias(oldCol, newCol));
        newScope.setColumnForVar(v, newCol);
        // Annotations
        x = String.format("%s%s%s:(%s=>%s)", x, sep, v, oldCol, newCol);
        sep = " ";
    }
    if (x.length() > 0)
        addNote(x);
}
Also used : Var(org.apache.jena.sparql.core.Var) SqlColumn(org.apache.jena.sdb.core.sqlexpr.SqlColumn)

Aggregations

Var (org.apache.jena.sparql.core.Var)264 Node (org.apache.jena.graph.Node)83 ArrayList (java.util.ArrayList)53 Test (org.junit.Test)47 Binding (org.apache.jena.sparql.engine.binding.Binding)33 VarExprList (org.apache.jena.sparql.core.VarExprList)30 Op (org.apache.jena.sparql.algebra.Op)29 Expr (org.apache.jena.sparql.expr.Expr)28 Triple (org.apache.jena.graph.Triple)17 HashMap (java.util.HashMap)15 ContractTest (org.xenei.junit.contract.ContractTest)13 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)12 Query (org.apache.jena.query.Query)11 ExprList (org.apache.jena.sparql.expr.ExprList)11 SortCondition (org.apache.jena.query.SortCondition)10 ExprVar (org.apache.jena.sparql.expr.ExprVar)10 HashSet (java.util.HashSet)9 Pair (org.apache.jena.atlas.lib.Pair)9 SqlColumn (org.apache.jena.sdb.core.sqlexpr.SqlColumn)9 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)9