public TransformFilterDisjunction() {}
@Override
public Op transform(OpFilter opFilter, final Op subOp)
{
ExprList exprList = opFilter.getExprs() ;
// First pass - any disjunctions at all?
boolean processDisjunction = false ;
for ( Expr expr : exprList )
{
if ( isDisjunction(expr) )
{
processDisjunction = true ;
break ;
}
}
// Still may be a disjunction in a form we don't optimize.
if ( ! processDisjunction )
return super.transform(opFilter, subOp) ;
ExprList exprList2 = new ExprList() ;
Op newOp = subOp ;
// remember what's been seen so that FILTER(?x = <x> || ?x = <x> ) does not result in two transforms.
Set<Expr> doneSoFar = new HashSet<>() ;
for ( Expr expr : exprList )
{
if ( ! isDisjunction(expr) )
{
// Assignment there?
exprList2.add(expr) ;
continue ;
}
// // Relies on expression equality.
// if ( doneSoFar.contains(expr) )
// continue ;
// // Must be canonical: ?x = <x> is the same as <x> = ?x
// doneSoFar.add(expr) ;
Op op2 = expandDisjunction(expr, newOp) ;
if ( op2 != null )
newOp = op2 ;
}
if ( exprList2.isEmpty() )
return newOp ;
// There should have been at least on disjunction.
if ( newOp == subOp ) {
Log.warn(this, "FilterDisjunction assumption failure: didn't find a disjunction after all") ;