Search in sources :

Example 21 with Function

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

the class TestFunctionResolving method testLookupTypeConversion.

/**
 * e1 is of type string, so 1 should be converted to string
 * @throws Exception
 */
@Test
public void testLookupTypeConversion() throws Exception {
    // $NON-NLS-1$
    String sql = "lookup('pm1.g1', 'e2', 'e1', 1)";
    Function f = (Function) getExpression(sql);
    assertEquals(DataTypeManager.DefaultDataClasses.STRING, f.getArg(3).getType());
}
Also used : Function(org.teiid.query.sql.symbol.Function) Test(org.junit.Test)

Example 22 with Function

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

the class TestFunctionResolving method testNumericConversion.

/**
 * e1 is of type string, so 1 should be converted to string
 * @throws Exception
 */
@Test
public void testNumericConversion() throws Exception {
    // $NON-NLS-1$
    String sql = "1.0/2";
    Function f = (Function) getExpression(sql);
    assertEquals(DataTypeManager.DefaultDataClasses.BIG_DECIMAL, f.getType());
}
Also used : Function(org.teiid.query.sql.symbol.Function) Test(org.junit.Test)

Example 23 with Function

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

the class TestFunctionResolving method testResolveConvertReference.

@Test
public void testResolveConvertReference() throws Exception {
    // $NON-NLS-1$
    Function function = new Function("convert", new Expression[] { new Reference(0), new Constant(DataTypeManager.DefaultDataTypes.BOOLEAN) });
    ResolverVisitor.resolveLanguageObject(function, RealMetadataFactory.example1Cached());
    assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getType());
    assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getArgs()[0].getType());
}
Also used : Function(org.teiid.query.sql.symbol.Function) Reference(org.teiid.query.sql.symbol.Reference) Constant(org.teiid.query.sql.symbol.Constant) Test(org.junit.Test)

Example 24 with Function

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

the class TestFunctionResolving method testUDFResolveOrder.

@Test
public void testUDFResolveOrder() throws Exception {
    QueryMetadataInterface tm = RealMetadataFactory.fromDDL("create foreign function func(x object) returns object; " + " create foreign function func(x string) returns string;" + " create foreign function func1(x object) returns double;" + " create foreign function func1(x string[]) returns bigdecimal;", "x", "y");
    String sql = "func('a')";
    Function func = (Function) QueryParser.getQueryParser().parseExpression(sql);
    ResolverVisitor.resolveLanguageObject(func, tm);
    assertEquals(DataTypeManager.DefaultDataClasses.STRING, func.getArgs()[0].getType());
    assertEquals(DataTypeManager.DefaultDataClasses.STRING, func.getType());
    sql = "func1(('1',))";
    func = (Function) QueryParser.getQueryParser().parseExpression(sql);
    ResolverVisitor.resolveLanguageObject(func, tm);
}
Also used : Function(org.teiid.query.sql.symbol.Function) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 25 with Function

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

the class TestFunctionResolving method helpResolveFunction.

private Function helpResolveFunction(String sql) throws QueryParserException, QueryResolverException, TeiidComponentException {
    Function func = (Function) getExpression(sql);
    assertEquals(DataTypeManager.DefaultDataClasses.STRING, func.getType());
    return func;
}
Also used : Function(org.teiid.query.sql.symbol.Function)

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