Пример #1
0
  @Test
  public void testProcedureBatching() throws Exception {
    ProcedureExecution exec = new FakeProcedureExecution(2, 1);

    // this has two result set columns and 1 out parameter
    int total_columns = 3;
    StoredProcedure command =
        (StoredProcedure) helpGetCommand("{call pm2.spTest8(?)}", EXAMPLE_BQT); // $NON-NLS-1$
    command.getInputParameters().get(0).setExpression(new Constant(1));
    Call proc = new LanguageBridgeFactory(EXAMPLE_BQT).translate(command);

    ProcedureBatchHandler pbh = new ProcedureBatchHandler(proc, exec);

    assertEquals(total_columns, pbh.padRow(Arrays.asList(null, null)).size());

    List params = pbh.getParameterRow();

    assertEquals(total_columns, params.size());
    // check the parameter value
    assertEquals(Integer.valueOf(0), params.get(2));

    try {
      pbh.padRow(Arrays.asList(1));
      fail("Expected exception from resultset mismatch"); // $NON-NLS-1$
    } catch (TranslatorException err) {
      assertEquals(
          "TEIID30479 Could not process stored procedure results for EXEC spTest8(1).  Expected 2 result set columns, but was 1.  Please update your models to allow for stored procedure results batching.",
          err.getMessage()); // $NON-NLS-1$
    }
  }
Пример #2
0
 private Expression rewriteMultiSourceCommand(Command command) throws TeiidComponentException {
   Expression result = null;
   if (command instanceof StoredProcedure) {
     StoredProcedure obj = (StoredProcedure) command;
     for (Iterator<SPParameter> params = obj.getMapOfParameters().values().iterator();
         params.hasNext(); ) {
       SPParameter param = params.next();
       if (param.getParameterType() != SPParameter.IN) {
         continue;
       }
       if (metadata.isMultiSourceElement(param.getMetadataID())) {
         Expression source = param.getExpression();
         params.remove();
         if (param.isUsingDefault()
             && source instanceof Constant
             && ((Constant) source).isNull()) {
           continue;
         }
         result = source;
         break;
       }
     }
   }
   if (command instanceof Insert) {
     Insert obj = (Insert) command;
     for (int i = 0; i < obj.getVariables().size(); i++) {
       ElementSymbol elem = obj.getVariables().get(i);
       Object metadataID = elem.getMetadataID();
       if (metadata.isMultiSourceElement(metadataID)) {
         Expression source = (Expression) obj.getValues().get(i);
         obj.getVariables().remove(i);
         obj.getValues().remove(i);
         result = source;
         break;
       }
     }
   } else if (command instanceof FilteredCommand) {
     for (Criteria c : Criteria.separateCriteriaByAnd(((FilteredCommand) command).getCriteria())) {
       if (!(c instanceof CompareCriteria)) {
         continue;
       }
       CompareCriteria cc = (CompareCriteria) c;
       if (cc.getLeftExpression() instanceof ElementSymbol) {
         ElementSymbol es = (ElementSymbol) cc.getLeftExpression();
         if (metadata.isMultiSourceElement(es.getMetadataID())
             && EvaluatableVisitor.willBecomeConstant(cc.getRightExpression())) {
           if (result != null && !result.equals(cc.getRightExpression())) {
             return Constant.NULL_CONSTANT;
           }
           result = cc.getRightExpression();
         }
       }
     }
   }
   return result;
 }
  @Override
  public void visit(StoredProcedure obj) {
    preVisitVisitor(obj);

    Collection<SPParameter> params = obj.getParameters();
    if (params != null && !params.isEmpty()) {
      for (SPParameter parameter : params) {
        Expression expression = parameter.getExpression();
        visitNode(expression);
      }
    }

    visitNode(obj.getOption());
    postVisitVisitor(obj);
  }
Пример #4
0
  public boolean equals(Object obj) {
    // Quick same object test
    if (this == obj) {
      return true;
    }

    // Quick fail tests
    if (!(obj instanceof StoredProcedure)) {
      return false;
    }

    StoredProcedure other = (StoredProcedure) obj;

    return sameOptionAndHint(other)
        && this.getGroup().equals(other.getGroup())
        && this.mapOfParameters.equals(other.mapOfParameters);
  }
Пример #5
0
 public Object clone() {
   StoredProcedure copy = new StoredProcedure();
   copy.setModelID(getModelID());
   copy.setProcedureName(getProcedureName());
   copy.setProcedureCallableName(getProcedureCallableName());
   copy.setProcedureID(getProcedureID());
   copy.setGroup(getGroup().clone());
   copy.callableName = callableName;
   copy.calledWithReturn = calledWithReturn;
   Collection<SPParameter> params = getParameters();
   for (SPParameter spParameter : params) {
     copy.setParameter((SPParameter) spParameter.clone());
   }
   copy.resultSetParameterKey = resultSetParameterKey;
   this.copyMetadataState(copy);
   copy.displayNamedParameters = displayNamedParameters;
   copy.isCallableStatement = isCallableStatement;
   copy.isProcedureRelational = isProcedureRelational;
   return copy;
 }
Пример #6
0
  private TupleSource handleSystemProcedures(final CommandContext context, StoredProcedure proc)
      throws TeiidComponentException, QueryMetadataException, QueryProcessingException,
          QueryResolverException, QueryValidatorException, TeiidProcessingException,
          ExpressionEvaluationException {
    final QueryMetadataInterface metadata = context.getMetadata();
    if (StringUtil.endsWithIgnoreCase(proc.getProcedureCallableName(), REFRESHMATVIEW)) {
      Object groupID =
          validateMatView(
              metadata, (String) ((Constant) proc.getParameter(2).getExpression()).getValue());
      TempMetadataID matTableId =
          context.getGlobalTableStore().getGlobalTempTableMetadataId(groupID);
      final GlobalTableStore globalStore = getGlobalStore(context, matTableId);
      String matViewName = metadata.getFullName(groupID);
      String matTableName = metadata.getFullName(matTableId);
      LogManager.logDetail(
          LogConstants.CTX_MATVIEWS, "processing refreshmatview for", matViewName); // $NON-NLS-1$
      boolean invalidate =
          Boolean.TRUE.equals(((Constant) proc.getParameter(3).getExpression()).getValue());
      boolean needsLoading =
          globalStore.needsLoading(matTableName, globalStore.getAddress(), true, true, invalidate);
      if (!needsLoading) {
        return CollectionTupleSource.createUpdateCountTupleSource(-1);
      }
      GroupSymbol matTable = new GroupSymbol(matTableName);
      matTable.setMetadataID(matTableId);
      return loadGlobalTable(context, matTable, matTableName, globalStore);
    } else if (StringUtil.endsWithIgnoreCase(proc.getProcedureCallableName(), REFRESHMATVIEWROW)) {
      final Object groupID =
          validateMatView(
              metadata, (String) ((Constant) proc.getParameter(2).getExpression()).getValue());
      TempMetadataID matTableId =
          context.getGlobalTableStore().getGlobalTempTableMetadataId(groupID);
      final GlobalTableStore globalStore = getGlobalStore(context, matTableId);
      Object pk = metadata.getPrimaryKey(groupID);
      String matViewName = metadata.getFullName(groupID);
      if (pk == null) {
        throw new QueryProcessingException(
            QueryPlugin.Event.TEIID30230,
            QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30230, matViewName));
      }
      List<?> ids = metadata.getElementIDsInKey(pk);
      Constant key = (Constant) proc.getParameter(3).getExpression();
      Object initialValue = key.getValue();
      SPParameter keyOther = proc.getParameter(4);
      Object[] otherCols = null;
      int length = 1;
      if (keyOther != null) {
        otherCols = ((ArrayImpl) ((Constant) keyOther.getExpression()).getValue()).getValues();
        if (otherCols != null) {
          length += otherCols.length;
        }
      }
      if (ids.size() != length) {
        throw new QueryProcessingException(
            QueryPlugin.Event.TEIID30231,
            QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30231, matViewName, ids.size(), length));
      }
      final String matTableName = RelationalPlanner.MAT_PREFIX + matViewName.toUpperCase();
      MatTableInfo info = globalStore.getMatTableInfo(matTableName);
      if (!info.isValid()) {
        return CollectionTupleSource.createUpdateCountTupleSource(-1);
      }
      TempTable tempTable = globalStore.getTempTable(matTableName);
      if (!tempTable.isUpdatable()) {
        throw new QueryProcessingException(
            QueryPlugin.Event.TEIID30232,
            QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30232, matViewName));
      }
      Iterator<?> iter = ids.iterator();
      final Object[] params = new Object[length];
      StringBuilder criteria = new StringBuilder();
      for (int i = 0; i < length; i++) {
        Object id = iter.next();
        String targetTypeName = metadata.getElementType(id);
        Object value = i == 0 ? initialValue : otherCols[i - 1];
        value =
            DataTypeManager.transformValue(value, DataTypeManager.getDataTypeClass(targetTypeName));
        params[i] = value;
        if (i != 0) {
          criteria.append(" AND "); // $NON-NLS-1$
        }
        criteria.append(metadata.getFullName(id)).append(" = ?"); // $NON-NLS-1$
      }
      LogManager.logInfo(
          LogConstants.CTX_MATVIEWS,
          QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30012, matViewName, Arrays.toString(params)));

      String queryString =
          Reserved.SELECT
              + " * "
              + Reserved.FROM
              + ' '
              + matViewName
              + ' '
              + Reserved.WHERE
              + ' '
              + //$NON-NLS-1$
              criteria.toString()
              + ' '
              + Reserved.OPTION
              + ' '
              + Reserved.NOCACHE;
      final QueryProcessor qp =
          context
              .getQueryProcessorFactory()
              .createQueryProcessor(queryString, matViewName.toUpperCase(), context, params);
      final TupleSource ts = new BatchCollector.BatchProducerTupleSource(qp);
      return new ProxyTupleSource() {

        @Override
        protected TupleSource createTupleSource()
            throws TeiidComponentException, TeiidProcessingException {
          List<?> tuple = ts.nextTuple();
          boolean delete = false;
          if (tuple == null) {
            delete = true;
            tuple = Arrays.asList(params);
          } else {
            tuple = new ArrayList<Object>(tuple); // ensure the list is serializable
          }
          List<?> result = globalStore.updateMatViewRow(matTableName, tuple, delete);
          if (eventDistributor != null) {
            eventDistributor.updateMatViewRow(
                context.getVdbName(),
                context.getVdbVersion(),
                metadata.getName(metadata.getModelID(groupID)),
                metadata.getName(groupID),
                tuple,
                delete);
          }
          return CollectionTupleSource.createUpdateCountTupleSource(result != null ? 1 : 0);
        }

        @Override
        public void closeSource() {
          super.closeSource();
          qp.closeProcessing();
        }
      };
    }
    return null;
  }
Пример #7
0
  private TupleSource handleCachedProcedure(final CommandContext context, StoredProcedure proc)
      throws TeiidComponentException, QueryMetadataException, TeiidProcessingException {
    String fullName = context.getMetadata().getFullName(proc.getProcedureID());
    LogManager.logDetail(
        LogConstants.CTX_DQP, "processing cached procedure request for", fullName); // $NON-NLS-1$
    LinkedList<Object> vals = new LinkedList<Object>();
    for (SPParameter param : proc.getInputParameters()) {
      vals.add(((Constant) param.getExpression()).getValue());
    }
    // collapse the hash to single byte for the key to restrict the possible results to 256
    int hash = vals.hashCode();
    hash |= (hash >>> 16);
    hash |= (hash >>> 8);
    hash &= 0x000000ff;
    final CacheID cid =
        new CacheID(
            new ParseInfo(),
            fullName + hash,
            context.getVdbName(),
            context.getVdbVersion(),
            context.getConnectionId(),
            context.getUserName());
    cid.setParameters(vals);
    CachedResults results = cache.get(cid);
    if (results != null) {
      TupleBuffer buffer = results.getResults();
      return buffer.createIndexedTupleSource();
    }
    // construct a query with a no cache hint
    final CacheHint hint = proc.getCacheHint();
    proc.setCacheHint(null);
    Option option = new Option();
    option.setNoCache(true);
    option.addNoCacheGroup(fullName);
    proc.setOption(option);
    StoredProcedure cloneProc = (StoredProcedure) proc.clone();
    int i = 0;
    for (SPParameter param : cloneProc.getInputParameters()) {
      param.setExpression(new Reference(i++));
    }
    final QueryProcessor qp =
        context
            .getQueryProcessorFactory()
            .createQueryProcessor(
                cloneProc.toString(), fullName.toUpperCase(), context, vals.toArray());
    final BatchCollector bc = qp.createBatchCollector();

    return new ProxyTupleSource() {
      boolean success = false;

      @Override
      protected TupleSource createTupleSource()
          throws TeiidComponentException, TeiidProcessingException {
        TupleBuffer tb = bc.collectTuples();
        CachedResults cr = new CachedResults();
        cr.setResults(tb, qp.getProcessorPlan());
        Determinism determinismLevel = qp.getContext().getDeterminismLevel();
        if (hint != null && hint.getDeterminism() != null) {
          LogManager.logTrace(
              LogConstants.CTX_DQP,
              new Object[] {
                "Cache hint modified the query determinism from ",
                determinismLevel,
                " to ",
                hint.getDeterminism()
              }); //$NON-NLS-1$ //$NON-NLS-2$
          determinismLevel = hint.getDeterminism();
        }
        cache.put(cid, determinismLevel, cr, hint != null ? hint.getTtl() : null);
        context.setDeterminismLevel(determinismLevel);
        success = true;
        return tb.createIndexedTupleSource();
      }

      @Override
      public void closeSource() {
        super.closeSource();
        qp.closeProcessing();
        if (!success && bc.getTupleBuffer() != null) {
          bc.getTupleBuffer().remove();
        }
      }
    };
  }
Пример #8
0
  TupleSource registerRequest(final CommandContext context, String modelName, final Command command)
      throws TeiidComponentException, TeiidProcessingException {
    final TempTableStore contextStore = context.getTempTableStore();
    if (command instanceof Query) {
      Query query = (Query) command;
      if (modelName != null && !modelName.equals(TempMetadataAdapter.TEMP_MODEL.getID())) {
        return null;
      }
      return registerQuery(context, contextStore, query);
    }
    if (command instanceof ProcedureContainer) {
      if (command instanceof StoredProcedure) {
        StoredProcedure proc = (StoredProcedure) command;
        if (CoreConstants.SYSTEM_ADMIN_MODEL.equals(modelName)) {
          TupleSource result = handleSystemProcedures(context, proc);
          if (result != null) {
            return result;
          }
        } else if (proc.getGroup().isGlobalTable()) {
          return handleCachedProcedure(context, proc);
        }
        return null; // it's not a stored procedure we want to handle
      }

      final GroupSymbol group = ((ProcedureContainer) command).getGroup();
      if (!modelName.equals(TempMetadataAdapter.TEMP_MODEL.getID()) || !group.isTempGroupSymbol()) {
        return null;
      }
      return new ProxyTupleSource() {

        @Override
        protected TupleSource createTupleSource()
            throws TeiidComponentException, TeiidProcessingException {
          final String groupKey = group.getNonCorrelationName();
          final TempTable table =
              contextStore.getOrCreateTempTable(
                  groupKey, command, bufferManager, true, true, context, group);
          if (command instanceof Insert) {
            Insert insert = (Insert) command;
            TupleSource ts = insert.getTupleSource();
            if (ts == null) {
              Evaluator eval =
                  new Evaluator(Collections.emptyMap(), TempTableDataManager.this, context);
              List<Object> values = new ArrayList<Object>(insert.getValues().size());
              for (Expression expr : (List<Expression>) insert.getValues()) {
                values.add(eval.evaluate(expr, null));
              }
              ts = new CollectionTupleSource(Arrays.asList(values).iterator());
            }
            return table.insert(ts, insert.getVariables(), true, context);
          }
          if (command instanceof Update) {
            final Update update = (Update) command;
            final Criteria crit = update.getCriteria();
            return table.update(crit, update.getChangeList());
          }
          if (command instanceof Delete) {
            final Delete delete = (Delete) command;
            final Criteria crit = delete.getCriteria();
            if (crit == null) {
              // TODO: we'll add a real truncate later
              int rows = table.truncate(false);
              return CollectionTupleSource.createUpdateCountTupleSource(rows);
            }
            return table.delete(crit);
          }
          throw new AssertionError("unknown command " + command); // $NON-NLS-1$
        }
      };
    }
    if (command instanceof Create) {
      Create create = (Create) command;
      String tempTableName = create.getTable().getName();
      if (contextStore.hasTempTable(tempTableName)) {
        throw new QueryProcessingException(
            QueryPlugin.Event.TEIID30229,
            QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30229, tempTableName));
      }
      if (create.getTableMetadata() != null) {
        contextStore.addForeignTempTable(tempTableName, create);
      } else {
        contextStore.addTempTable(tempTableName, create, bufferManager, true, context);
      }
      return CollectionTupleSource.createUpdateCountTupleSource(0);
    }
    if (command instanceof Drop) {
      String tempTableName = ((Drop) command).getTable().getName();
      contextStore.removeTempTableByName(tempTableName, context);
      return CollectionTupleSource.createUpdateCountTupleSource(0);
    }
    if (command instanceof AlterTempTable) {
      AlterTempTable att = (AlterTempTable) command;
      TempTable tt = contextStore.getTempTable(att.getTempTable());
      Assertion.isNotNull(tt, "Table doesn't exist"); // $NON-NLS-1$
      tt.setUpdatable(false);
      if (att.getIndexColumns() != null && tt.getRowCount() > 2 * tt.getTree().getPageSize(true)) {
        for (List<ElementSymbol> cols : att.getIndexColumns()) {
          tt.addIndex(cols, false);
        }
      }
      return CollectionTupleSource.createUpdateCountTupleSource(0);
    }
    return null;
  }
Пример #9
0
  private TupleSource handleSystemProcedures(final CommandContext context, StoredProcedure proc)
      throws TeiidComponentException, QueryMetadataException, QueryProcessingException,
          QueryResolverException, QueryValidatorException, TeiidProcessingException,
          ExpressionEvaluationException {
    final QueryMetadataInterface metadata = context.getMetadata();
    if (StringUtil.endsWithIgnoreCase(proc.getProcedureCallableName(), REFRESHMATVIEW)) {
      Object groupID =
          validateMatView(
              metadata, (String) ((Constant) proc.getParameter(2).getExpression()).getValue());
      TempMetadataID matTableId =
          context.getGlobalTableStore().getGlobalTempTableMetadataId(groupID);
      final GlobalTableStore globalStore = getGlobalStore(context, matTableId);
      String matViewName = metadata.getFullName(groupID);
      String matTableName = metadata.getFullName(matTableId);
      LogManager.logDetail(
          LogConstants.CTX_MATVIEWS, "processing refreshmatview for", matViewName); // $NON-NLS-1$
      boolean invalidate =
          Boolean.TRUE.equals(((Constant) proc.getParameter(3).getExpression()).getValue());
      boolean needsLoading =
          globalStore.needsLoading(matTableName, globalStore.getAddress(), true, true, invalidate);
      if (!needsLoading) {
        return CollectionTupleSource.createUpdateCountTupleSource(-1);
      }
      GroupSymbol matTable = new GroupSymbol(matTableName);
      matTable.setMetadataID(matTableId);
      return loadGlobalTable(context, matTable, matTableName, globalStore);
    } else if (StringUtil.endsWithIgnoreCase(proc.getProcedureCallableName(), REFRESHMATVIEWROWS)) {
      final Object groupID =
          validateMatView(
              metadata, (String) ((Constant) proc.getParameter(2).getExpression()).getValue());
      TempMetadataID matTableId =
          context.getGlobalTableStore().getGlobalTempTableMetadataId(groupID);
      final GlobalTableStore globalStore = getGlobalStore(context, matTableId);
      Object pk = metadata.getPrimaryKey(groupID);
      String matViewName = metadata.getFullName(groupID);
      if (pk == null) {
        throw new QueryProcessingException(
            QueryPlugin.Event.TEIID30230,
            QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30230, matViewName));
      }
      List<?> ids = metadata.getElementIDsInKey(pk);
      Object[][] params =
          (Object[][])
              ((ArrayImpl) ((Constant) proc.getParameter(3).getExpression()).getValue())
                  .getValues();
      return updateMatviewRows(context, metadata, groupID, globalStore, matViewName, ids, params);
    } else if (StringUtil.endsWithIgnoreCase(proc.getProcedureCallableName(), REFRESHMATVIEWROW)) {
      final Object groupID =
          validateMatView(
              metadata, (String) ((Constant) proc.getParameter(2).getExpression()).getValue());
      TempMetadataID matTableId =
          context.getGlobalTableStore().getGlobalTempTableMetadataId(groupID);
      final GlobalTableStore globalStore = getGlobalStore(context, matTableId);
      Object pk = metadata.getPrimaryKey(groupID);
      final String matViewName = metadata.getFullName(groupID);
      if (pk == null) {
        throw new QueryProcessingException(
            QueryPlugin.Event.TEIID30230,
            QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30230, matViewName));
      }
      List<?> ids = metadata.getElementIDsInKey(pk);
      Constant key = (Constant) proc.getParameter(3).getExpression();
      Object initialValue = key.getValue();
      SPParameter keyOther = proc.getParameter(4);
      Object[] param = null;
      if (keyOther != null) {
        Object[] otherCols =
            ((ArrayImpl) ((Constant) keyOther.getExpression()).getValue()).getValues();
        if (otherCols != null) {
          param = new Object[1 + otherCols.length];
          param[0] = initialValue;
          for (int i = 0; i < otherCols.length; i++) {
            param[i + 1] = otherCols[i];
          }
        }
      }
      if (param == null) {
        param = new Object[] {initialValue};
      }

      Object[][] params = new Object[][] {param};

      return updateMatviewRows(context, metadata, groupID, globalStore, matViewName, ids, params);
    }
    return null;
  }
Пример #10
0
  private void resolveStatement(
      CreateProcedureCommand command,
      Statement statement,
      GroupContext externalGroups,
      GroupSymbol variables,
      TempMetadataAdapter metadata)
      throws QueryResolverException, QueryMetadataException, TeiidComponentException {
    LogManager.logTrace(
        org.teiid.logging.LogConstants.CTX_QUERY_RESOLVER,
        new Object[] {"Resolving statement", statement}); // $NON-NLS-1$

    switch (statement.getType()) {
      case Statement.TYPE_IF:
        IfStatement ifStmt = (IfStatement) statement;
        Criteria ifCrit = ifStmt.getCondition();
        for (SubqueryContainer container :
            ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(ifCrit)) {
          resolveEmbeddedCommand(metadata, externalGroups, container.getCommand());
        }
        ResolverVisitor.resolveLanguageObject(ifCrit, null, externalGroups, metadata);
        resolveBlock(command, ifStmt.getIfBlock(), externalGroups, metadata);
        if (ifStmt.hasElseBlock()) {
          resolveBlock(command, ifStmt.getElseBlock(), externalGroups, metadata);
        }
        break;
      case Statement.TYPE_COMMAND:
        CommandStatement cmdStmt = (CommandStatement) statement;
        Command subCommand = cmdStmt.getCommand();

        TempMetadataStore discoveredMetadata =
            resolveEmbeddedCommand(metadata, externalGroups, subCommand);

        if (subCommand instanceof StoredProcedure) {
          StoredProcedure sp = (StoredProcedure) subCommand;
          for (SPParameter param : sp.getParameters()) {
            switch (param.getParameterType()) {
              case ParameterInfo.OUT:
              case ParameterInfo.RETURN_VALUE:
                if (param.getExpression() != null && !isAssignable(metadata, param)) {
                  throw new QueryResolverException(
                      QueryPlugin.Event.TEIID30121,
                      QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30121, param.getExpression()));
                }
                sp.setCallableStatement(true);
                break;
              case ParameterInfo.INOUT:
                if (!isAssignable(metadata, param)) {
                  continue;
                }
                sp.setCallableStatement(true);
                break;
            }
          }
        }

        if (discoveredMetadata != null) {
          metadata.getMetadataStore().getData().putAll(discoveredMetadata.getData());
        }

        // dynamic commands need to be updated as to their implicitly expected projected symbols
        if (subCommand instanceof DynamicCommand) {
          DynamicCommand dynCommand = (DynamicCommand) subCommand;

          if (dynCommand.getIntoGroup() == null && !dynCommand.isAsClauseSet()) {
            if ((command.getResultSetColumns() != null && command.getResultSetColumns().isEmpty())
                || !cmdStmt.isReturnable()
                || command.getResultSetColumns() == null) {
              // we're not interested in the resultset
              dynCommand.setAsColumns(Collections.EMPTY_LIST);
            } else {
              // should match the procedure
              dynCommand.setAsColumns(command.getResultSetColumns());
            }
          }
        }

        if (command.getResultSetColumns() == null
            && cmdStmt.isReturnable()
            && subCommand.returnsResultSet()
            && subCommand.getResultSetColumns() != null
            && !subCommand.getResultSetColumns().isEmpty()) {
          command.setResultSetColumns(subCommand.getResultSetColumns());
          if (command.getProjectedSymbols().isEmpty()) {
            command.setProjectedSymbols(subCommand.getResultSetColumns());
          }
        }

        break;
      case Statement.TYPE_ERROR:
      case Statement.TYPE_ASSIGNMENT:
      case Statement.TYPE_DECLARE:
      case Statement.TYPE_RETURN:
        ExpressionStatement exprStmt = (ExpressionStatement) statement;
        // first resolve the value.  this ensures the value cannot use the variable being defined
        if (exprStmt.getExpression() != null) {
          Expression expr = exprStmt.getExpression();
          for (SubqueryContainer container :
              ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(expr)) {
            resolveEmbeddedCommand(metadata, externalGroups, container.getCommand());
          }
          ResolverVisitor.resolveLanguageObject(expr, null, externalGroups, metadata);
        }

        // second resolve the variable
        switch (statement.getType()) {
          case Statement.TYPE_DECLARE:
            collectDeclareVariable(
                (DeclareStatement) statement, variables, metadata, externalGroups);
            break;
          case Statement.TYPE_ASSIGNMENT:
            AssignmentStatement assStmt = (AssignmentStatement) statement;
            ResolverVisitor.resolveLanguageObject(
                assStmt.getVariable(), null, externalGroups, metadata);
            if (!metadata.elementSupports(
                assStmt.getVariable().getMetadataID(), SupportConstants.Element.UPDATE)) {
              throw new QueryResolverException(
                  QueryPlugin.Event.TEIID30121,
                  QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30121, assStmt.getVariable()));
            }
            // don't allow variable assignments to be external
            assStmt.getVariable().setIsExternalReference(false);
            break;
          case Statement.TYPE_RETURN:
            ReturnStatement rs = (ReturnStatement) statement;
            if (rs.getExpression() != null) {
              if (command.getReturnVariable() == null) {
                throw new QueryResolverException(
                    QueryPlugin.Event.TEIID31125,
                    QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31125, rs));
              }
              rs.setVariable(command.getReturnVariable().clone());
            }
            // else - we don't currently require the use of return for backwards compatibility
            break;
        }

        // third ensure the type matches
        if (exprStmt.getExpression() != null) {
          Class<?> varType = exprStmt.getExpectedType();
          Class<?> exprType = exprStmt.getExpression().getType();
          if (exprType == null) {
            throw new QueryResolverException(
                QueryPlugin.Event.TEIID30123, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30123));
          }
          String varTypeName = DataTypeManager.getDataTypeName(varType);
          exprStmt.setExpression(
              ResolverUtil.convertExpression(exprStmt.getExpression(), varTypeName, metadata));
          if (statement.getType() == Statement.TYPE_ERROR) {
            ResolverVisitor.checkException(exprStmt.getExpression());
          }
        }
        break;
      case Statement.TYPE_WHILE:
        WhileStatement whileStmt = (WhileStatement) statement;
        Criteria whileCrit = whileStmt.getCondition();
        for (SubqueryContainer container :
            ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(whileCrit)) {
          resolveEmbeddedCommand(metadata, externalGroups, container.getCommand());
        }
        ResolverVisitor.resolveLanguageObject(whileCrit, null, externalGroups, metadata);
        resolveBlock(command, whileStmt.getBlock(), externalGroups, metadata);
        break;
      case Statement.TYPE_LOOP:
        LoopStatement loopStmt = (LoopStatement) statement;
        String groupName = loopStmt.getCursorName();

        isValidGroup(metadata, groupName);
        Command cmd = loopStmt.getCommand();
        resolveEmbeddedCommand(metadata, externalGroups, cmd);
        List<Expression> symbols = cmd.getProjectedSymbols();

        // add the loop cursor group into its own context
        TempMetadataStore store = metadata.getMetadataStore().clone();
        metadata = new TempMetadataAdapter(metadata.getMetadata(), store);
        externalGroups = new GroupContext(externalGroups, null);

        ProcedureContainerResolver.addScalarGroup(groupName, store, externalGroups, symbols, false);

        resolveBlock(command, loopStmt.getBlock(), externalGroups, metadata);
        break;
      case Statement.TYPE_COMPOUND:
        resolveBlock(command, (Block) statement, externalGroups, metadata);
        break;
    }
  }