Search in sources :

Example 81 with ElementSymbol

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

the class TestResolver method testStringConversion2.

@Test
public void testStringConversion2() {
    // 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(conversion);
    expected.setOperator(CompareCriteria.EQ);
    expected.setRightExpression(e1);
    // Resolve the query and check against expected objects
    // $NON-NLS-1$
    CompareCriteria actual = (CompareCriteria) helpResolveCriteria("'2003-02-27'=pm3.g1.e2");
    // if (! actual.getLeftExpression().equals(expected.getLeftExpression())) {
    // fail("Left expressions not equal");
    // } else if (!actual.getRightExpression().equals(expected.getRightExpression())) {
    // fail("Right expressions not equal");
    // }
    // $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 82 with ElementSymbol

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

the class TestResolver method test11716.

@Test
public void test11716() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT e1 FROM pm1.g1 where e1='1'";
    Map externalMetadata = new HashMap();
    // $NON-NLS-1$
    GroupSymbol inputSet = new GroupSymbol("INPUT");
    List inputSetElements = new ArrayList();
    // $NON-NLS-1$
    ElementSymbol inputSetElement = new ElementSymbol("INPUT.e1");
    inputSetElements.add(inputSetElement);
    externalMetadata.put(inputSet, inputSetElements);
    Query command = (Query) helpParse(sql);
    QueryResolver.resolveCommand(command, metadata);
    Collection groups = GroupCollectorVisitor.getGroups(command, false);
    assertFalse(groups.contains(inputSet));
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) XMLQuery(org.teiid.query.sql.symbol.XMLQuery) HashMap(java.util.HashMap) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) SymbolMap(org.teiid.query.sql.util.SymbolMap) Test(org.junit.Test)

Example 83 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol 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 84 with ElementSymbol

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

the class TestResolver method helpCheckElements.

private void helpCheckElements(LanguageObject langObj, String[] elementNames, String[] elementIDs) {
    List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
    ElementCollectorVisitor.getElements(langObj, elements);
    // $NON-NLS-1$
    assertEquals("Wrong number of elements: ", elementNames.length, elements.size());
    for (int i = 0; i < elements.size(); i++) {
        ElementSymbol symbol = elements.get(i);
        // $NON-NLS-1$
        assertEquals("Element name does not match: ", elementNames[i].toUpperCase(), symbol.getName().toUpperCase());
        Object elementID = symbol.getMetadataID();
        try {
            String name = metadata.getFullName(elementID);
            // $NON-NLS-1$ //$NON-NLS-2$
            assertNotNull("ElementSymbol " + symbol + " was not resolved and has no metadataID", elementID);
            // $NON-NLS-1$
            assertEquals("ElementID name does not match: ", elementIDs[i].toUpperCase(), name.toUpperCase());
        } catch (TeiidComponentException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ArrayList(java.util.ArrayList) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 85 with ElementSymbol

use of org.teiid.query.sql.symbol.ElementSymbol 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)

Aggregations

ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)417 ArrayList (java.util.ArrayList)165 Test (org.junit.Test)157 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)148 Expression (org.teiid.query.sql.symbol.Expression)104 List (java.util.List)103 Constant (org.teiid.query.sql.symbol.Constant)94 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)41 SymbolMap (org.teiid.query.sql.util.SymbolMap)40 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)36 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)29 Map (java.util.Map)28 AggregateSymbol (org.teiid.query.sql.symbol.AggregateSymbol)28 Query (org.teiid.query.sql.lang.Query)26 HashMap (java.util.HashMap)25 Select (org.teiid.query.sql.lang.Select)24 BufferManager (org.teiid.common.buffer.BufferManager)22 Criteria (org.teiid.query.sql.lang.Criteria)22 LinkedList (java.util.LinkedList)20 TupleBuffer (org.teiid.common.buffer.TupleBuffer)19