use of org.apache.jena.sdb.layout2.TableDescQuads 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.layout2.TableDescQuads 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);
}
use of org.apache.jena.sdb.layout2.TableDescQuads in project jena by apache.
the class FmtLayout2IndexDerby method formatTableQuads.
@Override
protected void formatTableQuads() {
TableDescQuads desc = new TableDescQuads();
dropTable(desc.getTableName());
try {
String x = sqlStr("CREATE TABLE %s (", " %2$s int NOT NULL,", " %3$s int NOT NULL,", " %4$s int NOT NULL,", " %5$s int NOT NULL,", " PRIMARY KEY (%2$s, %3$s, %4$s, %5$s)", ")");
x = String.format(x, desc.getTableName(), desc.getGraphColName(), desc.getSubjectColName(), desc.getPredicateColName(), desc.getObjectColName());
connection().exec(sqlStr("CREATE TABLE " + desc.getTableName() + " (", " g int NOT NULL,", " s int NOT NULL,", " p int NOT NULL,", " o int NOT NULL,", " PRIMARY KEY (g, s, p, o)", ")"));
} catch (SQLException ex) {
throw new SDBExceptionSQL("SQLException formatting table '" + TableDescTriples.name() + "'", ex);
}
}
Aggregations