Search in sources :

Example 6 with Function

use of org.teiid.language.Function in project teiid by teiid.

the class MonthOrDayNameFunctionModifier method translate.

@Override
public List<?> translate(Function function) {
    List<Expression> args = function.getParameters();
    Function func = // $NON-NLS-1$
    langFactory.createFunction(// $NON-NLS-1$
    "TO_CHAR", Arrays.asList(args.get(0), langFactory.createLiteral(format, TypeFacility.RUNTIME_TYPES.STRING)), TypeFacility.RUNTIME_TYPES.STRING);
    // For some reason, these values have trailing spaces
    Function trimFunc = langFactory.createFunction(SourceSystemFunctions.RTRIM, Arrays.asList(func), TypeFacility.RUNTIME_TYPES.STRING);
    return Arrays.asList(trimFunc);
}
Also used : Function(org.teiid.language.Function) Expression(org.teiid.language.Expression)

Example 7 with Function

use of org.teiid.language.Function in project teiid by teiid.

the class TestSQLConversionVisitor method helpTestMod.

private void helpTestMod(Literal c, String format, String expectedStr) throws Exception {
    Function func = LANG_FACTORY.createFunction(format, Arrays.asList(c), String.class);
    PrestoDBExecutionFactory ef = new PrestoDBExecutionFactory();
    ef.start();
    SQLConversionVisitor sqlVisitor = ef.getSQLConversionVisitor();
    sqlVisitor.append(func);
    assertEquals(expectedStr, sqlVisitor.toString());
}
Also used : Function(org.teiid.language.Function) SQLConversionVisitor(org.teiid.translator.jdbc.SQLConversionVisitor)

Example 8 with Function

use of org.teiid.language.Function in project teiid by teiid.

the class TestLeftOrRightFunctionModifier method helpTestMod.

public void helpTestMod(Literal c, Literal d, String target, String expectedStr) throws Exception {
    Function func = LANG_FACTORY.createFunction(target, Arrays.asList(c, d), String.class);
    OracleExecutionFactory trans = new OracleExecutionFactory();
    trans.start();
    SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
    sqlVisitor.append(func);
    assertEquals(expectedStr, sqlVisitor.toString());
}
Also used : Function(org.teiid.language.Function) SQLConversionVisitor(org.teiid.translator.jdbc.SQLConversionVisitor)

Example 9 with Function

use of org.teiid.language.Function in project teiid by teiid.

the class TestMonthOrDayNameFunctionModifier method helpTestMod.

public void helpTestMod(Literal c, String format, String expectedStr) throws Exception {
    Function func = // "monthname" //$NON-NLS-1$
    LANG_FACTORY.createFunction(// "monthname" //$NON-NLS-1$
    format.toLowerCase() + "name", Arrays.asList(c), String.class);
    OracleExecutionFactory trans = new OracleExecutionFactory();
    trans.start();
    SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
    sqlVisitor.append(func);
    assertEquals(expectedStr, sqlVisitor.toString());
}
Also used : Function(org.teiid.language.Function) SQLConversionVisitor(org.teiid.translator.jdbc.SQLConversionVisitor)

Example 10 with Function

use of org.teiid.language.Function in project teiid by teiid.

the class TestOracleConvertModifier method helpTest.

public void helpTest(Expression srcExpression, String tgtType, String expectedExpression) throws Exception {
    Function func = // $NON-NLS-1$
    LANG_FACTORY.createFunction(// $NON-NLS-1$
    "convert", Arrays.asList(srcExpression, LANG_FACTORY.createLiteral(tgtType, String.class)), TypeFacility.getDataTypeClass(tgtType));
    assertEquals(// $NON-NLS-1$ //$NON-NLS-2$
    "Error converting from " + srcExpression.getType() + " to " + tgtType, expectedExpression, helpGetString(func));
}
Also used : Function(org.teiid.language.Function)

Aggregations

Function (org.teiid.language.Function)173 Test (org.junit.Test)127 BigInteger (java.math.BigInteger)36 ArrayList (java.util.ArrayList)16 Literal (org.teiid.language.Literal)15 BigDecimal (java.math.BigDecimal)14 List (java.util.List)13 Expression (org.teiid.language.Expression)13 AliasModifier (org.teiid.translator.jdbc.AliasModifier)12 FunctionModifier (org.teiid.translator.jdbc.FunctionModifier)12 SQLConversionVisitor (org.teiid.translator.jdbc.SQLConversionVisitor)9 LinkedList (java.util.LinkedList)3 ColumnReference (org.teiid.language.ColumnReference)3 Comparison (org.teiid.language.Comparison)3 SearchedCase (org.teiid.language.SearchedCase)3 EscapeSyntaxModifier (org.teiid.translator.jdbc.EscapeSyntaxModifier)3 ModFunctionModifier (org.teiid.translator.jdbc.ModFunctionModifier)3 ConcatFunctionModifier (org.teiid.translator.jdbc.oracle.ConcatFunctionModifier)3 Timestamp (java.sql.Timestamp)2 AggregateFunction (org.teiid.language.AggregateFunction)2