// return null for don't need an expr anymore.
private Expr convert(Expr expr, SqlSelectBlock ssb, OpSQL opSQL)
{
if ( ! ( expr instanceof E_Regex ) )
return expr ;
E_Regex regex = (E_Regex)expr ;
Expr exprPattern = regex.getArg(2) ;
Expr exprFlags = ( regex.getArg(3) == null ? null : regex.getArg(3) ) ;
boolean caseInsensitive = false ;
// Any flags?
if ( exprFlags != null )
{
// Expression for flags?
if ( ! exprFlags.isConstant() ) return expr ;
String flags = exprFlags.getConstant().asString() ;
if ( ! "i".equals(flags) ) return expr ;
caseInsensitive = true ;
}
// Check pattern - must be a constant string
if ( !exprPattern.isConstant() ) return expr ;
String pattern = exprPattern.getConstant().asString() ;
if ( pattern == null ) return expr ;
// See if it's LIKEable.
String patternLike = RegexUtils.regexToLike(pattern) ;
if ( patternLike == null )
return expr ;
// Check target
// BUG in old ARQ getRegexExpr() returns the wrong thing.
if ( ! regex.getArg(1).isVariable() ) return expr ;
Var v = regex.getArg(1).asVar() ;
// Scope check
if ( ! ssb.getNodeScope().hasColumnForVar(v) )
// Probably out of scope - or just not in the graph apttern.
return expr ;