Package org.teiid.query.sql.lang

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


  private void addNestedCommand(PlanNode node,
      GroupSymbol group, Command nestedCommand, Command toPlan, boolean merge) throws TeiidComponentException, QueryMetadataException, TeiidProcessingException {
    if (nestedCommand instanceof QueryCommand) {
      //remove unnecessary order by
          QueryCommand queryCommand = (QueryCommand)nestedCommand;
          if (queryCommand.getLimit() == null) {
            queryCommand.setOrderBy(null);
          }
          if (merge && queryCommand.getWith() != null) {
            //TODO: should recontext with and merge
            merge = false;
          }
        }
    node.setProperty(NodeConstants.Info.NESTED_COMMAND, nestedCommand);
View Full Code Here


        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);
               
View Full Code Here

    }

    public void visit( SetQuery obj ) {
        addCacheHint(obj.getCacheHint());
        addWithClause(obj);
        QueryCommand query = obj.getLeftQuery();
        appendSetQuery(obj, query, false);

        beginClause(0);
        append(obj.getOperation());
View Full Code Here

    if (query.getWith() == null) {
      return;
    }
    LinkedHashSet<GroupSymbol> discoveredGroups = new LinkedHashSet<GroupSymbol>();
    for (WithQueryCommand obj : query.getWith()) {
            QueryCommand queryExpression = obj.getCommand();
           
            QueryResolver.setChildMetadata(queryExpression, query);
           
            QueryResolver.resolveCommand(queryExpression, metadata.getMetadata(), false);
View Full Code Here

        FakeMetadataFacade metadata = exampleMetadata();

        String resultSetName = "xmltest.rs"; //$NON-NLS-1$
       
        String sql = "SELECT itemNum, itemName, itemQuantity FROM xmltest.rs";         //$NON-NLS-1$
        QueryCommand command = (QueryCommand) helpGetCommand(sql, metadata);              
       
        Criteria crit = helpGetCriteria("xmltest.rs.itemName = 'Screwdriver'", metadata)//$NON-NLS-1$
        FakeXMLProcessorEnvironment env = new FakeXMLProcessorEnvironment();
        Program program = exampleProgram2(crit, metadata, env);
               
        BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
        XMLPlan temp = new XMLPlan(env);
        CommandContext context = new CommandContext("pid", null, null, null, 1); //$NON-NLS-1$
        temp.initialize(context,null,bufferMgr);
        env.addData(resultSetName, command.getProjectedSymbols(), new List[] {
                    Arrays.asList( new Object[] { "001", "Lamp", new Integer(5) } ),         //$NON-NLS-1$ //$NON-NLS-2$
                    Arrays.asList( new Object[] { "002", "Screwdriver", new Integer(100) } ),         //$NON-NLS-1$ //$NON-NLS-2$
                    Arrays.asList( new Object[] { "003", "Goat", new Integer(4) } )         //$NON-NLS-1$ //$NON-NLS-2$
                    } );           
View Full Code Here

        int cmdType = command.getType();
        Criteria criteria = null;
        switch(cmdType) {
            case Command.TYPE_QUERY:
               
                QueryCommand queryCommand = (QueryCommand) command;
               
                Limit limit = queryCommand.getLimit();
               
                if (limit != null && limit.getRowLimit() instanceof Constant) {
                    Constant rowLimit = (Constant)limit.getRowLimit();
                    if (Integer.valueOf(0).equals(rowLimit.getValue())) {
                        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;                           
                        }                       
                    }
                    return shouldExecute;
                }

                // Else this is a query
                Query query = (Query) queryCommand;               
                criteria = query.getCriteria();

                if(criteria == null) {
                    return true;
                } else if(!EvaluatableVisitor.isFullyEvaluatable(criteria, duringPlanning)) {
                    // If there are elements present in the criteria,
                    // then we don't know the result, so assume we need to execute
                    return true;
                } else if(Evaluator.evaluate(criteria)) {
                    if (simplifyCriteria) {
                        query.setCriteria(null);
                    }
                    return true;
                }
                break;
            case Command.TYPE_INSERT:
              Insert insert = (Insert) command;
              QueryCommand expr = insert.getQueryExpression();
              if (expr != null) {
                return shouldExecute(expr, simplifyCriteria);
              }
              return true;
            case Command.TYPE_UPDATE:
View Full Code Here

    /**
     * Returns a safe clone
     * @see java.lang.Object#clone()
     */
    public Object clone() {
      QueryCommand copyCommand = null;
        if(getCommand() != null) {
            copyCommand = (QueryCommand) getCommand().clone();
        }
        ScalarSubquery clone = new ScalarSubquery(copyCommand);
        //Don't invoke the lazy-loading getType()
View Full Code Here

        /*
         * Adds a row limit to a query if Statement.setMaxRows has been called and the command
         * doesn't already have a limit clause.
         */
        if (requestMsg.getRowLimit() > 0 && command instanceof QueryCommand) {
            QueryCommand query = (QueryCommand)command;
            if (query.getLimit() == null) {
                query.setLimit(new Limit(null, new Constant(new Integer(requestMsg.getRowLimit()), DataTypeManager.DefaultDataClasses.INTEGER)));
                this.addedLimit = true;
            }
        }
       
        try {
View Full Code Here

TOP

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

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.