static Table evalQuadPattern(OpQuadPattern opQuad, Evaluator evaluator)
{
if ( opQuad.isEmpty() )
return TableFactory.createUnit() ;
ExecutionContext cxt = evaluator.getExecContext() ;
DatasetGraph ds = cxt.getDataset() ;
BasicPattern pattern = opQuad.getBasicPattern() ;
if ( ! opQuad.getGraphNode().isVariable() )
{
if ( ! opQuad.getGraphNode().isURI() )
{ throw new ARQInternalErrorException("Not a URI or variable: "+opQuad.getGraphNode()) ;}
Graph g = null ;
if ( opQuad.isDefaultGraph() )
g = ds.getDefaultGraph() ;
else
g = ds.getGraph(opQuad.getGraphNode()) ;
if ( g == null )
return new TableEmpty() ;
ExecutionContext cxt2 = new ExecutionContext(cxt, g) ;
QueryIterator qIter = executeBGP(pattern, QueryIterRoot.create(cxt2), cxt2) ;
return TableFactory.create(qIter) ;
}
else
{
// Variable.
Var gVar = Var.alloc(opQuad.getGraphNode()) ;
// Or just just devolve to OpGraph and get OpUnion chain of OpJoin
QueryIterConcat concat = new QueryIterConcat(cxt) ;
for ( Iterator<Node> graphNodes = cxt.getDataset().listGraphNodes() ; graphNodes.hasNext(); )
{
Node gn = graphNodes.next() ;
//Op tableVarURI = TableFactory.create(gn.getName(), Node.createURI(uri)) ;
Graph g = cxt.getDataset().getGraph(gn) ;
Binding b = BindingFactory.binding(BindingRoot.create(), gVar, gn) ;
ExecutionContext cxt2 = new ExecutionContext(cxt, g) ;
// Eval the pattern, eval the variable, join.
// Pattern may be non-linear in the variable - do a pure execution.
Table t1 = TableFactory.create(gVar, gn) ;
QueryIterator qIter = executeBGP(pattern, QueryIterRoot.create(cxt2), cxt2) ;