use of org.teiid.query.sql.symbol.ExpressionSymbol in project teiid by teiid.
the class TestOrderByRewrite method helpCheckExpressionsSymbols.
private void helpCheckExpressionsSymbols(OrderBy langObj, String[] functionsNames) {
int expCount = 0;
for (Iterator<Expression> i = langObj.getSortKeys().iterator(); i.hasNext(); ) {
Expression ses = i.next();
if (ses instanceof ExpressionSymbol) {
// $NON-NLS-1$
assertEquals("Expression Symbols does not match: ", functionsNames[expCount++], ses.toString());
}
}
// $NON-NLS-1$
assertEquals("Wrong number of Symbols: ", functionsNames.length, expCount);
}
use of org.teiid.query.sql.symbol.ExpressionSymbol 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.ExpressionSymbol 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.ExpressionSymbol in project teiid by teiid.
the class TestAliasSymbol method testAliasEquals.
@Test
public void testAliasEquals() {
// $NON-NLS-1$ //$NON-NLS-2$
AliasSymbol a1 = new AliasSymbol("X", new ExpressionSymbol("x", new Constant(1)));
// $NON-NLS-1$ //$NON-NLS-2$
AliasSymbol a2 = new AliasSymbol("X", new ExpressionSymbol("x", new Constant(2)));
// $NON-NLS-1$ //$NON-NLS-2$
AliasSymbol a3 = new AliasSymbol("x", new ExpressionSymbol("x", new Constant(1)));
// just a different case for the alias
assertFalse(a1.equals(a3));
// different express
assertFalse(a1.equals(a2));
}
use of org.teiid.query.sql.symbol.ExpressionSymbol in project teiid by teiid.
the class TestExpressionSymbol method testExpressionHashCode1.
public void testExpressionHashCode1() {
Expression expr1 = new Constant(new Integer(1));
Expression expr2 = new Constant(new Integer(1));
// $NON-NLS-1$
ExpressionSymbol symbol1 = new ExpressionSymbol("foo", expr1);
// $NON-NLS-1$
ExpressionSymbol symbol2 = new ExpressionSymbol("bar", expr2);
assertTrue(symbol1.hashCode() == symbol2.hashCode());
}
Aggregations