Search in sources :

Example 76 with Function

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

the class TestSybaseIQConvertModifier method testIntegerToShort.

@Test
public void testIntegerToShort() throws Exception {
    Function func = // $NON-NLS-1$
    LANG_FACTORY.createFunction(// $NON-NLS-1$
    "convert", new Expression[] { LANG_FACTORY.createLiteral(new Integer(1232321), Integer.class), // $NON-NLS-1$
    LANG_FACTORY.createLiteral("short", Short.class) }, Short.class);
    // $NON-NLS-1$
    helpGetString1(func, "cast(1232321 AS smallint)");
}
Also used : BigInteger(java.math.BigInteger) Function(org.teiid.language.Function) Test(org.junit.Test)

Example 77 with Function

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

the class TestTeradataTranslator method helpTest.

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

Example 78 with Function

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

the class TestPathFunctionModifier method helpTestMod.

public void helpTestMod(Expression c, String expectedStr, String target) throws Exception {
    Function func = null;
    if (c != null) {
        func = LANG_FACTORY.createFunction(target, Arrays.asList(c), String.class);
    } else {
        func = LANG_FACTORY.createFunction(target, Collections.EMPTY_LIST, String.class);
    }
    ModeShapeExecutionFactory trans = new ModeShapeExecutionFactory();
    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 79 with Function

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

the class TestLog10FunctionModifier method testModifier.

public void testModifier() {
    Literal arg = LANG_FACTORY.createLiteral(new Double(5.2), Double.class);
    // $NON-NLS-1$
    Function func = LANG_FACTORY.createFunction("log10", Arrays.asList(arg), Double.class);
    Log10FunctionModifier modifier = new Log10FunctionModifier(LANG_FACTORY);
    modifier.translate(func);
    // $NON-NLS-1$
    assertEquals("log", func.getName());
    assertEquals(Double.class, func.getType());
    List<Expression> outArgs = func.getParameters();
    assertEquals(2, outArgs.size());
    assertEquals(arg, outArgs.get(1));
    assertTrue(outArgs.get(1) instanceof Literal);
    Literal newArg = (Literal) outArgs.get(0);
    assertEquals(Integer.class, newArg.getType());
    assertEquals(new Integer(10), newArg.getValue());
    // $NON-NLS-1$
    assertEquals("log(10, 5.2)", SQLStringVisitor.getSQLString(func));
}
Also used : Function(org.teiid.language.Function) Log10FunctionModifier(org.teiid.translator.jdbc.hana.Log10FunctionModifier) Expression(org.teiid.language.Expression) Literal(org.teiid.language.Literal)

Example 80 with Function

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

the class PIExecutionFactory method start.

@Override
public void start() throws TranslatorException {
    super.start();
    // $NON-NLS-1$
    convert.addTypeMapping("Int8", FunctionModifier.BYTE);
    // $NON-NLS-1$
    convert.addTypeMapping("Int16", FunctionModifier.SHORT);
    // $NON-NLS-1$
    convert.addTypeMapping("Int32", FunctionModifier.INTEGER);
    // $NON-NLS-1$
    convert.addTypeMapping("Int64", FunctionModifier.LONG);
    // $NON-NLS-1$
    convert.addTypeMapping("Single", FunctionModifier.FLOAT);
    // $NON-NLS-1$
    convert.addTypeMapping("Double", FunctionModifier.DOUBLE);
    // $NON-NLS-1$
    convert.addTypeMapping("Boolean", FunctionModifier.BOOLEAN);
    // $NON-NLS-1$
    convert.addTypeMapping("String", FunctionModifier.STRING);
    // $NON-NLS-1$
    convert.addTypeMapping("DateTime", FunctionModifier.TIMESTAMP);
    // $NON-NLS-1$
    convert.addTypeMapping("Time", FunctionModifier.TIME);
    // $NON-NLS-1$
    convert.addTypeMapping("Variant", FunctionModifier.OBJECT);
    convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Arrays.asList("cast(format(", function.getParameters().get(0), ", 'hh:mm:ss.fff') as Time)");
        }
    });
    convert.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.FLOAT, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Arrays.asList("cast(cast(", function.getParameters().get(0), " as int8) as single)");
        }
    });
    convert.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.DOUBLE, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Arrays.asList("cast(cast(", function.getParameters().get(0), " as int8) as double)");
        }
    });
    registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
    registerFunctionModifier(SourceSystemFunctions.MOD, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            return // $NON-NLS-1$ //$NON-NLS-2$
            Arrays.asList(// $NON-NLS-1$ //$NON-NLS-2$
            "cast(", // $NON-NLS-1$ //$NON-NLS-2$
            function.getParameters().get(0), // $NON-NLS-1$ //$NON-NLS-2$
            " as int64)", // $NON-NLS-1$ //$NON-NLS-2$
            "%", "cast(", function.getParameters().get(1), " as int64)");
        }
    });
    // $NON-NLS-1$
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new AliasModifier("DAY"));
    registerFunctionModifier(SourceSystemFunctions.LOCATE, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            if (function.getParameters().size() <= 2) {
                return Arrays.asList("INSTR(", function.getParameters().get(1), ",", function.getParameters().get(0), ")");
            }
            return Arrays.asList("INSTR(", function.getParameters().get(1), ",", function.getParameters().get(0), ",", function.getParameters().get(2), ")");
        }
    });
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("LOWER"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("UPPER"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("SUBSTR"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LENGTH, new AliasModifier("LEN"));
    // $NON-NLS-1$
    addPushDownFunction(PI, "COSH", FLOAT, FLOAT);
    // $NON-NLS-1$
    addPushDownFunction(PI, "TANH", FLOAT, FLOAT);
    // $NON-NLS-1$
    addPushDownFunction(PI, "SINH", FLOAT, FLOAT);
    // $NON-NLS-1$
    addPushDownFunction(PI, "FORMAT", STRING, FLOAT, STRING);
    // $NON-NLS-1$
    addPushDownFunction(PI, "FORMAT", STRING, INTEGER, STRING);
    // $NON-NLS-1$
    addPushDownFunction(PI, "ParentName", STRING, STRING, INTEGER);
    // $NON-NLS-1$
    addPushDownFunction(PI, "List", STRING, STRING).setVarArgs(true);
    // $NON-NLS-1$
    addPushDownFunction(PI, "DIGCODE", INTEGER, STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(PI, "DIGSTRING", STRING, INTEGER);
    // $NON-NLS-1$
    addPushDownFunction(PI, "PE", STRING, OBJECT);
    // $NON-NLS-1$
    addPushDownFunction(PI, "ParentName", STRING, STRING, INTEGER);
    // $NON-NLS-1$
    addPushDownFunction(PI, "VarType", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(PI, "UOMID", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(PI, "UOMName", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(PI, "UOMAbbreviation", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(PI, "UOMClassName", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(PI, "UOMCanonicallD", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(PI, "UOMConvert", DOUBLE, DOUBLE, STRING, STRING);
    // $NON-NLS-1$
    FunctionMethod f = addPushDownFunction(PI, "interval", TIMESTAMP, STRING);
    // $NON-NLS-1$
    f.setProperty(SQLConversionVisitor.TEIID_NATIVE_QUERY, "$1");
}
Also used : Function(org.teiid.language.Function) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) AliasModifier(org.teiid.translator.jdbc.AliasModifier) FunctionMethod(org.teiid.metadata.FunctionMethod) ArrayList(java.util.ArrayList) List(java.util.List)

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