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

    DynamicCommand dynamicCmd = (DynamicCommand) command;

    Iterator columns = dynamicCmd.getAsColumns().iterator();

    Set<GroupSymbol> groups = new HashSet<GroupSymbol>();

    // if there is no into group, just create temp metadata ids
    if (dynamicCmd.getIntoGroup() == null) {
      while (columns.hasNext()) {
        ElementSymbol column = (ElementSymbol) columns.next();
        column.setMetadataID(new TempMetadataID(column.getShortName(), column.getType()));
      }
    } else if (dynamicCmd.getIntoGroup().isTempGroupSymbol()) {
      while (columns.hasNext()) {
        ElementSymbol column = (ElementSymbol) columns.next();
        GroupSymbol gs = getTeiidParser().createASTNode(ASTNodes.GROUP_SYMBOL);
        gs.setName(dynamicCmd.getIntoGroup().getName());
        column.setGroupSymbol(gs);
      }
    }

    ResolverVisitor visitor = new ResolverVisitor(getTeiidParser().getVersion());
    visitor.resolveLanguageObject(
        dynamicCmd, groups, dynamicCmd.getExternalGroupContexts(), metadata);
    String sqlType = getDataTypeManager().getDataTypeName(dynamicCmd.getSql().getType());
    String targetType = DataTypeManagerService.DefaultDataTypes.STRING.getId();

    if (!targetType.equals(sqlType)
        && !getDataTypeManager().isImplicitConversion(sqlType, targetType)) {
      throw new QueryResolverException(Messages.gs(Messages.TEIID.TEIID30100, sqlType));
    }

    if (dynamicCmd.getUsing() != null && !dynamicCmd.getUsing().isEmpty()) {
      for (SetClause clause : dynamicCmd.getUsing().getClauses()) {
        ElementSymbol id = clause.getSymbol();
        GroupSymbol gs = getTeiidParser().createASTNode(ASTNodes.GROUP_SYMBOL);
        gs.setName(ProcedureReservedWords.DVARS);
        id.setGroupSymbol(gs);
        id.setType(clause.getValue().getType());
        id.setMetadataID(new TempMetadataID(id.getName(), id.getType()));
      }
    }

    GroupSymbol intoSymbol = dynamicCmd.getIntoGroup();
    if (intoSymbol != null) {
      if (!intoSymbol.isImplicitTempGroupSymbol()) {
        ResolverUtil.resolveGroup(intoSymbol, metadata);
      } else {
        List symbols = dynamicCmd.getAsColumns();
        ResolverUtil.resolveImplicitTempGroup(metadata, intoSymbol, symbols);
      }
    }
  }
 private void collectDeclareVariable(
     DeclareStatement obj,
     GroupSymbol variables,
     TempMetadataAdapter metadata,
     GroupContext externalGroups)
     throws QueryResolverException, TeiidComponentException {
   ElementSymbol variable = obj.getVariable();
   String typeName = obj.getVariableType();
   GroupSymbol gs = variable.getGroupSymbol();
   if (gs == null) {
     String outputName = variable.getShortName();
     variable.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.VARIABLES));
     variable.setOutputName(outputName);
   } else {
     if (gs.getSchema() != null
         || !gs.getShortName().equalsIgnoreCase(ProcedureReservedWords.VARIABLES)) {
       handleUnresolvableDeclaration(
           variable,
           QueryPlugin.Util.getString(
               "ERR.015.010.0031",
               new Object[] {ProcedureReservedWords.VARIABLES, variable})); // $NON-NLS-1$
     }
   }
   boolean exists = false;
   try {
     ResolverVisitor.resolveLanguageObject(variable, null, externalGroups, metadata);
     exists = true;
   } catch (QueryResolverException e) {
     // ignore, not already defined
   }
   if (exists) {
     handleUnresolvableDeclaration(
         variable,
         QueryPlugin.Util.getString("ERR.015.010.0032", variable.getOutputName())); // $NON-NLS-1$
   }
   variable.setType(DataTypeManager.getDataTypeClass(typeName));
   variable.setGroupSymbol(variables);
   TempMetadataID id =
       new TempMetadataID(
           variable.getName(),
           typeName.equalsIgnoreCase(SQLConstants.NonReserved.EXCEPTION)
               ? Exception.class
               : variable.getType());
   id.setUpdatable(true);
   variable.setMetadataID(id);
   // TODO: this will cause the variables group to loose it's cache of resolved symbols
   metadata
       .getMetadataStore()
       .addElementToTempGroup(ProcedureReservedWords.VARIABLES, variable.clone());
 }