Examples of QueryCommand


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

            if (limit != null) {
                processLimit(limit, unionCommand, metadata);
            }
            int count = 0;
            for (PlanNode child : setOpNode.getChildren()) {
                QueryCommand command = createQuery(metadata, capFinder, accessRoot, child);
                if (count == 0) {
                    unionCommand.setLeftQuery(command);
                } else if (count == 1) {
                    unionCommand.setRightQuery(command);
                } else {
View Full Code Here

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

            }
            case NodeConstants.Types.SOURCE:
            {
              if (Boolean.TRUE.equals(node.getProperty(NodeConstants.Info.INLINE_VIEW))) {
                    PlanNode child = node.getFirstChild();
                    QueryCommand newQuery = createQuery(metadata, capFinder, accessRoot, child);
                   
                    //ensure that the group is consistent
                    GroupSymbol symbol = node.getGroups().iterator().next();
                    SubqueryFromClause sfc = new SubqueryFromClause(symbol, newQuery);
                    query.getFrom().addClause(sfc);
View Full Code Here

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

    }
  }

  public static void prepareSubquery(SubqueryContainer container) {
    RelationalPlan subqueryPlan = (RelationalPlan)container.getCommand().getProcessorPlan();
    QueryCommand command = CriteriaCapabilityValidatorVisitor.getQueryCommand(subqueryPlan);
    if (command == null) {
      return;
    }
    final SymbolMap map = container.getCommand().getCorrelatedReferences();
    if (map != null) {
      ExpressionMappingVisitor visitor = new RuleMergeCriteria.ReferenceReplacementVisitor(map);
      DeepPostOrderNavigator.doVisit(command, visitor);
    }
    command.setProcessorPlan(container.getCommand().getProcessorPlan());
    boolean removeLimit = false;
    if (container instanceof ExistsCriteria) {
      removeLimit = !((ExistsCriteria)container).shouldEvaluate();
    } else if (container instanceof ScalarSubquery) {
      removeLimit = !((ScalarSubquery)container).shouldEvaluate();
    }
    if (removeLimit && command.getLimit() != null && command.getLimit().isImplicit()) {
      command.setLimit(null);
    }
    container.setCommand(command);
  }
View Full Code Here

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

          metadata = new TempMetadataAdapter(metadata, new TempMetadataStore(tempMetadata));
        }
       
        switch(command.getType()) {
      case Command.TYPE_QUERY:
                QueryCommand queryCommand = (QueryCommand)command;
              if (removeOrderBy && queryCommand.getLimit() == null) {
                queryCommand.setOrderBy(null);
                }
              if (queryCommand.getWith() != null) {
                for (WithQueryCommand withQueryCommand : queryCommand.getWith()) {
                  if (withQueryCommand.getColumns() == null) {
                    List<ElementSymbol> columns = ResolverUtil.resolveElementsInGroup(withQueryCommand.getGroupSymbol(), metadata);
                    withQueryCommand.setColumns(LanguageObject.Util.deepClone(columns, ElementSymbol.class));
                  }
            rewriteSubqueryContainer(withQueryCommand, true);
View Full Code Here

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

  public ProcessorPlan optimize(ProcedureContainer userCommand, TriggerAction ta, IDGenerator idGenerator, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context)
  throws QueryMetadataException, TeiidComponentException, QueryResolverException, TeiidProcessingException {
    //TODO consider caching the plans without using the changing vars
    QueryRewriter.rewrite(ta, null, metadata, context, QueryResolver.getVariableValues(userCommand, true, metadata), userCommand.getType());
   
    QueryCommand query = null;
    Map<ElementSymbol, Expression> params = new HashMap<ElementSymbol, Expression>();
   
    if (userCommand instanceof Insert) {
      Insert insert = (Insert)userCommand;
      if (insert.getQueryExpression() != null) {
        query = insert.getQueryExpression();
      } else {
        query = new Query();
        ((Query)query).setSelect(new Select(RuleChooseJoinStrategy.createExpressionSymbols(insert.getValues())));
      }
    } else if (userCommand instanceof Delete) {
      query = createOldQuery(userCommand, ta, metadata, params);
    } else if (userCommand instanceof Update) {
      query = createOldQuery(userCommand, ta, metadata, params);
    } else {
      throw new AssertionError();
    }
   
    for (Map.Entry<ElementSymbol, Expression> entry : QueryResolver.getVariableValues(userCommand, false, metadata).entrySet()) {
      if (entry.getKey().getGroupSymbol().getShortName().equalsIgnoreCase(ProcedureReservedWords.INPUTS)) {
        Expression value = entry.getValue() instanceof SingleElementSymbol ? entry.getValue() : new ExpressionSymbol("x", entry.getValue()); //$NON-NLS-1$
        ElementSymbol newElementSymbol = entry.getKey().clone();
        newElementSymbol.getGroupSymbol().setName(SQLConstants.Reserved.NEW);
        params.put(newElementSymbol, value);
        if (userCommand instanceof Update) {
          ((Query)query).getSelect().addSymbol((SelectSymbol) value);
        }
      } else {
        params.put(entry.getKey(), entry.getValue());
      }
    }
    ForEachRowPlan result = new ForEachRowPlan();
    result.setParams(params);
    ProcessorPlan queryPlan = QueryOptimizer.optimizePlan(query, metadata, idGenerator, capFinder, analysisRecord, context);
    result.setQueryPlan(queryPlan);
    result.setLookupMap(RelationalNode.createLookupMap(query.getProjectedSymbols()));
    ProcedurePlan rowProcedure = (ProcedurePlan)QueryOptimizer.optimizePlan(new CreateUpdateProcedureCommand(ta.getBlock()), metadata, idGenerator, capFinder, analysisRecord, context);
    result.setRowProcedure(rowProcedure);
    return result;
  }
View Full Code Here

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

  private QueryCommand createOldQuery(ProcedureContainer userCommand,
      TriggerAction ta, QueryMetadataInterface metadata,
      Map<ElementSymbol, Expression> params)
      throws QueryMetadataException, TeiidComponentException {
    QueryCommand query;
    ArrayList<SelectSymbol> selectSymbols = new ArrayList<SelectSymbol>();
    List<ElementSymbol> allSymbols = ResolverUtil.resolveElementsInGroup(ta.getView(), metadata);
    for (ElementSymbol elementSymbol : allSymbols) {
      params.put(new ElementSymbol(SQLConstants.Reserved.OLD + ElementSymbol.SEPARATOR + elementSymbol.getShortName()), elementSymbol);
      if (userCommand instanceof Update) {
View Full Code Here

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

        List<WithQueryCommand> withList = null;
        Object modelID = null;
    boolean supportsWithPushdown = true;
    List<WithQueryCommand> pushDownWith = null;
    if (command instanceof QueryCommand) {
      QueryCommand queryCommand = (QueryCommand)command;
      final HashSet<String> names = new HashSet<String>();
      if (queryCommand.getWith() != null) {
            withList = queryCommand.getWith();
            for (WithQueryCommand with : queryCommand.getWith()) {
              Command subCommand = with.getCommand();
                  ProcessorPlan procPlan = QueryOptimizer.optimizePlan(subCommand, metadata, idGenerator, capFinder, analysisRecord, context);
                  subCommand.setProcessorPlan(procPlan);
                  QueryCommand withCommand = CriteriaCapabilityValidatorVisitor.getQueryCommand(procPlan);
                  if (withCommand != null && supportsWithPushdown) {
                    modelID = CriteriaCapabilityValidatorVisitor.validateCommandPushdown(modelID, metadata, capFinder, withCommand);
                }
                  if (modelID == null) {
                    supportsWithPushdown = false;
                  } else {
                    if (pushDownWith == null) {
                      pushDownWith = new ArrayList<WithQueryCommand>();
                    }
                    WithQueryCommand wqc = new WithQueryCommand(with.getGroupSymbol(), with.getColumns(), withCommand);
                    pushDownWith.add(wqc);
                  }
              names.add(with.getGroupSymbol().getCanonicalName());
        }
            if (modelID != null && supportsWithPushdown) {
              supportsWithPushdown = CapabilitiesUtil.supports(Capability.COMMON_TABLE_EXPRESSIONS, modelID, metadata, capFinder);
            }
        if (supportsWithPushdown) {
          addModelIds(command, modelID, names);
        }
          }
    }
       
        PlanNode plan;
    try {
      plan = generatePlan(command);
    } catch (TeiidProcessingException e) {
      throw new QueryPlannerException(e, e.getMessage());
    }

    if(debug) {
            analysisRecord.println("\nCANONICAL PLAN: \n" + plan); //$NON-NLS-1$
    }

        // Connect ProcessorPlan to SubqueryContainer (if any) of SELECT or PROJECT nodes
    connectSubqueryContainers(plan); //TODO: merge with node creation
       
        // Set top column information on top node
        List<SingleElementSymbol> topCols = Util.deepClone(command.getProjectedSymbols(), SingleElementSymbol.class);

        // Build rule set based on hints
        RuleStack rules = buildRules();

        // Run rule-based optimizer
        plan = executeRules(rules, plan);

        RelationalPlan result = planToProcessConverter.convert(plan);
        if (withList != null && supportsWithPushdown) {
          QueryCommand queryCommand = CriteriaCapabilityValidatorVisitor.getQueryCommand(result);
          if (queryCommand != null) {
        if (CriteriaCapabilityValidatorVisitor.validateCommandPushdown(modelID, metadata, capFinder, queryCommand) == null) {
          supportsWithPushdown = false;
        } else {
          queryCommand.setWith(pushDownWith);
        }
          } else {
            supportsWithPushdown = false;
          }
        }
View Full Code Here

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

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

        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

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

    }

    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
TOP
Copyright © 2018 www.massapi.com. 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.