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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations