* @return CompareCriteria
*/
private CompareCriteria simplifyMathematicalCriteria(CompareCriteria criteria)
throws TeiidComponentException, TeiidProcessingException{
Expression leftExpr = criteria.getLeftExpression();
Expression rightExpr = criteria.getRightExpression();
// Identify all the pieces of this criteria
Function function = (Function) leftExpr;
String funcName = function.getName();
Expression[] args = function.getArgs();
Constant const1 = null;
Expression expr = null;
if(args[1] instanceof Constant) {
const1 = (Constant) args[1];
expr = args[0];
} else {
if(funcName.equals("+") || funcName.equals("*")) { //$NON-NLS-1$ //$NON-NLS-2$
const1 = (Constant) args[0];
expr = args[1];
} else {
// If we have "5 - x = 10" or "5 / x = 10", abort!
return criteria;
}
}
int operator = criteria.getOperator();
// Determine opposite function
String oppFunc = null;
switch(funcName.charAt(0)) {
case '+': oppFunc = "-"; break; //$NON-NLS-1$
case '-': oppFunc = "+"; break; //$NON-NLS-1$
case '*': oppFunc = "/"; break; //$NON-NLS-1$
case '/': oppFunc = "*"; break; //$NON-NLS-1$
}
// Create a function of the two constants and evaluate it
Expression combinedConst = null;
FunctionLibrary funcLib = this.metadata.getFunctionLibrary();
FunctionDescriptor descriptor = funcLib.findFunction(oppFunc, new Class[] { rightExpr.getType(), const1.getType() });
if (descriptor == null){
//See defect 9380 - this can be caused by const2 being a null Constant, for example (? + 1) < null
return criteria;