use of org.teiid.query.sql.symbol.Function in project teiid by teiid.
the class TestProjectNode method testProjectWithLookupFunction.
@Test
public void testProjectWithLookupFunction() 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$ //$NON-NLS-3$ //$NON-NLS-4$
Function func = new Function("lookup", new Expression[] { new Constant("pm1.g1"), new Constant("e2"), new Constant("e1"), es1 });
// $NON-NLS-1$
FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, String.class });
func.setFunctionDescriptor(desc);
func.setType(DataTypeManager.DefaultDataClasses.STRING);
// $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[] { "2" }) };
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "a" }), // $NON-NLS-1$
Arrays.asList(new Object[] { "b" }) };
FakeDataManager dataMgr = new FakeDataManager();
dataMgr.setThrowBlocked(true);
Map valueMap = new HashMap();
// $NON-NLS-1$ //$NON-NLS-2$
valueMap.put("1", "a");
// $NON-NLS-1$ //$NON-NLS-2$
valueMap.put("2", "b");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dataMgr.defineCodeTable("pm1.g1", "e1", "e2", valueMap);
helpTestProject(projectElements, data, elements, expected, dataMgr);
}
use of org.teiid.query.sql.symbol.Function in project teiid by teiid.
the class TestProjectNode method testProjectExpression.
@Test
public void testProjectExpression() 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("concat", new Expression[] { es1, new Constant("abc") });
// $NON-NLS-1$
FunctionDescriptor fd = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("concat", new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING });
func.setFunctionDescriptor(fd);
func.setType(DataTypeManager.DefaultDataClasses.STRING);
// $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[] { "2" }) };
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "1abc" }), // $NON-NLS-1$
Arrays.asList(new Object[] { "2abc" }) };
helpTestProject(projectElements, data, elements, expected, null);
}
use of org.teiid.query.sql.symbol.Function in project teiid by teiid.
the class TestSelectNode method testSelectWithLookup.
@Test
public void testSelectWithLookup() throws TeiidComponentException, TeiidProcessingException {
// $NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("e1");
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
// $NON-NLS-1$
ElementSymbol es2 = new ElementSymbol("e2");
es2.setType(DataTypeManager.DefaultDataClasses.STRING);
List elements = new ArrayList();
elements.add(es1);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Function func = new Function("lookup", new Expression[] { new Constant("pm1.g1"), new Constant("e2"), new Constant("e1"), es1 });
// $NON-NLS-1$
FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, Integer.class });
func.setFunctionDescriptor(desc);
func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
CompareCriteria crit = new CompareCriteria(func, CompareCriteria.EQ, new Constant(new Integer(1)));
List[] data = new List[20];
for (int i = 0; i < 20; i++) {
data[i] = new ArrayList();
data[i].add(new Integer((i * 51) % 11));
// $NON-NLS-1$
String str = "" + (i * 3);
str = str.substring(0, 1);
data[i].add(str);
}
List childElements = new ArrayList();
childElements.add(es1);
childElements.add(es2);
List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(0) }), Arrays.asList(new Object[] { new Integer(0) }) };
FakeDataManager dataMgr = new FakeDataManager();
dataMgr.setThrowBlocked(true);
Map valueMap = new HashMap();
valueMap.put(new Integer(0), new Integer(1));
valueMap.put(new Integer(1), new Integer(2));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dataMgr.defineCodeTable("pm1.g1", "e1", "e2", valueMap);
helpTestSelect(elements, crit, data, childElements, dataMgr, expected);
}
use of org.teiid.query.sql.symbol.Function in project teiid by teiid.
the class TestFunctionResolving method testResolveAmbiguousFunction.
@Test
public void testResolveAmbiguousFunction() throws Exception {
// $NON-NLS-1$
Function function = new Function("LCASE", new Expression[] { new Reference(0) });
try {
ResolverVisitor.resolveLanguageObject(function, RealMetadataFactory.example1Cached());
// $NON-NLS-1$
fail("excpetion expected");
} catch (QueryResolverException err) {
// $NON-NLS-1$
assertEquals("TEIID30069 The function 'LCASE(?)' has more than one possible signature.", err.getMessage());
}
}
use of org.teiid.query.sql.symbol.Function in project teiid by teiid.
the class TestFunctionResolving method testImportedPushdown.
@Test
public void testImportedPushdown() throws Exception {
RealMetadataFactory.example1Cached();
QueryMetadataInterface tm = RealMetadataFactory.fromDDL("x", new DDLHolder("y", "create foreign function func(x object) returns object;"), new DDLHolder("z", "create foreign function func(x object) returns object;"));
String sql = "func('a')";
Function func = (Function) QueryParser.getQueryParser().parseExpression(sql);
try {
ResolverVisitor.resolveLanguageObject(func, tm);
fail("should be ambiguous");
} catch (QueryResolverException e) {
}
tm = RealMetadataFactory.fromDDL("x", new DDLHolder("y", "create foreign function func(x object) returns object options (\"teiid_rel:system-name\" 'f');"), new DDLHolder("z", "create foreign function func(x object) returns object options (\"teiid_rel:system-name\" 'f');"));
func = (Function) QueryParser.getQueryParser().parseExpression(sql);
ResolverVisitor.resolveLanguageObject(func, tm);
tm = RealMetadataFactory.fromDDL("x", new DDLHolder("y", "create foreign function func() returns object options (\"teiid_rel:system-name\" 'f');"), new DDLHolder("z", "create foreign function func() returns object options (\"teiid_rel:system-name\" 'f');"));
func = (Function) QueryParser.getQueryParser().parseExpression("func()");
ResolverVisitor.resolveLanguageObject(func, tm);
}
Aggregations