Search in sources :

Example 51 with Expression

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

the class TestResolver method helpCheckSelect.

private void helpCheckSelect(Query query, String[] elementNames) {
    Select select = query.getSelect();
    List<Expression> elements = select.getProjectedSymbols();
    // $NON-NLS-1$
    assertEquals("Wrong number of select symbols: ", elementNames.length, elements.size());
    for (int i = 0; i < elements.size(); i++) {
        Expression symbol = elements.get(i);
        String name = Symbol.getShortName(symbol);
        if (symbol instanceof ElementSymbol) {
            name = ((ElementSymbol) symbol).getName();
        }
        // $NON-NLS-1$
        assertEquals("Element name does not match: ", elementNames[i].toUpperCase(), name.toString().toUpperCase());
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Expression(org.teiid.query.sql.symbol.Expression)

Example 52 with Expression

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

the class TestResolver method testStringConversion1.

@Test
public void testStringConversion1() {
    // Expected left expression
    // $NON-NLS-1$
    ElementSymbol e1 = new ElementSymbol("pm3.g1.e2");
    e1.setType(DataTypeManager.DefaultDataClasses.DATE);
    // Expected right expression
    Class srcType = DataTypeManager.DefaultDataClasses.STRING;
    String tgtTypeName = DataTypeManager.DefaultDataTypes.DATE;
    // $NON-NLS-1$
    Expression expression = new Constant("2003-02-27");
    FunctionLibrary library = RealMetadataFactory.SFM.getSystemFunctionLibrary();
    FunctionDescriptor fd = library.findFunction(FunctionLibrary.CONVERT, new Class[] { srcType, DataTypeManager.DefaultDataClasses.STRING });
    Function conversion = new Function(fd.getName(), new Expression[] { expression, new Constant(tgtTypeName) });
    conversion.setType(DataTypeManager.getDataTypeClass(tgtTypeName));
    conversion.setFunctionDescriptor(fd);
    conversion.makeImplicit();
    // Expected criteria
    CompareCriteria expected = new CompareCriteria();
    expected.setLeftExpression(e1);
    expected.setOperator(CompareCriteria.EQ);
    expected.setRightExpression(conversion);
    // Resolve the query and check against expected objects
    // $NON-NLS-1$
    CompareCriteria actual = (CompareCriteria) helpResolveCriteria("pm3.g1.e2='2003-02-27'");
    // $NON-NLS-1$
    assertEquals("Did not match expected criteria", expected, actual);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Function(org.teiid.query.sql.symbol.Function) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) FunctionLibrary(org.teiid.query.function.FunctionLibrary) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) Test(org.junit.Test)

Example 53 with Expression

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

the class TestResolver method testUpdateSetClauseReferenceType.

@Test
public void testUpdateSetClauseReferenceType() {
    // $NON-NLS-1$
    String sql = "UPDATE pm1.g1 SET pm1.g1.e1 = 1, pm1.g1.e2 = ?;";
    Update update = (Update) helpResolve(sql, RealMetadataFactory.example1Cached());
    Expression ref = update.getChangeList().getClauses().get(1).getValue();
    assertTrue(ref instanceof Reference);
    assertNotNull(ref.getType());
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) Reference(org.teiid.query.sql.symbol.Reference) Test(org.junit.Test)

Example 54 with Expression

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

the class TestResolver method testNullConstantInSelect.

@Test
public void testNullConstantInSelect() throws Exception {
    // $NON-NLS-1$
    String userSql = "SELECT null as x";
    Query query = (Query) helpParse(userSql);
    QueryResolver.resolveCommand(query, RealMetadataFactory.exampleBQTCached());
    // Check type of resolved null constant
    Expression symbol = query.getSelect().getSymbols().get(0);
    assertNotNull(symbol.getType());
    assertEquals(DataTypeManager.DefaultDataClasses.STRING, symbol.getType());
}
Also used : XMLQuery(org.teiid.query.sql.symbol.XMLQuery) Expression(org.teiid.query.sql.symbol.Expression) Test(org.junit.Test)

Example 55 with Expression

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

the class TestResolver method testExecProjectedSymbols.

@Test
public void testExecProjectedSymbols() {
    // $NON-NLS-1$
    String query = "exec pm1.sq1()";
    StoredProcedure proc = (StoredProcedure) helpResolve(query);
    List<Expression> projected = proc.getProjectedSymbols();
    assertEquals(2, projected.size());
    for (Iterator<Expression> i = projected.iterator(); i.hasNext(); ) {
        ElementSymbol symbol = (ElementSymbol) i.next();
        assertNotNull(symbol.getGroupSymbol());
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Expression(org.teiid.query.sql.symbol.Expression) Test(org.junit.Test)

Aggregations

Expression (org.teiid.query.sql.symbol.Expression)257 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)104 ArrayList (java.util.ArrayList)74 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)54 Test (org.junit.Test)53 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)50 List (java.util.List)49 Constant (org.teiid.query.sql.symbol.Constant)38 SymbolMap (org.teiid.query.sql.util.SymbolMap)37 HashMap (java.util.HashMap)22 LinkedList (java.util.LinkedList)22 Criteria (org.teiid.query.sql.lang.Criteria)22 Map (java.util.Map)21 ClobType (org.teiid.core.types.ClobType)16 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)16 HashSet (java.util.HashSet)13 LinkedHashSet (java.util.LinkedHashSet)13 AliasSymbol (org.teiid.query.sql.symbol.AliasSymbol)13 SearchedCaseExpression (org.teiid.query.sql.symbol.SearchedCaseExpression)13 OrderBy (org.teiid.query.sql.lang.OrderBy)12