Package org.teiid.query.sql.lang

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


     * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, TempMetadataAdapter, boolean)
     */
    public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals)
        throws QueryMetadataException, QueryResolverException, TeiidComponentException {

        SetQuery setQuery = (SetQuery) command;
       
        SimpleQueryResolver.resolveWith(metadata, setQuery);
       
        QueryCommand firstCommand = setQuery.getLeftQuery();
       
        QueryResolver.setChildMetadata(firstCommand, setQuery);
        QueryResolver.resolveCommand(firstCommand, metadata.getMetadata(), false);

        List<SingleElementSymbol> firstProject = firstCommand.getProjectedSymbols();
        List<Class<?>> firstProjectTypes = new ArrayList<Class<?>>();
        for (SingleElementSymbol symbol : firstProject) {
            firstProjectTypes.add(symbol.getType());
        }

        QueryCommand rightCommand = setQuery.getRightQuery();
       
        QueryResolver.setChildMetadata(rightCommand, setQuery);
        QueryResolver.resolveCommand(rightCommand, metadata.getMetadata(), false);

        if (firstProject.size() != rightCommand.getProjectedSymbols().size()) {
            throw new QueryResolverException(QueryPlugin.Util.getString("ERR.015.012.0035", setQuery.getOperation())); //$NON-NLS-1$
        }
        checkSymbolTypes(firstProjectTypes, rightCommand.getProjectedSymbols());
       
        if (resolveNullLiterals) {
            for (int i = 0; i < firstProjectTypes.size(); i++) {
                Class<?> clazz = firstProjectTypes.get(i);
               
                if (clazz == null || clazz.equals(DataTypeManager.DefaultDataClasses.NULL)) {
                    firstProjectTypes.set(i, DataTypeManager.DefaultDataClasses.STRING);
                }
            }
        }

        setQuery.setProjectedTypes(firstProjectTypes, metadata.getMetadata());
       
        // ORDER BY clause
        if(setQuery.getOrderBy() != null) {
            //order by elements must use the short name of the projected symbols
            ResolverUtil.resolveOrderBy(setQuery.getOrderBy(), setQuery, metadata);
        }

        setProjectedTypes(setQuery, firstProjectTypes, metadata.getMetadata());
       
        if (setQuery.getLimit() != null) {
            ResolverUtil.resolveLimit(setQuery.getLimit());
        }
       
        setQuery.setTemporaryMetadata(new HashMap(firstCommand.getTemporaryMetadata()));
    }
View Full Code Here


    return partitions;
  }
 
  public static boolean extractQueries(QueryCommand queryCommand, List<Query> result) {
    if (queryCommand instanceof SetQuery) {
      SetQuery sq = (SetQuery)queryCommand;
      if (sq.isAll() && sq.getOperation() == Operation.UNION && sq.getOrderBy() == null && sq.getLimit() == null && sq.getWith() == null) {
        if (!extractQueries(sq.getLeftQuery(), result)) {
          return false;
        }
        if (!extractQueries(sq.getRightQuery(), result)) {
          return false;
        }
        return true;
        }
      return false;
View Full Code Here

        From u2f = new From();
        u2f = new From();
        u2f.addClause(new UnaryFromClause(new GroupSymbol("db.g3"))); //$NON-NLS-1$
        u2.setFrom(u2f);

        SetQuery union = new SetQuery(Operation.UNION, true, u1, u2);       
                      
        SubquerySetCriteria subCrit = new SubquerySetCriteria(expr, union);
      
        Query outer = new Query();
        outer.setSelect(select);
View Full Code Here

    public void validate(Command command, List<ElementSymbol> viewSymbols) throws QueryMetadataException, TeiidComponentException {
      if (this.updateInfo.deleteType != UpdateType.INHERENT && this.updateInfo.updateType != UpdateType.INHERENT && this.updateInfo.insertType != UpdateType.INHERENT) {
        return;
      }
      if (command instanceof SetQuery) {
        SetQuery setQuery = (SetQuery)command;
          if (setQuery.getLimit() != null) {
            handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0013"), true, true, true); //$NON-NLS-1$
            return;
          }
        LinkedList<Query> queries = new LinkedList<Query>();
        if (!PartitionAnalyzer.extractQueries((SetQuery)command, queries)) {
View Full Code Here

                        return false;
                    }
                }
           
                if(queryCommand instanceof SetQuery) {
                    SetQuery union = (SetQuery) queryCommand;
                    boolean shouldExecute = false;
                    for (QueryCommand innerQuery : union.getQueryCommands()) {
                        boolean shouldInner = shouldExecute(innerQuery, simplifyCriteria, duringPlanning);
                        if(shouldInner) {
                          shouldExecute = true;
                            break;                           
                        }                       
View Full Code Here

    f2.addGroup(new GroupSymbol("m.g2"));     //$NON-NLS-1$
    Query q2 = new Query();
    q2.setSelect(s2);
    q2.setFrom(f2);
   
    SetQuery sq = new SetQuery(Operation.UNION, false, q1, q2);

    helpTest(sq, "SELECT e1 FROM m.g1 UNION SELECT e1 FROM m.g2"); //$NON-NLS-1$
  }
View Full Code Here

    f2.addGroup(new GroupSymbol("m.g2"));     //$NON-NLS-1$
    Query q2 = new Query();
    q2.setSelect(s2);
    q2.setFrom(f2);
   
    SetQuery sq = new SetQuery(Operation.UNION, true, q1, q2);

    helpTest(sq, "SELECT e1 FROM m.g1 UNION ALL SELECT e1 FROM m.g2"); //$NON-NLS-1$
  }
View Full Code Here

    q2.setFrom(f2);
   
    OrderBy orderBy = new OrderBy();
    orderBy.addVariable(new ElementSymbol("e1")); //$NON-NLS-1$
   
    SetQuery sq = new SetQuery(Operation.UNION, false, q1, q2);
    sq.setOrderBy(orderBy);

    helpTest(sq, "SELECT e1 FROM m.g1 UNION SELECT e1 FROM m.g2 ORDER BY e1"); //$NON-NLS-1$
  }
View Full Code Here

    f2.addGroup(new GroupSymbol("m.g2"));     //$NON-NLS-1$
    Query q2 = new Query();
    q2.setSelect(s2);
    q2.setFrom(f2);
   
    SetQuery sq = new SetQuery(Operation.UNION, false, q1, q2);

    helpTest(sq, "SELECT e1 FROM m.g1 UNION SELECT e1 FROM m.g2"); //$NON-NLS-1$
  }
View Full Code Here

    f3.addGroup(new GroupSymbol("m.g3"));     //$NON-NLS-1$
    Query q3 = new Query();
    q3.setSelect(s3);
    q3.setFrom(f3);
   
    SetQuery sq = new SetQuery(Operation.UNION, false, q1, q2);

    SetQuery sq2 = new SetQuery(Operation.UNION, true, q3, sq);

    helpTest(sq2, "SELECT e3 FROM m.g3 UNION ALL (SELECT e1 FROM m.g1 UNION SELECT e1 FROM m.g2)"); //$NON-NLS-1$
  }
View Full Code Here

TOP

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

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.