예제 #1
0
  /**
   * @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);
      }
    }
  }
예제 #2
0
 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());
 }
예제 #3
0
 private void updateGroupName(PlanNode node, TableFunctionReference tt) {
   String groupName = node.getGroups().iterator().next().getName();
   tt.getGroupSymbol().setName(groupName);
   for (ElementSymbol symbol : tt.getProjectedSymbols()) {
     symbol.setGroupSymbol(new GroupSymbol(groupName));
   }
 }
예제 #4
0
 /**
  * Get the ordered list of all elements returned by this query. These elements may be
  * ElementSymbols or ExpressionSymbols but in all cases each represents a single column.
  *
  * @return Ordered list of SingleElementSymbol
  */
 public List getProjectedSymbols() {
   if (!returnParameters()) {
     return getResultSetColumns();
   }
   // add result set columns
   List<ElementSymbol> result = new ArrayList<ElementSymbol>(getResultSetColumns());
   // add out/inout parameter symbols
   for (SPParameter parameter : mapOfParameters.values()) {
     if (parameter.getParameterType() == ParameterInfo.RETURN_VALUE) {
       ElementSymbol symbol = parameter.getParameterSymbol();
       symbol.setGroupSymbol(this.getGroup());
       result.add(0, symbol);
     } else if (parameter.getParameterType() == ParameterInfo.INOUT
         || parameter.getParameterType() == ParameterInfo.OUT) {
       ElementSymbol symbol = parameter.getParameterSymbol();
       symbol.setGroupSymbol(this.getGroup());
       result.add(symbol);
     }
   }
   return result;
 }
예제 #5
0
 public List<ElementSymbol> getResultSetColumns() {
   SPParameter resultSetParameter = getResultSetParameter();
   if (resultSetParameter != null) {
     List<ElementSymbol> result = new LinkedList<ElementSymbol>();
     for (Iterator<ElementSymbol> i = resultSetParameter.getResultSetColumns().iterator();
         i.hasNext(); ) {
       ElementSymbol symbol = i.next().clone();
       symbol.setGroupSymbol(getGroup());
       result.add(symbol);
     }
     return result;
   }
   return Collections.emptyList();
 }
예제 #6
0
 private ElementSymbol exceptionSymbol(GroupSymbol gs, int pos) {
   ElementSymbol es = UpdateProcedureResolver.exceptionGroup.get(pos).clone();
   es.setGroupSymbol(gs);
   return es;
 }