Package org.teiid.language

Examples of org.teiid.language.Expression


    static int[] getNeededColumns(List<DerivedColumn> select, RuntimeMetadata metadata) throws TranslatorException {
        int[] cols = new int[select.size()];
        Iterator iter = select.iterator();
        for(int i=0; iter.hasNext(); i++) {
            DerivedColumn symbol = (DerivedColumn) iter.next();
            Expression expr = symbol.getExpression();
            if(expr instanceof ColumnReference) {
                Column element = ((ColumnReference)expr).getMetadataObject();
                cols[i] = element.getPosition();
            } else {
                throw new TranslatorException(YahooPlugin.Util.getString("YahooExecution.Invalid_select_symbol", expr)); //$NON-NLS-1$
View Full Code Here


    this.booleanNumeric = true;
    //number -> boolean
    this.addTypeConversion(new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        Expression stringValue = function.getParameters().get(0);
        return Arrays.asList("CASE WHEN ", stringValue, " = 0 THEN 0 WHEN ", stringValue, " IS NOT NULL THEN 1 END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
    }, FunctionModifier.BOOLEAN);
    this.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        Expression booleanValue = function.getParameters().get(0);
        if (booleanValue instanceof Function) {
          Function nested = (Function)booleanValue;
          if (nested.getName().equalsIgnoreCase("convert") && Number.class.isAssignableFrom(nested.getParameters().get(0).getType())) { //$NON-NLS-1$
            booleanValue = nested.getParameters().get(0);
          }
        }
        if (!booleanNullable) {
          return Arrays.asList("CASE WHEN ", booleanValue, " = 0 THEN 'false' ELSE 'true' END"); //$NON-NLS-1$ //$NON-NLS-2$         
        }
        return Arrays.asList("CASE WHEN ", booleanValue, " = 0 THEN 'false' WHEN ", booleanValue, " IS NOT NULL THEN 'true' END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
    });
      this.addConvert(FunctionModifier.STRING, FunctionModifier.BOOLEAN, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        Expression stringValue = function.getParameters().get(0);
        return Arrays.asList("CASE WHEN ", stringValue, " IN ('false', '0') THEN 0 WHEN ", stringValue, " IS NOT NULL THEN 1 END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
    });
  }
View Full Code Here

      objs.add(function.getName().substring(function.getName().indexOf('_') + 1));
      objs.add(SQLConstants.Tokens.LPAREN);
     
      for (Iterator<Expression> iter = parms.iterator(); iter.hasNext();)
      {
        Expression expr = iter.next();
        if (expr instanceof ColumnReference) {
          boolean dotAll = false;
          boolean useSelector = false;
          ColumnReference cr = (ColumnReference)expr;
          Column c = cr.getMetadataObject();
View Full Code Here

        this.convertModifier = convertModifier;
      }
   
      @Override
    public List<?> translate(Function function) {
        Expression expr1 =  function.getParameters().get(0);
        Expression expr2 =  function.getParameters().get(1);
        ArrayList target = new ArrayList();
        target.add("position("); //$NON-NLS-1$
        target.addAll(expressionToString(expr1, this.convertModifier));
        target.add( " in "); //$NON-NLS-1$
        target.addAll(expressionToString(expr2, this.convertModifier));
View Full Code Here

        this.funcName = name;
        this.convertModifier = converModifier;
      }
      @Override
    public List<?> translate(Function function) {
      Expression expr = function.getParameters().get(0);
      ArrayList target = new ArrayList();
      target.add(this.funcName);
      target.add("("); //$NON-NLS-1$
      target.addAll(expressionToString(expr, this.convertModifier));
      target.add(")"); //$NON-NLS-1$
View Full Code Here

      convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "HH24:MI:SS")); //$NON-NLS-1$ //$NON-NLS-2$
      convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD HH24:MI:SS.US")); //$NON-NLS-1$ //$NON-NLS-2$
      convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new FunctionModifier() {
      @Override
      public List<?> translate(Function function) {
        Expression stringValue = function.getParameters().get(0);
        return Arrays.asList("CASE WHEN ", stringValue, " THEN 'true' WHEN not(", stringValue, ") THEN 'false' END"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
    });
      convertModifier.addSourceConversion(new FunctionModifier() {
      @Override
View Full Code Here

     * @param expectedStr A string representing the modified expression
     * @return On success, the modified expression.
     * @throws Exception
     */
    public void helpTestLocate(final String locateFunctionName, final boolean parameterOrder, Expression[] args, String expectedStr) throws Exception {
      Expression param1 = null;
      Expression param2 = null;
      Expression param3 = null;
     
      if (args.length > 0 ) param1 = args[0];
      if (args.length > 1 ) param2 = args[1];
      if (args.length > 2 ) param3 = args[2];
     
View Full Code Here

     * @param expectedStr A string representing the modified expression
     * @return On success, the modified expression.
     * @throws Exception
     */
    public void helpTestMod(final String modFunctionName, Expression[] args, String expectedStr) throws Exception {
      Expression param1 = args[0];
      Expression param2 = args[1];
     
      Function func = LANG_FACTORY.createFunction(modFunctionName,
            Arrays.asList(param1, param2), param1.getType());

      JDBCExecutionFactory trans = new JDBCExecutionFactory() {
View Full Code Here

   * @param function the LOCATE function that may need to be modified
   */
    public void modify(Function function) {
      super.modify(function);
        List<Expression> args = function.getParameters();
        Expression searchStr = args.get(0);
        Expression sourceStr = args.get(1);

        // if startIndex was given then we may need to do additional work
        if (args.size() > 2) {
          args.set(2, ensurePositiveStartIndex(args.get(2)));
        }
View Full Code Here

    Iterator<DerivedColumn> symbolIter = selectSymbols.iterator();
    int index = 0;
    while (symbolIter.hasNext()) {
      DerivedColumn symbol = symbolIter.next();
      // get the name in source
      Expression expression = symbol.getExpression();
      if (expression instanceof ColumnReference) {
        Column element = ((ColumnReference) expression).getMetadataObject();
        selectSymbolIndexToElement.put(index, element);
        String qualifiedName = element.getParent().getNameInSource() + ':' + element.getNameInSource();
        selectSymbolNameToIndex .put(qualifiedName, index);
View Full Code Here

TOP

Related Classes of org.teiid.language.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.