示例#1
0
  /**
   * Convert a list of SingleElementSymbols to a List of ColumnInfo objects.
   *
   * @param symbols List of SingleElementSymbols
   * @return List of ColumnInfos
   */
  public static List createColumnInfos(List symbols) {
    List infos = new ArrayList(symbols.size());
    Iterator iter = symbols.iterator();
    while (iter.hasNext()) {
      Expression symbol = (Expression) iter.next();
      String name = Symbol.getName(symbol);
      if (symbol instanceof AliasSymbol) {
        AliasSymbol alias = (AliasSymbol) symbol;
        symbol = alias.getSymbol();
      }
      if (symbol instanceof ElementSymbol) {
        ElementSymbol element = (ElementSymbol) symbol;
        GroupSymbol group = element.getGroupSymbol();
        Object groupID = null;
        if (group != null) {
          groupID = group.getMetadataID();
        }
        infos.add(
            new ColumnInfo(
                name,
                DataTypeManager.getDataTypeName(element.getType()),
                element.getType(),
                groupID,
                element.getMetadataID()));
      } else { // ExpressionSymbol or AggregateSymbol
        // Expressions don't map to a single element or group, so don't save that info
        infos.add(
            new ColumnInfo(
                name, DataTypeManager.getDataTypeName(symbol.getType()), symbol.getType()));
      }
    }

    return infos;
  }
  /**
   * @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);
      }
    }
  }
示例#3
0
 private List<Constant> convertValuesToConstants(List<?> values, List<ElementSymbol> elements) {
   ArrayList<Constant> constants = new ArrayList<Constant>(values.size());
   for (int i = 0; i < elements.size(); i++) {
     ElementSymbol es = elements.get(i);
     Class<?> type = es.getType();
     constants.add(new Constant(values.get(i), type));
   }
   return constants;
 }
 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());
 }