Package org.teiid.query.sql.symbol

Examples of org.teiid.query.sql.symbol.Expression


     * @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;
View Full Code Here


     * @throws QueryValidatorException
     * @since 4.2
     */
    private Criteria simplifyConvertFunction(CompareCriteria crit) {
        Function leftFunction = (Function) crit.getLeftExpression();
        Expression leftExpr = leftFunction.getArgs()[0];
       
        if(!(crit.getRightExpression() instanceof Constant)
            //TODO: this can be relaxed for order preserving operations
            || !(crit.getOperator() == CompareCriteria.EQ || crit.getOperator() == CompareCriteria.NE)) {
          return crit;
        }

        Constant rightConstant = (Constant) crit.getRightExpression();
       
        String leftExprTypeName = DataTypeManager.getDataTypeName(leftExpr.getType());

        Constant result = ResolverUtil.convertConstant(DataTypeManager.getDataTypeName(rightConstant.getType()), leftExprTypeName, rightConstant);
        if (result == null) {
          return getSimpliedCriteria(crit, leftExpr, crit.getOperator() != CompareCriteria.EQ, true);
        }
View Full Code Here

     * @throws QueryValidatorException
     * @since 4.2
     */
  private Criteria simplifyConvertFunction(SetCriteria crit) throws TeiidComponentException, TeiidProcessingException{
        Function leftFunction = (Function) crit.getExpression();
        Expression leftExpr = leftFunction.getArgs()[0];
        String leftExprTypeName = DataTypeManager.getDataTypeName(leftExpr.getType());
       
        Iterator i = crit.getValues().iterator();
        Collection newValues = new ArrayList(crit.getNumberOfValues());
       
        boolean convertedAll = true;
View Full Code Here

            inverseFunction = "parse" + type; //$NON-NLS-1$
            isFormat = true;
        } else {
            return crit;
        }
        Expression rightExpr = crit.getRightExpression();
        if (!(rightExpr instanceof Constant)) {
          return crit;
        }
        Expression leftExpr = leftFunction.getArgs()[0];
        Expression formatExpr = leftFunction.getArgs()[1];
        if(!(formatExpr instanceof Constant)) {
            return crit;
        }
        String format = (String)((Constant)formatExpr).getValue();
        FunctionLibrary funcLib = this.metadata.getFunctionLibrary();
        FunctionDescriptor descriptor = funcLib.findFunction(inverseFunction, new Class[] { rightExpr.getType(), formatExpr.getType() });
        if(descriptor == null){
            return crit;
        }
      Object value = ((Constant)rightExpr).getValue();
      try {
View Full Code Here

    private Criteria simplifyTimestampMerge2(CompareCriteria criteria) {
        if(criteria.getOperator() != CompareCriteria.EQ) {
            return criteria;
        }
       
        Expression leftExpr = criteria.getLeftExpression();
        Expression rightExpr = criteria.getRightExpression();
       
        // Allow for concat and string literal to be on either side
        Function tsCreateFunction = null;
        Constant timestampConstant = null;       
        if(leftExpr instanceof Function && rightExpr instanceof Constant) {
View Full Code Here

   private Criteria simplifyTimestampMerge(CompareCriteria criteria) {
       if(criteria.getOperator() != CompareCriteria.EQ) {
           return criteria;
       }
      
       Expression leftExpr = criteria.getLeftExpression();
       Expression rightExpr = criteria.getRightExpression();
      
       // Allow for concat and string literal to be on either side
       Function concatFunction = null;
       Constant timestampConstant = null;       
       if(leftExpr instanceof Function && rightExpr instanceof Constant) {
View Full Code Here

       
        if (isNull(criteria.getLeftExpression()) || isNull(criteria.getRightExpression())) {
            return UNKNOWN_CRITERIA;
        }

        Expression rightExpr = criteria.getRightExpression();
        if(rightExpr instanceof Constant && rightExpr.getType().equals(DataTypeManager.DefaultDataClasses.STRING)) {
            Constant constant = (Constant) rightExpr;
            String value = (String) constant.getValue();

            char escape = criteria.getEscapeChar();
View Full Code Here

        LinkedHashSet newVals = new LinkedHashSet(vals.size());
        Iterator valIter = vals.iterator();
        boolean allConstants = true;
        boolean hasNull = false;
        while(valIter.hasNext()) {
            Expression value = rewriteExpressionDirect( (Expression) valIter.next());
            if (isNull(value)) {
              hasNull = true;
              continue;
            }
            allConstants &= value instanceof Constant;
            newVals.add(value);
        }
       
        int size = newVals.size();
        if (size == 1) {
            Expression value = (Expression)newVals.iterator().next();
            return rewriteCriteria(new CompareCriteria(criteria.getExpression(), criteria.isNegated()?CompareCriteria.NE:CompareCriteria.EQ, value));
        }
       
        criteria.setValues(newVals);
        if (allConstants) {
View Full Code Here

        Class<?> type  = es.getType();
            if (!processing && es.isExternalReference()) {
                if (variables == null) {
                  return new Reference(es);
                }
                Expression value = variables.get(es);

                if (value == null) {
                  if (es.getGroupSymbol().getSchema() == null) {
                        String grpName = es.getGroupSymbol().getShortCanonicalName();
                    if (grpName.equals(ProcedureReservedWords.INPUTS)) {
                      return new Constant(null, es.getType());
                    }
                    if (grpName.equals(ProcedureReservedWords.CHANGING)) {
                        Assertion.failed("Changing value should not be null"); //$NON-NLS-1$
                    }
                  }
                } else if (value instanceof Constant) {
                  if (value.getType() == type) {
                    return value;
                  }
                  try {
            return new Constant(FunctionMethods.convert(((Constant)value).getValue(), DataTypeManager.getDataTypeName(type)), es.getType());
          } catch (FunctionExecutionException e) {
View Full Code Here

       
        return function;
  }

  private Expression convertDecodeFunction(Function function){
      Expression exprs[] = function.getArgs();
      String decodeString = (String)((Constant)exprs[1]).getValue();
      String decodeDelimiter = ","; //$NON-NLS-1$
      if(exprs.length == 3){
        decodeDelimiter = (String)((Constant)exprs[2]).getValue();
      }
View Full Code Here

TOP

Related Classes of org.teiid.query.sql.symbol.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.