private List < GroovyExpression > expandOrFunction ( GroovyExpression expr , OptimizationContext context ) { FunctionCallExpression functionCall = ( FunctionCallExpression ) expr ; GroovyExpression caller = functionCall . getCaller ( ) ; List < GroovyExpression > updatedCallers = null ; if ( caller != null ) { updatedCallers = expandOrs ( caller , context ) ; } else { updatedCallers = Collections . singletonList ( null ) ; } UpdatedExpressions newArguments = getUpdatedChildren ( functionCall . getArguments ( ) , context ) ; List < GroovyExpression > allUpdatedArguments = new ArrayList <> ( ) ; for ( List < GroovyExpression > exprs : newArguments . getUpdatedChildren ( ) ) { allUpdatedArguments . addAll ( exprs ) ; } List < AbstractFunctionExpression > extractableArguments = new ArrayList <> ( ) ; List < GroovyExpression > nonExtractableArguments = new ArrayList <> ( ) ; for ( GroovyExpression argument : allUpdatedArguments ) { if ( GremlinQueryOptimizer . isExtractable ( argument ) ) { extractableArguments . add ( ( AbstractFunctionExpression ) argument ) ; } else { logger_ . warn ( "Found non-extractable argument '{}; in the 'or' expression '{}'" , argument . toString ( ) , expr . toString ( ) ) ; nonExtractableArguments . add ( argument ) ; } } List < GroovyExpression > result = new ArrayList <> ( ) ; for ( GroovyExpression updatedCaller : updatedCallers ) { for ( AbstractFunctionExpression arg : extractableArguments ) { GroovyExpression updated = GremlinQueryOptimizer . copyWithNewLeafNode ( arg , updatedCaller ) ; result . add ( updated ) ; } if ( ! nonExtractableArguments . isEmpty ( ) ) { result . add ( factory . generateLogicalExpression ( updatedCaller , "or" , nonExtractableArguments ) ) ; } } return result ; }
This method takes an or expression and expands it into multiple expressions .