Search in sources :

Example 46 with Function

use of org.teiid.query.sql.symbol.Function in project teiid by teiid.

the class TestFunctionResolving method testResolveBadConvert.

@Test
public void testResolveBadConvert() throws Exception {
    // $NON-NLS-1$
    Function function = new Function("convert", new Expression[] { new Constant(new Character('a')), new Constant(DataTypeManager.DefaultDataTypes.DATE) });
    try {
        ResolverVisitor.resolveLanguageObject(function, RealMetadataFactory.example1Cached());
        // $NON-NLS-1$
        fail("excpetion expected");
    } catch (QueryResolverException err) {
        // $NON-NLS-1$
        assertEquals("TEIID30071 The conversion from char to date is not allowed.", err.getMessage());
    }
}
Also used : Function(org.teiid.query.sql.symbol.Function) Constant(org.teiid.query.sql.symbol.Constant) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) Test(org.junit.Test)

Example 47 with Function

use of org.teiid.query.sql.symbol.Function in project teiid by teiid.

the class TestStaticSymbolMappingVisitor method testExecParamFunction.

public void testExecParamFunction() {
    StoredProcedure exec = new StoredProcedure();
    // $NON-NLS-1$
    exec.setProcedureName("pm1.proc1");
    // $NON-NLS-1$
    exec.setProcedureID("proc");
    // $NON-NLS-1$
    Function f = new Function("length", new Expression[] { exampleElement(true, 1) });
    SPParameter param1 = new SPParameter(1, f);
    exec.setParameter(param1);
    // Run symbol mapper
    StaticSymbolMappingVisitor visitor = new StaticSymbolMappingVisitor(getSymbolMap());
    DeepPreOrderNavigator.doVisit(exec, visitor);
    // Check that element got switched
    Function afterFunc = (Function) param1.getExpression();
    // $NON-NLS-1$
    assertEquals("Stored proc param did not get mapped correctly: ", exampleElement(false, 1), afterFunc.getArg(0));
}
Also used : Function(org.teiid.query.sql.symbol.Function) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) SPParameter(org.teiid.query.sql.lang.SPParameter)

Example 48 with Function

use of org.teiid.query.sql.symbol.Function in project teiid by teiid.

the class TestStaticSymbolMappingVisitor method testExecParamNestedFunction.

public void testExecParamNestedFunction() {
    StoredProcedure exec = new StoredProcedure();
    // $NON-NLS-1$
    exec.setProcedureName("pm1.proc1");
    // $NON-NLS-1$
    exec.setProcedureID("proc");
    // $NON-NLS-1$
    Function f = new Function("length", new Expression[] { exampleElement(true, 1) });
    // $NON-NLS-1$
    Function f2 = new Function("+", new Expression[] { f, new Constant(new Integer(1)) });
    SPParameter param1 = new SPParameter(1, f2);
    exec.setParameter(param1);
    // Run symbol mapper
    StaticSymbolMappingVisitor visitor = new StaticSymbolMappingVisitor(getSymbolMap());
    DeepPreOrderNavigator.doVisit(exec, visitor);
    // Check that element got switched
    Function afterFunc = (Function) param1.getExpression();
    Function innerFunc = (Function) afterFunc.getArgs()[0];
    // $NON-NLS-1$
    assertEquals("Stored proc param did not get mapped correctly: ", exampleElement(false, 1), innerFunc.getArg(0));
}
Also used : Function(org.teiid.query.sql.symbol.Function) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Constant(org.teiid.query.sql.symbol.Constant) SPParameter(org.teiid.query.sql.lang.SPParameter)

Example 49 with Function

use of org.teiid.query.sql.symbol.Function in project teiid by teiid.

the class TestStaticSymbolMappingVisitor method testVisitSubquerySetCriteria.

public void testVisitSubquerySetCriteria() {
    SubquerySetCriteria ssc = new SubquerySetCriteria();
    // $NON-NLS-1$
    ssc.setExpression(new Function("length", new Expression[] { exampleElement(true, 0) }));
    ssc.setCommand(new Query());
    helpTest(ssc, getSymbolMap());
}
Also used : Function(org.teiid.query.sql.symbol.Function) Query(org.teiid.query.sql.lang.Query) Expression(org.teiid.query.sql.symbol.Expression) SubquerySetCriteria(org.teiid.query.sql.lang.SubquerySetCriteria)

Example 50 with Function

use of org.teiid.query.sql.symbol.Function in project teiid by teiid.

the class TestFunction method testFunction3.

public void testFunction3() {
    // $NON-NLS-1$ //$NON-NLS-2$
    Function f1 = new Function("f1", new Expression[] { new Constant("xyz") });
    // $NON-NLS-1$ //$NON-NLS-2$
    Function f2 = new Function("f2", new Expression[] { new Constant("xyz") });
    UnitTestUtil.helpTestEquivalence(1, f1, f2);
}
Also used : Function(org.teiid.query.sql.symbol.Function) Constant(org.teiid.query.sql.symbol.Constant)

Aggregations

Function (org.teiid.query.sql.symbol.Function)55 Constant (org.teiid.query.sql.symbol.Constant)31 Test (org.junit.Test)25 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)16 Expression (org.teiid.query.sql.symbol.Expression)12 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)11 ArrayList (java.util.ArrayList)10 List (java.util.List)7 ScalarSubquery (org.teiid.query.sql.symbol.ScalarSubquery)7 SearchedCaseExpression (org.teiid.query.sql.symbol.SearchedCaseExpression)6 HashMap (java.util.HashMap)5 ExpressionSymbol (org.teiid.query.sql.symbol.ExpressionSymbol)5 Map (java.util.Map)4 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)4 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)4 Reference (org.teiid.query.sql.symbol.Reference)4 FunctionLibrary (org.teiid.query.function.FunctionLibrary)3 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)3 FakeDataManager (org.teiid.query.processor.FakeDataManager)3 Query (org.teiid.query.sql.lang.Query)3