Search in sources :

Example 11 with ExpressionSymbol

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);
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) ExpressionSymbol(org.teiid.query.sql.symbol.ExpressionSymbol)

Example 12 with ExpressionSymbol

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);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Function(org.teiid.query.sql.symbol.Function) FakeDataManager(org.teiid.query.processor.FakeDataManager) HashMap(java.util.HashMap) 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) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 13 with ExpressionSymbol

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);
}
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 14 with ExpressionSymbol

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));
}
Also used : AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) Constant(org.teiid.query.sql.symbol.Constant) ExpressionSymbol(org.teiid.query.sql.symbol.ExpressionSymbol) Test(org.junit.Test)

Example 15 with ExpressionSymbol

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());
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) ExpressionSymbol(org.teiid.query.sql.symbol.ExpressionSymbol)

Aggregations

ExpressionSymbol (org.teiid.query.sql.symbol.ExpressionSymbol)16 Constant (org.teiid.query.sql.symbol.Constant)10 Expression (org.teiid.query.sql.symbol.Expression)9 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Test (org.junit.Test)6 AliasSymbol (org.teiid.query.sql.symbol.AliasSymbol)5 Function (org.teiid.query.sql.symbol.Function)5 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)4 LinkedHashSet (java.util.LinkedHashSet)3 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)3 OrderBy (org.teiid.query.sql.lang.OrderBy)3 AggregateSymbol (org.teiid.query.sql.symbol.AggregateSymbol)3 Map (java.util.Map)2 WindowFunction (org.teiid.query.sql.symbol.WindowFunction)2 SymbolMap (org.teiid.query.sql.util.SymbolMap)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1