Search in sources :

Example 1 with Expression

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

the class AutoGenDataService method createResults.

public static List[] createResults(List symbols, int rowCount, boolean useIntCounter) {
    List[] rows = new List[rowCount];
    for (int i = 0; i < rowCount; i++) {
        List row = new ArrayList();
        Iterator iter = symbols.iterator();
        while (iter.hasNext()) {
            Expression symbol = (Expression) iter.next();
            Class type = symbol.getType();
            row.add(getValue(type, i, useIntCounter));
        }
        rows[i] = row;
    }
    return rows;
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Expression

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

the class ODataSQLBuilder method processOrderBy.

private OrderBy processOrderBy(OrderBy orderBy, List<OrderByItem> orderByItems, DocumentNode resource) throws TeiidException {
    for (OrderByItem obitem : orderByItems) {
        ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(resource, false, getUriInfo(), this.metadata, this.odata, this.nameGenerator, this.params, this.parseService);
        Expression expr = visitor.getExpression(obitem.getExpression());
        if (expr instanceof ElementSymbol) {
            orderBy.addVariable(expr, !obitem.isDescending());
        } else {
            AliasSymbol alias = new AliasSymbol("_orderByAlias", expr);
            orderBy.addVariable(alias, !obitem.isDescending());
            visitor.getEntityResource().addProjectedColumn(alias, EdmInt32.getInstance(), null, false);
        }
    }
    return orderBy;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) OrderByItem(org.apache.olingo.server.api.uri.queryoption.OrderByItem) AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) Expression(org.teiid.query.sql.symbol.Expression)

Example 3 with Expression

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

the class ODataSQLBuilder method visit.

@Override
public void visit(FilterOption info) {
    ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(this.context, this.prepared, getUriInfo(), this.metadata, this.odata, this.nameGenerator, this.params, this.parseService);
    Expression filter = null;
    try {
        filter = visitor.getExpression(info.getExpression());
    } catch (TeiidException e) {
        this.exceptions.add(e);
    }
    // Here Lambda operation may have joined a table and changed the context.
    this.context = visitor.getEntityResource();
    this.context.addCriteria(filter);
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) TeiidException(org.teiid.core.TeiidException)

Example 4 with Expression

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

the class ODataSQLBuilder method buildAggregateQuery.

private void buildAggregateQuery(DocumentNode node, Query outerQuery, ExpandDocumentNode expandResource, OrderBy expandOrder, Query query, EdmNavigationProperty navigationProperty) throws TeiidException {
    Select select = query.getSelect();
    Array array = new Array(Object.class, new ArrayList<Expression>(select.getSymbols()));
    select.getSymbols().clear();
    AggregateSymbol symbol = new AggregateSymbol(AggregateSymbol.Type.ARRAY_AGG.name(), false, array);
    select.addSymbol(symbol);
    symbol.setOrderBy(expandOrder);
    Criteria crit = node.buildJoinCriteria(expandResource, navigationProperty);
    if (crit != null) {
        query.setCriteria(Criteria.combineCriteria(crit, query.getCriteria()));
    }
    // else assertion error?
    expandResource.setColumnIndex(outerQuery.getSelect().getCount() + 1);
    ScalarSubquery agg = new ScalarSubquery(query);
    SubqueryHint subqueryHint = new SubqueryHint();
    subqueryHint.setMergeJoin(true);
    agg.setSubqueryHint(subqueryHint);
    outerQuery.getSelect().addSymbol(agg);
}
Also used : Array(org.teiid.query.sql.symbol.Array) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) Expression(org.teiid.query.sql.symbol.Expression) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint)

Example 5 with Expression

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

the class TestJoinOptimization method helpTestNullDependent.

private void helpTestNullDependent(String expressionSQL, boolean dependent) throws QueryParserException, QueryResolverException, QueryMetadataException, TeiidComponentException {
    List<GroupSymbol> innerGroups = new ArrayList<GroupSymbol>();
    // $NON-NLS-1$
    innerGroups.add(new GroupSymbol("pm1.g1"));
    Expression expr = QueryParser.getQueryParser().parseExpression(expressionSQL);
    ResolverVisitor.resolveLanguageObject(expr, RealMetadataFactory.example1Cached());
    assertEquals(dependent, JoinUtil.isNullDependent(RealMetadataFactory.example1Cached(), innerGroups, expr));
}
Also used : Expression(org.teiid.query.sql.symbol.Expression) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList)

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