Search in sources :

Example 1 with SqlColumn

use of org.apache.jena.sdb.core.sqlexpr.SqlColumn in project jena by apache.

the class TransformSDB method transform.

// Now done in QueryCompilerMain at a later stage.
//    @Override
//    public Op transform(OpSlice opSlice, Op subOp)
//    {
//        if ( ! request.LimitOffsetTranslation )
//            return super.transform(opSlice, subOp) ;
//
//        // Not a slice of SQL
//        if ( ! SDB_QC.isOpSQL(subOp) )
//            return super.transform(opSlice, subOp) ;
//        
//        // Two cases are currently handled:
//        // (slice (project (sql expression)))
//        // (slice (sql expression))
//
//        if ( isProject(opSlice.getSubOp()) )
//            // This should not happen because the pre-transform done in QueryEngineMain
//            // rewrites the case into the equivalent (project (slice ...))
//            return transformSliceProject(opSlice, (OpSQL)subOp, ((OpSQL)subOp).getSqlNode()) ;
//
//        // (slice (sql expression))
//        return transformSlice(opSlice, ((OpSQL)subOp).getSqlNode()) ;
//    }
//        
//    private Op transformSlice(OpSlice opSlice, SqlNode sqlSubOp)
//    {
//        SqlNode n = SqlSelectBlock.slice(request, sqlSubOp, opSlice.getStart(), opSlice.getLength()) ;
//        OpSQL x = new OpSQL(n, opSlice, request) ;
//        return x ;
//    }
//    
//    private Op transformSliceProject(OpSlice opSlice, OpSQL subOp, SqlNode sqlOp)
//    {
//        // This put the LIMIT outside all the projects left joins, which is a bit of a pity.
//        // Could improve by rewriting (slice (project...)) into (project (slice...)) in QueryCompilerMain 
//        OpSQL x = (OpSQL)transformSlice(opSlice, sqlOp) ;
//        SQLBridge bridge = subOp.getBridge() ;
//        return x ;
//    }
//    // ----
//    
//    private boolean translateConstraints = true ;
//    
//    private SDBConstraint transformFilter(OpFilter opFilter)
//    {
//        if ( ! translateConstraints )
//            return null ;
//        
//        ExprList exprs = opFilter.getExprs() ;
//        List<Expr> x = exprs.getList() ;
//        for ( Expr  expr : x )
//        {
//            ConditionCompiler cc = new RegexCompiler() ;
//            SDBConstraint psc = cc.recognize(expr) ;
//            if ( psc != null )
//                return psc ; 
//        }
//        return null ;
//    }
//
//    private Set<Var> getVarsInFilter(Expr expr)
//    {
//        Set<Var> vars = expr.getVarsMentioned() ;
//        return vars ;
//    }
@Override
public Op transform(OpDatasetNames opDatasetNames) {
    if (false)
        return super.transform(opDatasetNames);
    // Basically, an implementation of "GRAPH ?g {}" 
    Node g = opDatasetNames.getGraphNode();
    if (!Var.isVar(g))
        throw new SDBInternalError("OpDatasetNames - not a variable: " + g);
    Var v = Var.alloc(g);
    // Inner SELECT SQL: (SELECT DISTINCT g FROM Quads)
    TableDescQuads quads = request.getStore().getQuadTableDesc();
    SqlTable sqlTableQ = new SqlTable(quads.getTableName());
    sqlTableQ.setIdColumnForVar(v, new SqlColumn(sqlTableQ, quads.getGraphColName()));
    SqlNode sqlNodeQ = SqlSelectBlock.distinct(request, sqlTableQ);
    // Will have the value left join added later. 
    return new OpSQL(sqlNodeQ, opDatasetNames, request);
}
Also used : TableDescQuads(org.apache.jena.sdb.layout2.TableDescQuads) Var(org.apache.jena.sparql.core.Var) SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode) Node(org.apache.jena.graph.Node) SDBInternalError(org.apache.jena.sdb.shared.SDBInternalError) SqlTable(org.apache.jena.sdb.core.sqlnode.SqlTable) SqlColumn(org.apache.jena.sdb.core.sqlexpr.SqlColumn) SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode)

Example 2 with SqlColumn

use of org.apache.jena.sdb.core.sqlexpr.SqlColumn 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 3 with SqlColumn

use of org.apache.jena.sdb.core.sqlexpr.SqlColumn 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 4 with SqlColumn

use of org.apache.jena.sdb.core.sqlexpr.SqlColumn 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 5 with SqlColumn

use of org.apache.jena.sdb.core.sqlexpr.SqlColumn in project jena by apache.

the class SqlProject method project.

/** make sure this node is a projection and add a column */
/*public*/
private static SqlNode project(SqlNode sqlNode, SqlColumn col, String colOutName) {
    SqlColumn asCol = new SqlColumn(null, colOutName);
    ColAlias colAlias = new ColAlias(col, asCol);
    return SqlProject.project(sqlNode, colAlias);
}
Also used : SqlColumn(org.apache.jena.sdb.core.sqlexpr.SqlColumn)

Aggregations

SqlColumn (org.apache.jena.sdb.core.sqlexpr.SqlColumn)13 Var (org.apache.jena.sparql.core.Var)9 ScopeEntry (org.apache.jena.sdb.core.ScopeEntry)4 SqlExpr (org.apache.jena.sdb.core.sqlexpr.SqlExpr)3 SqlTable (org.apache.jena.sdb.core.sqlnode.SqlTable)3 S_Equal (org.apache.jena.sdb.core.sqlexpr.S_Equal)2 SqlNode (org.apache.jena.sdb.core.sqlnode.SqlNode)2 Node (org.apache.jena.graph.Node)1 Scope (org.apache.jena.sdb.core.Scope)1 SqlExprList (org.apache.jena.sdb.core.sqlexpr.SqlExprList)1 TableDescQuads (org.apache.jena.sdb.layout2.TableDescQuads)1 SDBInternalError (org.apache.jena.sdb.shared.SDBInternalError)1