Search in sources :

Example 6 with SqlNode

use of org.apache.jena.sdb.core.sqlnode.SqlNode in project jena by apache.

the class SlotCompilerIndex method insertConstantAccesses.

protected SqlNode insertConstantAccesses(Collection<Node> constants) {
    SqlNode sqlNode = null;
    for (Node n : constants) {
        long hash = NodeLayout2.hash(n);
        SqlConstant hashValue = new SqlConstant(hash);
        // Access nodes table.
        SqlTable nTable = new SqlTable(getRequest().genId(NodeConstBase), nodeTableDesc.getTableName());
        nTable.addNote("Const: " + FmtUtils.stringForNode(n, getRequest().getPrefixMapping()));
        SqlColumn cHash = new SqlColumn(nTable, nodeTableDesc.getHashColName());
        // Record 
        constantCols.put(n, new SqlColumn(nTable, nodeTableDesc.getIdColName()));
        SqlExpr c = new S_Equal(cHash, hashValue);
        sqlNode = SqlBuilder.innerJoin(getRequest(), sqlNode, nTable);
        sqlNode = SqlBuilder.restrict(getRequest(), sqlNode, c);
    }
    return sqlNode;
}
Also used : SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode) Node(org.apache.jena.graph.Node) SqlTable(org.apache.jena.sdb.core.sqlnode.SqlTable) SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode)

Example 7 with SqlNode

use of org.apache.jena.sdb.core.sqlnode.SqlNode in project jena by apache.

the class SQLBridge2 method insertValueGetter.

private SqlNode insertValueGetter(SDBRequest request, SqlNode sqlNode, Var var) {
    ScopeEntry e1 = sqlNode.getIdScope().findScopeForVar(var);
    if (e1 == null) {
        // Debug.
        Scope scope = sqlNode.getIdScope();
        // Variable not actually in results.
        return sqlNode;
    }
    // Already in scope (from a condition)?
    ScopeEntry e2 = sqlNode.getNodeScope().findScopeForVar(var);
    if (e2 != null)
        // Already there
        return sqlNode;
    SqlColumn c1 = e1.getColumn();
    // Not in scope -- add a table to get it
    TableDescNodes nodeTableDesc = request.getStore().getNodeTableDesc();
    String tableAlias = request.genId(NodeBase);
    SqlTable nTable = new SqlTable(tableAlias, nodeTableDesc.getTableName());
    String nodeKeyColName = nodeTableDesc.getNodeRefColName();
    SqlColumn c2 = new SqlColumn(nTable, nodeKeyColName);
    nTable.setValueColumnForVar(var, c2);
    // Condition for value: triple table column = node table id/hash 
    nTable.addNote("Var: " + var);
    SqlExpr cond = new S_Equal(c1, c2);
    SqlNode n = SqlBuilder.leftJoin(request, sqlNode, nTable, cond);
    return n;
}
Also used : ScopeEntry(org.apache.jena.sdb.core.ScopeEntry) Scope(org.apache.jena.sdb.core.Scope) SqlExpr(org.apache.jena.sdb.core.sqlexpr.SqlExpr) SqlTable(org.apache.jena.sdb.core.sqlnode.SqlTable) S_Equal(org.apache.jena.sdb.core.sqlexpr.S_Equal) SqlColumn(org.apache.jena.sdb.core.sqlexpr.SqlColumn) SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode)

Example 8 with SqlNode

use of org.apache.jena.sdb.core.sqlnode.SqlNode in project jena by apache.

the class QuadBlockCompilerMain method compile.

//@Override
@Override
public final SqlNode compile(QuadBlock quads) {
    SqlNode sqlNode = slotCompiler.start(quads);
    // Copy it because it's modified.
    quads = new QuadBlock(quads);
    // ---- Stage builder 
    SqlStageList sList = new SqlStageList();
    // Potential concurrent modification - need to use an explicit index.
    for (int i = 0; i < quads.size(); ) {
        Quad q = quads.get(i);
        if (patternTable != null && patternTable.trigger(q)) {
            // Removes current quad
            SqlStage stage = patternTable.process(i, quads);
            if (stage != null) {
                if (quads.get(i) == q)
                    throw new SDBInternalError("Pattern table returned a stage but did not remove the first quad");
                sList.add(stage);
                continue;
            }
        }
        sList.add(new SqlStageBasicQuad(q));
        i++;
    }
    // ---- and now turn the stages into SqlNodes  
    SqlNode sqlStages = sList.build(request, slotCompiler);
    // --- Join the initial node (constants). 
    sqlNode = SqlBuilder.innerJoin(request, sqlNode, sqlStages);
    sqlNode = slotCompiler.finish(sqlNode, quads);
    // Insert DISTINCT if accessing the RDF merge of all named graphs
    // An RDF Merge is the DISTINCT results of query over the union of all graphs.
    // Or in TransformSDB
    boolean needDistinct = false;
    // Either it's the uniongraph ...
    if (quads.getGraphNode().equals(Quad.unionGraph))
        needDistinct = true;
    else // Or it's the union graph via redirected defaultGraph
    if (Quad.isDefaultGraphGenerated(quads.getGraphNode()) && request.getContext().isTrue(SDB.unionDefaultGraph))
        needDistinct = true;
    if (needDistinct) {
        // DISTINCT -- over the named variables but not * (which includes the graph node).
        String renameName = request.genId("A");
        //sqlNode = SqlRename.view(renameName, sqlNode) ;
        sqlNode = SqlBuilder.view(request, sqlNode);
        sqlNode = SqlBuilder.distinct(request, sqlNode);
    }
    return sqlNode;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) SDBInternalError(org.apache.jena.sdb.shared.SDBInternalError) SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode)

Example 9 with SqlNode

use of org.apache.jena.sdb.core.sqlnode.SqlNode in project jena by apache.

the class SDB_QC method toSqlString.

public static String toSqlString(OpSQL opSQL, SDBRequest request) {
    SqlNode sqlNode = opSQL.getSqlNode();
    String sqlStmt = request.getStore().getSQLGenerator().generateSQL(request, sqlNode);
    return sqlStmt;
}
Also used : SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode)

Example 10 with SqlNode

use of org.apache.jena.sdb.core.sqlnode.SqlNode in project jena by apache.

the class TransformSDB method transform.

@Override
public Op transform(OpJoin opJoin, Op left, Op right) {
    // Scoping problems.
    if (true)
        return super.transform(opJoin, left, right);
    if (!SDB_QC.isOpSQL(left) || !SDB_QC.isOpSQL(right))
        return super.transform(opJoin, left, right);
    SqlNode sqlLeft = ((OpSQL) left).getSqlNode();
    SqlNode sqlRight = ((OpSQL) right).getSqlNode();
    return new OpSQL(SqlBuilder.innerJoin(request, sqlLeft, sqlRight), opJoin, request);
}
Also used : SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode)

Aggregations

SqlNode (org.apache.jena.sdb.core.sqlnode.SqlNode)11 SqlTable (org.apache.jena.sdb.core.sqlnode.SqlTable)3 Var (org.apache.jena.sparql.core.Var)3 Node (org.apache.jena.graph.Node)2 ScopeEntry (org.apache.jena.sdb.core.ScopeEntry)2 SqlColumn (org.apache.jena.sdb.core.sqlexpr.SqlColumn)2 SDBInternalError (org.apache.jena.sdb.shared.SDBInternalError)2 Scope (org.apache.jena.sdb.core.Scope)1 S_Equal (org.apache.jena.sdb.core.sqlexpr.S_Equal)1 SqlExpr (org.apache.jena.sdb.core.sqlexpr.SqlExpr)1 TableDescQuads (org.apache.jena.sdb.layout2.TableDescQuads)1 SQLBridge (org.apache.jena.sdb.store.SQLBridge)1 SQLBridgeFactory (org.apache.jena.sdb.store.SQLBridgeFactory)1 Quad (org.apache.jena.sparql.core.Quad)1