Package org.teiid.query.sql.symbol

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


     * @param targetType the target type, if the expression's type is null.
     * @throws QueryResolverException if unable to set the reference type to the target type.
     */
    public static void setDesiredType(Expression expression, Class<?> targetType, LanguageObject surroundingExpression) throws QueryResolverException {
        if (expression instanceof Reference) {
          Reference ref = (Reference)expression;
          if (ref.isPositional() && ref.getType() == null) {
            if (targetType == null) {
              throw new QueryResolverException("ERR.015.008.0026", QueryPlugin.Util.getString("ERR.015.008.0026", surroundingExpression)); //$NON-NLS-1$ //$NON-NLS-2$
            }
              ref.setType(targetType);
          }
        } else if (expression instanceof Function) {
          Function f = (Function)expression;
          if (f.getType() == null) {
            f.setType(targetType);
View Full Code Here


       
        assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, function.getType());
    }
   
    @Test public void testResolveConvertReference() throws Exception {
        Function function = new Function("convert", new Expression[] {new Reference(0), new Constant(DataTypeManager.DefaultDataTypes.BOOLEAN)}); //$NON-NLS-1$
       
        ResolverVisitor.resolveLanguageObject(function, FakeMetadataFactory.example1Cached());
       
        assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getType());
        assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getArgs()[0].getType());
View Full Code Here

        assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getType());
        assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getArgs()[0].getType());
    }
   
    @Test public void testResolveAmbiguousFunction() throws Exception {
        Function function = new Function("LCASE", new Expression[] {new Reference(0)}); //$NON-NLS-1$
       
        try {
          ResolverVisitor.resolveLanguageObject(function, FakeMetadataFactory.example1Cached());
            fail("excpetion expected"); //$NON-NLS-1$
        } catch (QueryResolverException err) {
View Full Code Here

   
    static List<Reference> getReferences(Command command) {
        List<Reference> boundList = new ArrayList<Reference>();
       
        for (Iterator<Reference> refs = ReferenceCollectorVisitor.getReferences(command).iterator(); refs.hasNext();) {
            Reference ref = refs.next();
            Expression expr = ref.getExpression();
            if (!(expr instanceof ElementSymbol)){
                continue;
            }
            ElementSymbol elem = (ElementSymbol)expr;
           
View Full Code Here

     
      for (SPParameter metadataParameter : metadataParams) {
          SPParameter clonedParam = (SPParameter)metadataParameter.clone();
          if (clonedParam.getParameterType()==ParameterInfo.IN || metadataParameter.getParameterType()==ParameterInfo.INOUT) {
              ElementSymbol paramSymbol = clonedParam.getParameterSymbol();
              Reference ref = new Reference(paramSymbol);
              clonedParam.setExpression(ref);
              clonedParam.setIndex(paramIndex++);
              storedProcedureCommand.setParameter(clonedParam);
             
              String aliasName = paramSymbol.getShortName();
View Full Code Here

            @Override
            public Expression replaceExpression(Expression element) {
              if (!(element instanceof Reference)) {
                return element;
              }
              Reference ref = (Reference)element;
              if (!ref.isPositional()) {
                return ref;
              }
              return elements.get(ref.getIndex()).clone();
            }
          };
          DeepPostOrderNavigator.doVisit(currentCommand, emv);
        } else {
            TempMetadataStore rootExternalStore = new TempMetadataStore();
View Full Code Here

      if (expression instanceof ElementSymbol) {
        ElementSymbol es = (ElementSymbol)expression;
        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) {
            throw new QueryValidatorException(e, e.getMessage());
          }
                }
                return new Reference(es);
            }
            return expression;
      }
      boolean isBindEligible = true;
      if(expression instanceof Function) {
View Full Code Here

            critInProgress = prepareCriteria();
        }
       
        for (int j = 0; j < inputReferences.size(); j++) {

            Reference ref = (Reference)inputReferences.get(j);

            context.remove(ref.getExpression());
        }
       
      if (critInProgress == QueryRewriter.FALSE_CRITERIA) {
        critInProgress = null;
        consumedCriteria();
        return false;
      }

        boolean validRow = true;

        for (Iterator i = Criteria.separateCriteriaByAnd(critInProgress).iterator(); i.hasNext();) {
            Criteria crit = (Criteria)i.next();

            Object value = null;
            boolean nullAllowed = false;
            Reference parameter = null;

            if (crit instanceof IsNullCriteria) {
                parameter = (Reference)((IsNullCriteria)crit).getExpression();
                nullAllowed = true;
            } else if (crit instanceof CompareCriteria) {
                CompareCriteria compare = (CompareCriteria)crit;
                value = compare.getRightExpression();
                parameter = (Reference)compare.getLeftExpression();
            } else {
                Assertion.failed("Unknown predicate type"); //$NON-NLS-1$
            }

            if (value instanceof Expression) {
                value = eval.evaluate((Expression)value, null);
            }

            if (value == null && !nullAllowed) {
                validRow = false;
                break;
            }

            ElementSymbol parameterSymbol = parameter.getExpression();
            if (context.containsVariable(parameterSymbol)) {
              Object existingValue = context.getValue(parameterSymbol);
 
              if ((value != null && !value.equals(existingValue)) || (value == null && existingValue != null)) {
                  validRow = false;
                  break;
              }
            }

            context.setValue(parameterSymbol, value);
        }

        critInProgress = null;
        consumedCriteria();

        if (!validRow) {
            return false;
        }

        for (int j = 0; j < inputReferences.size(); j++) {
            Object defaultValue = inputDefaults.get(j);

            Reference ref = (Reference)inputReferences.get(j);

            if (defaultValue != null && !context.containsVariable(ref.getExpression())) {
                context.setValue(ref.getExpression(), defaultValue);
            }
        }

        return true;
    }
View Full Code Here

      /*
       * Special handling for references in translated criteria.
       * We need to create a locally valid reference name.
       */
      if (obj instanceof Reference) {
        Reference implicit = (Reference)obj;
        ElementSymbol key = null;
        if (implicit.isPositional()) {
          key = new ElementSymbol("$INPUT." + implicit.getContextSymbol()); //$NON-NLS-1$
        } else {
          key = new ElementSymbol("$INPUT." + implicit.getExpression().getName()); //$NON-NLS-1$
        }
        key.setType(implicit.getType());
        this.implicitParams.put(key, implicit);
        return new Reference(key);
      }
      return super.replaceExpression(obj);
    }
View Full Code Here

     } else if(expression instanceof CaseExpression) {
         return evaluate((CaseExpression) expression, tuple);
     } else if(expression instanceof SearchedCaseExpression) {
         return evaluate((SearchedCaseExpression) expression, tuple);
     } else if(expression instanceof Reference) {
       Reference ref = (Reference)expression;
       if (ref.isPositional() && ref.getExpression() == null) {
         return getContext(ref).getVariableContext().getGlobalValue(ref.getContextSymbol());
       }
       return internalEvaluate(ref.getExpression(), tuple);
     } else if(expression instanceof Criteria) {
         return evaluate((Criteria) expression, tuple);
     } else if(expression instanceof ScalarSubquery) {
         return evaluate((ScalarSubquery) expression, tuple);
     } else if (expression instanceof Criteria) {
View Full Code Here

TOP

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

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.