Search in sources :

Example 26 with Function

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

the class TestProjectNode method testProjectExpressionFunctionFails.

@Test
public void testProjectExpressionFunctionFails() throws Exception {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.STRING);
    List elements = new ArrayList();
    elements.add(es1);
    // $NON-NLS-1$ //$NON-NLS-2$
    Function func = new Function("convert", new Expression[] { es1, new Constant("integer") });
    // $NON-NLS-1$
    FunctionDescriptor fd = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("convert", new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING });
    func.setFunctionDescriptor(fd);
    func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ExpressionSymbol expr = new ExpressionSymbol("expr", func);
    List projectElements = new ArrayList();
    projectElements.add(expr);
    List[] data = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "1" }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "2x" }) };
    // $NON-NLS-1$
    String expectedMessage = "TEIID30328 UNABLE TO EVALUATE CONVERT(E1, INTEGER): TEIID30384 ERROR WHILE EVALUATING FUNCTION CONVERT";
    helpTestProjectFails(projectElements, data, elements, expectedMessage);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Function(org.teiid.query.sql.symbol.Function) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) ExpressionSymbol(org.teiid.query.sql.symbol.ExpressionSymbol) Test(org.junit.Test)

Example 27 with Function

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

the class TestOptionsAndHints method testDepOptions2.

@Test
public void testDepOptions2() {
    // $NON-NLS-1$
    GroupSymbol a = new GroupSymbol("a");
    // $NON-NLS-1$
    GroupSymbol b = new GroupSymbol("b");
    // $NON-NLS-1$
    ElementSymbol x = new ElementSymbol("a.x", true);
    // $NON-NLS-1$
    ElementSymbol y = new ElementSymbol("b.y", true);
    // $NON-NLS-1$
    Criteria criteria = new CompareCriteria(x, CompareCriteria.EQ, new Function("func", new Expression[] { y }));
    JoinPredicate predicate = new JoinPredicate(new UnaryFromClause(a), new UnaryFromClause(b), JoinType.JOIN_INNER, Arrays.asList(new Object[] { criteria }));
    From from = new From(Arrays.asList(predicate));
    predicate.getLeftClause().setMakeNotDep(true);
    predicate.getRightClause().setMakeDep(true);
    Select select = new Select(Arrays.asList(x, y));
    Query query = new Query(select, from, null, null, null, null, null);
    // $NON-NLS-1$
    TestParser.helpTest(// $NON-NLS-1$
    "Select a.x, b.y From a MAKENOTDEP INNER JOIN b MAKEDEP ON a.x = func(b.y)", // $NON-NLS-1$
    "SELECT a.x, b.y FROM /*+ MAKENOTDEP */ a INNER JOIN /*+ MAKEDEP */ b ON a.x = func(b.y)", query);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) Function(org.teiid.query.sql.symbol.Function) Expression(org.teiid.query.sql.symbol.Expression) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Test(org.junit.Test)

Example 28 with Function

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

the class TestCapabilitiesUtil method testSupportsFunctionInGroupBy.

/**
 * Supports functions in group by is misleading.  It should actually
 * be called supports expression in group by.  Thus the example below
 * is not supported.
 */
@Test
public void testSupportsFunctionInGroupBy() throws Exception {
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Function f = new Function("concat", new Expression[] { new Constant("a"), new Constant("b") });
    // $NON-NLS-1$
    ExpressionSymbol expr = new ExpressionSymbol("e", f);
    List cols = new ArrayList();
    cols.add(expr);
    helpTestSupportsAggregates(false, false, cols);
}
Also used : Function(org.teiid.query.sql.symbol.Function) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ExpressionSymbol(org.teiid.query.sql.symbol.ExpressionSymbol) Test(org.junit.Test)

Example 29 with Function

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

the class TestCapabilitiesUtil method testSupportsScalar3.

// Test where capabilities doesn't support function
@Test
public void testSupportsScalar3() throws Exception {
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    // $NON-NLS-1$
    caps.setFunctionSupport("now", false);
    // $NON-NLS-1$
    Function func = new Function("NOW", new Expression[] {});
    helpTestSupportsScalar(caps, func, false);
}
Also used : Function(org.teiid.query.sql.symbol.Function) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Test(org.junit.Test)

Example 30 with Function

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

the class TestCapabilitiesUtil method testSupportsScalar4.

// Test where capabilities do support function
@Test
public void testSupportsScalar4() throws Exception {
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    // $NON-NLS-1$
    caps.setFunctionSupport("now", true);
    // $NON-NLS-1$
    Function func = new Function("NOW", new Expression[] {});
    helpTestSupportsScalar(caps, func, true);
}
Also used : Function(org.teiid.query.sql.symbol.Function) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Test(org.junit.Test)

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