use of org.apache.jena.sdb.core.sqlexpr.SqlExprList in project jena by apache.
the class SqlStageBasicQuad method build.
// There are three special graph names:
// Quad.defaultGraph - the quad marker for a query pattern for the default graph.
// Quad.defaultGraphName - the explicit internal name for the default graph
// Quad.unionDefaultGraph - the internal name for the union of all named graphs (excluding the degault graph).
//
// If SDB.unionDefaultGraph is true in the context, then patterns on the
// default graph are made against the union graph.
//
// If the explicit names (defaultGraphName, unionDefaultGraph) are used in GRAPH,
// then the default or union beahviour is avilable regardless of the setting of
// SDB.unionDefaultGraph.
@Override
public SqlNode build(SDBRequest request, SlotCompiler slotCompiler) {
SqlExprList conditions = new SqlExprList();
// ARQ 2.8.4 quad.isDefaultGraph() ;
boolean defaultGraph = Quad.isDefaultGraph(quad.getGraph());
boolean unionGraph = quad.isUnionGraph();
// ---- Choose the mode of access.
//quad.isDefaultGraph() ;
boolean accessStoredDefaultGraph = Quad.isDefaultGraph(quad.getGraph());
boolean accessUnionGraph = false;
if (accessStoredDefaultGraph && request.getContext().isTrue(SDB.unionDefaultGraph)) {
// Treat the default graph as the union of all triples in named graphs.
defaultGraph = false;
unionGraph = true;
accessStoredDefaultGraph = false;
accessUnionGraph = true;
}
// GRAPH <name of default graph> { }
if (quad.isDefaultGraphExplicit()) {
// "named" access to the default graph
accessStoredDefaultGraph = true;
accessUnionGraph = false;
}
if (quad.isUnionGraph()) {
// "named" access to the union of the named graphs
accessStoredDefaultGraph = false;
accessUnionGraph = true;
// Add DISTINCT over the join of SqlStageBasicQuad for RDF merge
}
// ---- Choose the table to access
// The default graph table may be a specialized table (e.g. triples, not quads).
TableDescQuads tableDesc = null;
String alias = null;
if (accessStoredDefaultGraph) {
tableDesc = request.getStore().getTripleTableDesc();
alias = request.genId(AliasesSql.TriplesTableBase);
} else {
tableDesc = request.getStore().getQuadTableDesc();
alias = request.genId(AliasesSql.QuadTableBase);
}
SqlTable table = new SqlTable(alias, tableDesc.getTableName());
if (accessStoredDefaultGraph)
table.addNote(FmtUtils.stringForTriple(quad.asTriple(), request.getPrefixMapping()));
else
table.addNote(FmtUtils.stringForQuad(quad, request.getPrefixMapping()));
if (!accessStoredDefaultGraph && !accessUnionGraph)
slotCompiler.processSlot(request, table, conditions, quad.getGraph(), tableDesc.getGraphColName());
slotCompiler.processSlot(request, table, conditions, quad.getSubject(), tableDesc.getSubjectColName());
slotCompiler.processSlot(request, table, conditions, quad.getPredicate(), tableDesc.getPredicateColName());
slotCompiler.processSlot(request, table, conditions, quad.getObject(), tableDesc.getObjectColName());
return SqlBuilder.restrict(request, table, conditions);
}
use of org.apache.jena.sdb.core.sqlexpr.SqlExprList in project jena by apache.
the class GenerateSQLVisitor method rewrite.
public SqlJoinInner rewrite(SqlJoinInner join) {
if (!join.getRight().isInnerJoin())
return join;
// if ( join(A, join(B, C)) ) rewrite as join(join(A,B),C)
// this then is written without brackets (and so scope changing)
// TODO abstract as organiseJoin(List<join elements>)
// and remember to do top down to find maximal join trees
SqlJoinInner right = join.getRight().asInnerJoin();
String alias1 = join.getAliasName();
String alias2 = right.getAliasName();
SqlNode sn_a = join.getLeft();
SqlNode sn_b = right.getLeft();
SqlNode sn_c = right.getRight();
SqlExprList conditions = new SqlExprList(join.getConditions());
conditions.addAll(right.getConditions());
Set<SqlTable> tables_ab = sn_a.tablesInvolved();
tables_ab.addAll(sn_b.tablesInvolved());
// Goes to new join(A,B)
SqlExprList newCond_ab = new SqlExprList();
// Goes to new join(,C)
SqlExprList newCond_c = new SqlExprList();
// Place conditions
for (SqlExpr e : conditions) {
Set<SqlColumn> cols = e.getColumnsNeeded();
// columns to tables.
Set<SqlTable> tables = tables(cols);
// Are the tables contained in tables_ab?
tables.removeAll(tables_ab);
if (tables.size() == 0)
newCond_ab.add(e);
else
newCond_c.add(e);
}
if (newCond_ab.size() + newCond_c.size() != conditions.size())
log.error(String.format("Conditions mismatch: (%d,%d,%d)", newCond_ab.size(), newCond_c.size(), conditions.size()));
SqlJoinInner join2 = new SqlJoinInner(sn_a, sn_b);
join2.addConditions(newCond_ab);
join2 = new SqlJoinInner(join2, sn_c);
join2.addConditions(newCond_c);
return join2;
}
Aggregations