Package org.teiid.language

Examples of org.teiid.language.Function


    if (supportedTypes.contains(type)) {
      modify(function);
      return null;
    }
    //x % y => x - sign(x) * floor(abs(x / y)) * y
    Function divide = langFactory.createFunction(SourceSystemFunctions.DIVIDE_OP, new ArrayList<Expression>(expressions), type);

    Function abs = langFactory.createFunction(SourceSystemFunctions.ABS, Arrays.asList(divide), type);
   
    Function floor = langFactory.createFunction(SourceSystemFunctions.FLOOR, Arrays.asList(abs), type);
   
    Function sign = langFactory.createFunction(SourceSystemFunctions.SIGN, Arrays.asList(expressions.get(0)), type);
   
    List<? extends Expression> multArgs = Arrays.asList(sign, floor, langFactory.createFunction(SourceSystemFunctions.ABS, Arrays.asList(expressions.get(1)), type));
    Function mult = langFactory.createFunction(SourceSystemFunctions.MULTIPLY_OP, multArgs, type);

    List<Expression> minusArgs = Arrays.asList(expressions.get(0), mult);
   
    return Arrays.asList(langFactory.createFunction(SourceSystemFunctions.SUBTRACT_OP, minusArgs, type));
  }
View Full Code Here


    public LanguageObject example1() {
        NamedTable g = new NamedTable("g1", null, null); //$NON-NLS-1$
        List symbols = new ArrayList();       
        symbols.add(new ColumnReference(g, "e1", null, String.class)); //$NON-NLS-1$
        Function function = new Function("length", Arrays.asList(new ColumnReference(g, "e2", null, String.class)), Integer.class); //$NON-NLS-1$ //$NON-NLS-2$
        symbols.add(function);
        List groups = new ArrayList();
        groups.add(g);
        Select q = new Select(symbols, false, groups, null, null, null, null);
            
View Full Code Here

    public TestMonthOrDayNameFunctionModifier(String name) {
        super(name);
    }

    public void helpTestMod(Literal c, String format, String expectedStr) throws Exception {
        Function func = LANG_FACTORY.createFunction(format.toLowerCase()+"name"// "monthname" //$NON-NLS-1$
            Arrays.asList( c ),
            String.class);
       
        OracleExecutionFactory trans = new OracleExecutionFactory();
        trans.start();
View Full Code Here

   
    @Test public void testVisitConvertFunctionOracleStyle() throws Exception {
        String expected = "convert(columnA, integer)"; //$NON-NLS-1$
       
        List<? extends Expression> params = Arrays.asList(new ColumnReference(null, "columnA", null, String.class), new Literal("integer", String.class));
        Function test = new Function("convert", params, Integer.class); //$NON-NLS-1$
       
        assertEquals(expected, getString(test));
    }
View Full Code Here

        registerFunctionModifier(SourceSystemFunctions.DIVIDE_OP, new FunctionModifier() {
     
      @Override
      public List<?> translate(Function function) {
        if (function.getType() == TypeFacility.RUNTIME_TYPES.INTEGER || function.getType() == TypeFacility.RUNTIME_TYPES.LONG) {
          Function result = ConvertModifier.createConvertFunction(getLanguageFactory(), function, TypeFacility.getDataTypeName(function.getType()));
          function.setType(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
          return Arrays.asList(result);
        }
        return null;
      }
View Full Code Here

    if (tgtType.equals(String.class) && (expr instanceof Literal)) {
      return Arrays.asList(expr)
    }
    else if (tgtType.equals(String.class) && (expr instanceof Function)) {
     
      Function func = (Function)expr;
      if (func.getParameters().get(0) instanceof ColumnReference) {
        ColumnReference ref = (ColumnReference)func.getParameters().get(0);
        if(Number.class.isAssignableFrom(ref.getType())) {
          ArrayList target = new ArrayList();
          target.add("cast("); //$NON-NLS-1$
          target.add(func.getParameters().get(0));
          target.add(" AS varchar(100))"); //$NON-NLS-1$
        }
        else {
          return modifier.translate(func);
        }
View Full Code Here

       
        return sqlVisitor.toString();       
    }

    public void helpTest(Expression srcExpression, String tgtType, String expectedExpression) throws Exception {
        Function func = LANG_FACTORY.createFunction("convert"//$NON-NLS-1$
            Arrays.asList(
                srcExpression,
                LANG_FACTORY.createLiteral(tgtType, String.class)),
            TypeFacility.getDataTypeClass(tgtType));
       
View Full Code Here

       
        return sqlVisitor.toString();       
    }

    public void helpTest(Expression srcExpression, String tgtType, String expectedExpression) throws Exception {
        Function func = LANG_FACTORY.createFunction("convert"//$NON-NLS-1$
            Arrays.asList(
                srcExpression,
                LANG_FACTORY.createLiteral(tgtType, String.class)),
            TypeFacility.getDataTypeClass(tgtType));
       
View Full Code Here

       
        return sqlVisitor.toString();       
    }

    public void helpTest(Expression srcExpression, String tgtType, String expectedExpression) throws Exception {
        Function func = LANG_FACTORY.createFunction("convert"//$NON-NLS-1$
            Arrays.asList(
                srcExpression,
                LANG_FACTORY.createLiteral(tgtType, String.class)),
            TypeFacility.getDataTypeClass(tgtType));
       
View Full Code Here

     * @return list of translated parts
     */
    public List<?> translate(LanguageObject obj, ExecutionContext context) {
    List<?> parts = null;
      if (obj instanceof Function) {
        Function function = (Function)obj;
        if (functionModifiers != null) {
          FunctionModifier modifier = functionModifiers.get(function.getName().toLowerCase());
          if (modifier != null) {
            parts = modifier.translate(function);
          }
        }
      } else if (obj instanceof Command) {
View Full Code Here

TOP

Related Classes of org.teiid.language.Function

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.