Package org.teiid.query.sql.lang

Examples of org.teiid.query.sql.lang.Select


    private SetQuery exampleSetQuery(Operation op) {
        GroupSymbol g = new GroupSymbol("g"); //$NON-NLS-1$
        From from = new From();
        from.addGroup(g);

        Select select = new Select();
        select.addSymbol(new ElementSymbol("a")); //$NON-NLS-1$
       
        Query query1 = new Query();
        query1.setSelect(select);
        query1.setFrom(from);
       
        g = new GroupSymbol("h"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("b")); //$NON-NLS-1$
       
        Query query2 = new Query();
        query2.setSelect(select);
        query2.setFrom(from);
       
View Full Code Here


    public void testUnionAll(){
        GroupSymbol g = new GroupSymbol("g"); //$NON-NLS-1$
        From from = new From();
        from.addGroup(g);

        Select select = new Select();
        select.addSymbol(new ElementSymbol("a")); //$NON-NLS-1$
       
        Query query1 = new Query();
        query1.setSelect(select);
        query1.setFrom(from);
       
        g = new GroupSymbol("h"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("b")); //$NON-NLS-1$
       
        Query query2 = new Query();
        query2.setSelect(select);
        query2.setFrom(from);
       
View Full Code Here

        setQuery.setAll(false);
        GroupSymbol g = new GroupSymbol("g1"); //$NON-NLS-1$
        From from = new From();
        from.addGroup(g);

        Select select = new Select();
        select.addSymbol(new ElementSymbol("c1")); //$NON-NLS-1$
       
        Query query = new Query();
        query.setSelect(select);
        query.setFrom(from);

        setQuery.setLeftQuery(query);
       
        g = new GroupSymbol("g2"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("c2")); //$NON-NLS-1$
       
        query = new Query();
        query.setSelect(select);
        query.setFrom(from);
       
        setQuery.setRightQuery(query);

        g = new GroupSymbol("g3"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("c3")); //$NON-NLS-1$
       
        query = new Query();
        query.setSelect(select);
        query.setFrom(from);
       
View Full Code Here

        setQuery.setAll(false);
        GroupSymbol g = new GroupSymbol("g1"); //$NON-NLS-1$
        From from = new From();
        from.addGroup(g);

        Select select = new Select();
        select.addSymbol(new ElementSymbol("c1")); //$NON-NLS-1$
       
        Query query = new Query();
        query.setSelect(select);
        query.setFrom(from);

        setQuery.setLeftQuery(query);
       
        g = new GroupSymbol("g2"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("c2")); //$NON-NLS-1$
       
        query = new Query();
        query.setSelect(select);
        query.setFrom(from);
       
        setQuery.setRightQuery(query);

        g = new GroupSymbol("g3"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("c3")); //$NON-NLS-1$
       
        query = new Query();
        query.setSelect(select);
        query.setFrom(from);
       
        setQuery = new SetQuery(SetQuery.Operation.UNION, true, setQuery, query);

        g = new GroupSymbol("g4"); //$NON-NLS-1$
        from = new From();
        from.addGroup(g);

        select = new Select();
        select.addSymbol(new ElementSymbol("c4")); //$NON-NLS-1$
       
        query = new Query();
        query.setSelect(select);
        query.setFrom(from);
       
View Full Code Here

            hasExpression = iterator.next() instanceof ExpressionSymbol;
        }
        if (!hasExpression) {
          return query;
        }
        Select select = query.getSelect();
        GroupBy groupBy = query.getGroupBy();
        query.setGroupBy(null);
        Criteria having = query.getHaving();
        query.setHaving(null);
        OrderBy orderBy = query.getOrderBy();
        query.setOrderBy(null);
        Limit limit = query.getLimit();
        query.setLimit(null);
        Into into = query.getInto();
        query.setInto(null);
        Set<Expression> newSelectColumns = new HashSet<Expression>();
        for (final Iterator iterator = groupBy.getSymbols().iterator(); iterator.hasNext();) {
            newSelectColumns.add(SymbolMap.getExpression((SingleElementSymbol)iterator.next()));
        }
        Set<AggregateSymbol> aggs = new HashSet<AggregateSymbol>();
        aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(select, true));
        if (having != null) {
            aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(having, true));
        }
        for (AggregateSymbol aggregateSymbol : aggs) {
            if (aggregateSymbol.getExpression() != null) {
                Expression expr = aggregateSymbol.getExpression();
                newSelectColumns.add(SymbolMap.getExpression(expr));
            }
        }
        Select innerSelect = new Select();
        int index = 0;
        for (Expression expr : newSelectColumns) {
            if (expr instanceof SingleElementSymbol) {
                innerSelect.addSymbol((SingleElementSymbol)expr);
            } else {
                innerSelect.addSymbol(new ExpressionSymbol("EXPR" + index++ , expr)); //$NON-NLS-1$
            }
        }
        query.setSelect(innerSelect);
        Query outerQuery = null;
        try {
View Full Code Here

    public QueryCommand rewriteOrderBy(QueryCommand queryCommand) throws TeiidComponentException {
      final OrderBy orderBy = queryCommand.getOrderBy();
        if (orderBy == null) {
            return queryCommand;
        }
        Select select = queryCommand.getProjectedQuery().getSelect();
        final List<SingleElementSymbol> projectedSymbols = select.getProjectedSymbols();
       
        LinkedList<OrderByItem> unrelatedItems = new LinkedList<OrderByItem>();
       
        boolean hasUnrelatedExpression = rewriteOrderBy(queryCommand, orderBy,
        projectedSymbols, unrelatedItems);
       
        if (orderBy.getVariableCount() == 0 || !hasUnrelatedExpression) {
          return queryCommand;
        }
       
        int originalSymbolCount = select.getProjectedSymbols().size();

        //add unrelated to select
        for (OrderByItem orderByItem : unrelatedItems) {
            select.addSymbol(orderByItem.getSymbol());       
    }
        makeSelectUnique(select, false);
       
        Query query = queryCommand.getProjectedQuery();
       
        Into into = query.getInto();
        query.setInto(null);
        Limit limit = query.getLimit();
        query.setLimit(null);
        query.setOrderBy(null);
       
        Query top = null;
       
        try {
          top = createInlineViewQuery(new GroupSymbol("X"), query, metadata, select.getProjectedSymbols()); //$NON-NLS-1$
      Iterator<SingleElementSymbol> iter = top.getSelect().getProjectedSymbols().iterator();
        HashMap<Expression, SingleElementSymbol> expressionMap = new HashMap<Expression, SingleElementSymbol>();
        for (SingleElementSymbol symbol : select.getProjectedSymbols()) {
          SingleElementSymbol ses = iter.next();
            expressionMap.put(SymbolMap.getExpression(symbol), ses);
            expressionMap.put(new ElementSymbol(symbol.getName()), ses);
        }
        ExpressionMappingVisitor.mapExpressions(orderBy, expressionMap);
View Full Code Here

                                               QueryMetadataInterface metadata,
                                               List<? extends SingleElementSymbol> actualSymbols) throws QueryMetadataException,
                                                                  QueryResolverException,
                                                                  TeiidComponentException {
        Query query = new Query();
        Select select = new Select();
        query.setSelect(select);
        From from = new From();
        from.addClause(new UnaryFromClause(inlineGroup));
        TempMetadataStore store = new TempMetadataStore();
        TempMetadataAdapter tma = new TempMetadataAdapter(metadata, store);
        if (nested instanceof QueryCommand) {
          Query firstProject = ((QueryCommand)nested).getProjectedQuery();
          makeSelectUnique(firstProject.getSelect(), false);
        }
        TempMetadataID gid = store.addTempGroup(inlineGroup.getName(), nested.getProjectedSymbols());
        inlineGroup.setMetadataID(gid);
       
        List<Class<?>> actualTypes = new ArrayList<Class<?>>(nested.getProjectedSymbols().size());
        for (SingleElementSymbol ses : actualSymbols) {
            actualTypes.add(ses.getType());
        }
        List<SingleElementSymbol> selectSymbols = SetQuery.getTypedProjectedSymbols(ResolverUtil.resolveElementsInGroup(inlineGroup, tma), actualTypes, tma);
        Iterator<? extends SingleElementSymbol> iter = actualSymbols.iterator();
        for (SingleElementSymbol ses : selectSymbols) {
          ses = (SingleElementSymbol)ses.clone();
          SingleElementSymbol actual = iter.next();
          if (!ses.getShortCanonicalName().equals(actual.getShortCanonicalName())) {
            if (ses instanceof AliasSymbol) {
              ((AliasSymbol)ses).setShortName(actual.getShortName());
            } else {
              ses = new AliasSymbol(actual.getShortName(), ses);
            }
          }
      select.addSymbol(ses);
    }
        query.setFrom(from);
        QueryResolver.resolveCommand(query, tma);
        query.setOption(nested.getOption());
        from.getClauses().clear();
View Full Code Here

    Query query = (Query)info.getViewDefinition().clone();
    query.setOrderBy(null);
    SymbolMap expressionMapping = SymbolMap.createSymbolMap(update.getGroup(), query.getProjectedSymbols(), metadata);
   
    ArrayList<SingleElementSymbol> selectSymbols = mapChangeList(update, symbolMap);
    query.setSelect(new Select(selectSymbols));
    ExpressionMappingVisitor emv = new ExpressionMappingVisitor(expressionMapping.asMap(), true);
    PostOrderNavigator.doVisit(query.getSelect(), emv);
   
    Criteria crit = update.getCriteria();
    if (crit != null) {
View Full Code Here

   
    Query query = (Query)info.getViewDefinition().clone();
    query.setOrderBy(null);
    SymbolMap expressionMapping = SymbolMap.createSymbolMap(delete.getGroup(), query.getProjectedSymbols(), metadata);
   
    query.setSelect(new Select());
    ExpressionMappingVisitor emv = new ExpressionMappingVisitor(expressionMapping.asMap(), true);
   
    Criteria crit = delete.getCriteria();
    if (crit != null) {
      PostOrderNavigator.doVisit(crit, emv);
View Full Code Here

  }
 
  public static Command createDeleteProcedure(Delete delete, QueryMetadataInterface metadata, CommandContext context) throws QueryResolverException, QueryMetadataException, TeiidComponentException, TeiidProcessingException {
    QueryRewriter rewriter = new QueryRewriter(metadata, context, null);
    Criteria crit = delete.getCriteria();
    Query query = new Query(new Select(), new From(Arrays.asList(new UnaryFromClause(delete.getGroup()))), crit, null, null);
    return rewriter.createDeleteProcedure(delete, query, delete.getGroup(), delete.getGroup().getName());
  }
View Full Code Here

TOP

Related Classes of org.teiid.query.sql.lang.Select

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.