use of org.apache.jena.sdb.shared.SDBInternalError 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.shared.SDBInternalError in project jena by apache.
the class QueryIterOpSQL method nextStage.
@Override
protected QueryIterator nextStage(Binding binding) {
OpSQL execSQL = this.opSQL;
if (binding != null && !isRoot(binding)) {
QueryCompiler qc = opSQL.getRequest().getStore().getQueryCompilerFactory().createQueryCompiler(request);
Op op2 = Substitute.substitute(opSQL.getOriginal(), binding);
Op op = qc.compile(op2);
if (op instanceof OpSQL)
execSQL = (OpSQL) op;
else
throw new SDBInternalError("Failed to recompile the OpSQL to an OpSQL");
}
return execSQL.exec(binding, getExecContext());
// QueryIterator qIter = execSQL.exec(binding, getExecContext()) ;
// List<Binding> x = Iter.toList(qIter) ;
// qIter = new QueryIterPlainWrapper(x.iterator(), getExecContext()) ;
// System.out.println("SQL Eval:") ;
// x.forEach(b -> System.out.println(" "+b) );
// System.out.println() ;
// return qIter ;
}
use of org.apache.jena.sdb.shared.SDBInternalError 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.shared.SDBInternalError in project jena by apache.
the class SqlSelectBlock method blockWithView.
private static SqlSelectBlock blockWithView(SDBRequest request, SqlNode sqlNode) {
if (sqlNode instanceof SqlSelectBlock) {
SqlSelectBlock block = (SqlSelectBlock) sqlNode;
if (block.cols.size() == 0) {
// Didn't have a column view - force it
calcView(block);
}
return (SqlSelectBlock) sqlNode;
}
SqlSelectBlock block = _create(request, sqlNode);
if (block.getCols().size() != 0)
throw new SDBInternalError("Can't set a view on Select block which is already had columns set");
calcView(block);
return block;
}
Aggregations