Search in sources :

Example 56 with Expression

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

the class TestOrderByRewrite method helpCheckElements.

private void helpCheckElements(OrderBy langObj, String[] elementNames, String[] elementIDs) {
    List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
    for (Iterator<Expression> i = langObj.getSortKeys().iterator(); i.hasNext(); ) {
        ElementCollectorVisitor.getElements(i.next(), 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());
        Column elementID = (Column) symbol.getMetadataID();
        // $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(), elementID.getFullName().toUpperCase());
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Expression(org.teiid.query.sql.symbol.Expression) Column(org.teiid.metadata.Column) ArrayList(java.util.ArrayList)

Example 57 with Expression

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

the class TestProcedureResolving method testVarArgs2.

@Test
public void testVarArgs2() throws Exception {
    String ddl = "create foreign procedure proc (VARIADIC z object) returns (x string);\n";
    TransformationMetadata tm = createMetadata(ddl);
    // $NON-NLS-1$
    String sql = "call proc ()";
    StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals("EXEC proc()", sp.toString());
    assertEquals(new Array(DataTypeManager.DefaultDataClasses.OBJECT, new ArrayList<Expression>(0)), sp.getParameter(1).getExpression());
    // $NON-NLS-1$
    sql = "call proc (1, (2, 3))";
    sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals("EXEC proc(1, (2, 3))", sp.toString());
    ArrayList<Expression> expressions = new ArrayList<Expression>();
    expressions.add(new Constant(1));
    expressions.add(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))));
    assertEquals(new Array(DataTypeManager.DefaultDataClasses.OBJECT, expressions), sp.getParameter(1).getExpression());
}
Also used : Array(org.teiid.query.sql.symbol.Array) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 58 with Expression

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

the class SetQuery method getTypedProjectedSymbols.

public static List<Expression> getTypedProjectedSymbols(List<? extends Expression> acutal, List<Class<?>> projectedTypes, QueryMetadataInterface metadata) {
    List<Expression> newProject = new ArrayList<Expression>();
    for (int i = 0; i < acutal.size(); i++) {
        Expression originalSymbol = acutal.get(i);
        Expression symbol = originalSymbol;
        Class<?> type = projectedTypes.get(i);
        if (symbol.getType() != type) {
            symbol = SymbolMap.getExpression(originalSymbol);
            try {
                symbol = ResolverUtil.convertExpression(symbol, DataTypeManager.getDataTypeName(type), metadata);
            } catch (QueryResolverException err) {
                throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30447, err);
            }
            if (originalSymbol instanceof Symbol) {
                symbol = new AliasSymbol(Symbol.getShortName(originalSymbol), symbol);
            }
        }
        newProject.add(symbol);
    }
    return newProject;
}
Also used : AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) Expression(org.teiid.query.sql.symbol.Expression) AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) Symbol(org.teiid.query.sql.symbol.Symbol) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 59 with Expression

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

the class SubqueryCompareCriteria method clone.

/**
 * Deep copy of object.  The values Iterator of this object
 * will not be cloned - it will be null in the new object
 * (see #setValueIterator setValueIterator}).
 * @return Deep copy of object
 * @see java.lang.Object#clone()
 */
public Object clone() {
    Expression leftCopy = null;
    if (getLeftExpression() != null) {
        leftCopy = (Expression) getLeftExpression().clone();
    }
    QueryCommand copyCommand = null;
    if (getCommand() != null) {
        copyCommand = (QueryCommand) getCommand().clone();
    }
    SubqueryCompareCriteria copy = new SubqueryCompareCriteria(leftCopy, copyCommand, this.getOperator(), this.getPredicateQuantifier());
    if (this.subqueryHint != null) {
        copy.subqueryHint = this.subqueryHint.clone();
    }
    if (this.arrayExpression != null) {
        copy.arrayExpression = (Expression) this.arrayExpression.clone();
    }
    return copy;
}
Also used : Expression(org.teiid.query.sql.symbol.Expression)

Example 60 with Expression

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

the class Command method getUpdateCommandSymbol.

public static List<Expression> getUpdateCommandSymbol() {
    if (updateCommandSymbol == null) {
        // $NON-NLS-1$
        ElementSymbol symbol = new ElementSymbol("Count");
        symbol.setType(DataTypeManager.DefaultDataClasses.INTEGER);
        updateCommandSymbol = Arrays.asList((Expression) symbol);
    }
    return updateCommandSymbol;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Expression(org.teiid.query.sql.symbol.Expression)

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