Example #1
0
  /** Handler for tree selection. */
  void handleTreeSelection() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    ElementSymbol element = null;

    if (!selection.isEmpty()) {
      ICriteriaStrategy strategy = ElementViewerFactory.getCriteriaStrategy(viewer);
      strategy.setTreeViewer(viewer); // make sure this viewer is set before using strategy

      if (strategy.isValid(selection.getFirstElement())) {
        Object eObj = selection.getFirstElement();
        if (eObj instanceof ElementSymbol) {
          element = ((ElementSymbol) eObj);
        } else {
          element = new ElementSymbol(strategy.getRuntimeFullName(eObj), true);

          // the viewer model contains EObjects. so the objects in the selection will
          // be EObjects. since the EObject is used later on in the QueryCriteriaStrategy.getNode()
          // method. save it here.
          element.setMetadataID(eObj);
        }
      }
    }

    model.selectElementSymbol(element);
  }
Example #2
0
  @Test
  public void testForwardOnly() throws Exception {
    ElementSymbol x = new ElementSymbol("x"); // $NON-NLS-1$
    x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List<ElementSymbol> schema = Arrays.asList(x);
    TupleBuffer tb =
        BufferManagerFactory.getStandaloneBufferManager()
            .createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); // $NON-NLS-1$
    tb.setForwardOnly(true);
    tb.addTuple(Arrays.asList(1));
    TupleBatch batch = tb.getBatch(1);
    assertTrue(!batch.getTerminationFlag());
    assertEquals(1, batch.getBeginRow());
    try {
      tb.getBatch(1);
      fail("expected exception"); // $NON-NLS-1$
    } catch (AssertionError e) {

    }
    tb.addTuple(Arrays.asList(1));
    tb.close();
    batch = tb.getBatch(2);
    assertTrue(batch.getTerminationFlag());
    assertEquals(2, batch.getBeginRow());
  }
Example #3
0
 @Test
 public void testTruncate() throws Exception {
   ElementSymbol x = new ElementSymbol("x"); // $NON-NLS-1$
   x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
   List<ElementSymbol> schema = Arrays.asList(x);
   TupleBuffer tb =
       BufferManagerFactory.getStandaloneBufferManager()
           .createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); // $NON-NLS-1$
   tb.setBatchSize(2);
   for (int i = 0; i < 5; i++) {
     tb.addTuple(Arrays.asList(1));
   }
   TupleBatch batch = tb.getBatch(1);
   assertTrue(!batch.getTerminationFlag());
   assertEquals(2, batch.getEndRow());
   tb.close();
   assertEquals(5, tb.getManagedRowCount());
   tb.truncateTo(3);
   assertEquals(3, tb.getManagedRowCount());
   assertEquals(3, tb.getRowCount());
   batch = tb.getBatch(3);
   assertTrue(batch.getTerminationFlag());
   tb.truncateTo(2);
   assertEquals(2, tb.getManagedRowCount());
   assertEquals(2, tb.getRowCount());
   batch = tb.getBatch(2);
   assertTrue(batch.getTerminationFlag());
 }
 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));
   }
 }
Example #5
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;
  }
 public static void determineDependencies(AbstractMetadataRecord p, Command command) {
   Collection<GroupSymbol> groups =
       GroupCollectorVisitor.getGroupsIgnoreInlineViewsAndEvaluatableSubqueries(command, true);
   LinkedHashSet<AbstractMetadataRecord> values = new LinkedHashSet<AbstractMetadataRecord>();
   for (GroupSymbol group : groups) {
     Object mid = group.getMetadataID();
     if (mid instanceof TempMetadataAdapter) {
       mid = ((TempMetadataID) mid).getOriginalMetadataID();
     }
     if (mid instanceof AbstractMetadataRecord) {
       values.add((AbstractMetadataRecord) mid);
     }
   }
   Collection<ElementSymbol> elems = ElementCollectorVisitor.getElements(command, true, true);
   for (ElementSymbol elem : elems) {
     Object mid = elem.getMetadataID();
     if (mid instanceof TempMetadataAdapter) {
       mid = ((TempMetadataID) mid).getOriginalMetadataID();
     }
     if (mid instanceof AbstractMetadataRecord) {
       values.add((AbstractMetadataRecord) mid);
     }
   }
   p.setIncomingObjects(new ArrayList<AbstractMetadataRecord>(values));
 }
  /**
   * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command,
   *     TempMetadataAdapter, boolean)
   */
  public void resolveCommand(
      Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals)
      throws QueryMetadataException, QueryResolverException, TeiidComponentException {

    // by creating a new group context here it means that variables will resolve with a higher
    // precedence than input/changing
    GroupContext externalGroups = command.getExternalGroupContexts();

    List<ElementSymbol> symbols = new LinkedList<ElementSymbol>();

    String countVar =
        ProcedureReservedWords.VARIABLES + Symbol.SEPARATOR + ProcedureReservedWords.ROWCOUNT;
    ElementSymbol updateCount = new ElementSymbol(countVar);
    updateCount.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    symbols.add(updateCount);

    ProcedureContainerResolver.addScalarGroup(
        ProcedureReservedWords.VARIABLES, metadata.getMetadataStore(), externalGroups, symbols);

    if (command instanceof TriggerAction) {
      TriggerAction ta = (TriggerAction) command;
      CreateProcedureCommand cmd = new CreateProcedureCommand(ta.getBlock());
      cmd.setVirtualGroup(ta.getView());
      // TODO: this is not generally correct - we should update the api to set the appropriate type
      cmd.setUpdateType(Command.TYPE_INSERT);
      resolveBlock(cmd, ta.getBlock(), ta.getExternalGroupContexts(), metadata);
      return;
    }

    CreateProcedureCommand procCommand = (CreateProcedureCommand) command;

    resolveBlock(procCommand, procCommand.getBlock(), externalGroups, metadata);
  }
Example #8
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;
 }
Example #9
0
 /** @return singleton update symbol which is lazily created */
 public List<Expression> getUpdateCommandSymbol() {
   if (updateCommandSymbol == null) {
     ElementSymbol symbol = parser.createASTNode(ASTNodes.ELEMENT_SYMBOL);
     symbol.setName("Count"); // $NON-NLS-1$
     symbol.setType(DataTypeManagerService.DefaultDataTypes.INTEGER.getTypeClass());
     updateCommandSymbol = Arrays.asList((Expression) symbol);
   }
   return updateCommandSymbol;
 }
  private boolean isAssignable(TempMetadataAdapter metadata, SPParameter param)
      throws TeiidComponentException, QueryMetadataException {
    if (!(param.getExpression() instanceof ElementSymbol)) {
      return false;
    }
    ElementSymbol symbol = (ElementSymbol) param.getExpression();

    return metadata.elementSupports(symbol.getMetadataID(), SupportConstants.Element.UPDATE);
  }
 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;
 }
 static {
   ElementSymbol es1 = new ElementSymbol("STATE"); // $NON-NLS-1$
   es1.setType(DataTypeManager.DefaultDataClasses.STRING);
   ElementSymbol es2 = new ElementSymbol("ERRORCODE"); // $NON-NLS-1$
   es2.setType(DataTypeManager.DefaultDataClasses.INTEGER);
   ElementSymbol es3 = new ElementSymbol("TEIIDCODE"); // $NON-NLS-1$
   es3.setType(DataTypeManager.DefaultDataClasses.STRING);
   ElementSymbol es4 = new ElementSymbol(NonReserved.EXCEPTION);
   es4.setType(Exception.class);
   ElementSymbol es5 = new ElementSymbol(NonReserved.CHAIN);
   es5.setType(Exception.class);
   exceptionGroup = Arrays.asList(es1, es2, es3, es4, es5);
 }
Example #13
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();
 }
Example #14
0
 @Test
 public void testLobHandling() throws Exception {
   ElementSymbol x = new ElementSymbol("x"); // $NON-NLS-1$
   x.setType(DataTypeManager.DefaultDataClasses.CLOB);
   List<ElementSymbol> schema = Arrays.asList(x);
   TupleBuffer tb =
       BufferManagerFactory.getStandaloneBufferManager()
           .createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); // $NON-NLS-1$
   tb.setInlineLobs(false);
   ClobType c = new ClobType(new SerialClob(new char[0]));
   TupleBatch batch = new TupleBatch(1, new List[] {Arrays.asList(c)});
   tb.addTupleBatch(batch, false);
   assertNotNull(tb.getLobReference(c.getReferenceStreamId()));
 }
 private void handleUnresolvableDeclaration(ElementSymbol variable, String description)
     throws QueryResolverException {
   UnresolvedSymbolDescription symbol =
       new UnresolvedSymbolDescription(variable.toString(), description);
   QueryResolverException e = new QueryResolverException(symbol.getDescription());
   e.setUnresolvedSymbols(Arrays.asList(new Object[] {symbol}));
   throw e;
 }
 @Test
 public void testCreateTempTable1() {
   Create create = getFactory().newCreate();
   create.setTable(getFactory().newGroupSymbol("tempTable")); // $NON-NLS-1$
   List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
   ElementSymbol column = getFactory().newElementSymbol("c1"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.BOOLEAN.getTypeClass());
   columns.add(column);
   column = getFactory().newElementSymbol("c2"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.BYTE.getTypeClass());
   columns.add(column);
   create.setElementSymbolsAsColumns(columns);
   helpTest(
       "Create local TEMPORARY table tempTable (c1 boolean, c2 byte)",
       "CREATE LOCAL TEMPORARY TABLE tempTable (c1 boolean, c2 byte)",
       create); //$NON-NLS-1$ //$NON-NLS-2$
 }
Example #17
0
  private void helpTestNextBatch(int tupleBatchSize, Mode mode) throws Exception {

    ProjectIntoNode node = new ProjectIntoNode(2);

    TupleSource tupleSource = new FakeDataTupleSource(NUM_ROWS);
    RelationalNode child = new FakeRelationalNode(1, tupleSource, tupleBatchSize);
    node.addChild(child);
    node.setIntoGroup(new GroupSymbol("myGroup")); // $NON-NLS-1$
    ElementSymbol elementSymbol_1 = new ElementSymbol("myGroup.myElement1"); // $NON-NLS-1$
    ElementSymbol elementSymbol_2 = new ElementSymbol("myGroup.myElement2"); // $NON-NLS-1$
    elementSymbol_1.setType(Integer.class);
    elementSymbol_2.setType(String.class);
    List<ElementSymbol> elements = Arrays.asList(elementSymbol_1, elementSymbol_2);
    node.setIntoElements(elements);
    child.setElements(elements);
    node.setMode(mode);
    node.setModelName("myModel"); // $NON-NLS-1$

    CommandContext context = new CommandContext();
    BufferManager bm = BufferManagerFactory.getTestBufferManager(tupleBatchSize, tupleBatchSize);
    ProcessorDataManager dataManager = new FakePDM(tupleBatchSize);

    child.initialize(context, bm, dataManager);
    node.initialize(context, bm, dataManager);
    node.open();

    TupleBatch batch = null;
    // Do the remaining batches
    while (true) {
      try {
        batch = node.nextBatch();
        break;
      } catch (BlockedException e) {
        // Normal
      }
    }
    assertNotNull(batch);
    List[] tuples = batch.getAllTuples();
    assertEquals(1, tuples.length);
    Object[] columns = tuples[0].toArray();
    assertNotNull(columns);
    assertEquals(1, columns.length);
    // Should have inserted all rows
    assertEquals(new Integer(NUM_ROWS), columns[0]);
  }
Example #18
0
 @Test
 public void testCreateTempTableWithPrimaryKey() {
   Create create = new Create();
   create.setTable(new GroupSymbol("tempTable")); // $NON-NLS-1$
   List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
   ElementSymbol column = new ElementSymbol("c1"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
   columns.add(column);
   column = new ElementSymbol("c2"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BYTE);
   columns.add(column);
   create.setElementSymbolsAsColumns(columns);
   create.getPrimaryKey().add(column);
   helpTest(
       "Create local TEMPORARY table tempTable(c1 boolean, c2 byte, primary key (c2))",
       "CREATE LOCAL TEMPORARY TABLE tempTable (c1 boolean, c2 byte, PRIMARY KEY(c2))",
       create); //$NON-NLS-1$ //$NON-NLS-2$
 }
Example #19
0
 @Test
 public void testCreateTempTable1() {
   Create create = new Create();
   create.setTable(new GroupSymbol("tempTable")); // $NON-NLS-1$
   List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
   ElementSymbol column = new ElementSymbol("c1"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
   columns.add(column);
   column = new ElementSymbol("c2"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BYTE);
   columns.add(column);
   create.setElementSymbolsAsColumns(columns);
   create.setCommitAction(CommitAction.PRESERVE_ROWS);
   helpTest(
       "Create local TEMPORARY table tempTable (c1 boolean, c2 byte) on commit preserve rows",
       "CREATE LOCAL TEMPORARY TABLE tempTable (c1 boolean, c2 byte) ON COMMIT PRESERVE ROWS",
       create); //$NON-NLS-1$ //$NON-NLS-2$
 }
Example #20
0
 @Test
 public void testCreateTempTable2() {
   Create create = new Create();
   create.setTable(new GroupSymbol("tempTable")); // $NON-NLS-1$
   List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
   ElementSymbol column = new ElementSymbol("c1"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
   columns.add(column);
   column = new ElementSymbol("c2"); // $NON-NLS-1$
   column.setType(DataTypeManager.DefaultDataClasses.BYTE);
   columns.add(column);
   create.setElementSymbolsAsColumns(columns);
   create.getColumns().get(0).setNullType(NullType.No_Nulls);
   helpTest(
       "Create local TEMPORARY table tempTable(c1 boolean not null, c2 byte)",
       "CREATE LOCAL TEMPORARY TABLE tempTable (c1 boolean NOT NULL, c2 byte)",
       create); //$NON-NLS-1$ //$NON-NLS-2$
 }
Example #21
0
 public void process(ProcedurePlan procEnv) throws TeiidComponentException {
   List<?> currentRow = procEnv.getCurrentRow(rsName);
   VariableContext varContext = procEnv.getCurrentVariableContext();
   // set results to the variable context(the cursor.element is treated as variable)
   if (this.elements == null) {
     List schema = procEnv.getSchema(rsName);
     elements = new ArrayList<ElementSymbol>(schema.size());
     for (int i = 0; i < schema.size(); i++) {
       Expression element = (Expression) schema.get(i);
       ElementSymbol e =
           new ElementSymbol(rsName + Symbol.SEPARATOR + Symbol.getShortName(element));
       e.setType(element.getType());
       elements.add(e);
     }
   }
   for (int i = 0; i < elements.size(); i++) {
     varContext.setValue(elements.get(i), currentRow.get(i));
   }
 }
Example #22
0
 private void checkNotNull(ElementSymbol param, Object value)
     throws TeiidComponentException, QueryMetadataException, QueryValidatorException {
   if (metadata.elementSupports(param.getMetadataID(), SupportConstants.Element.NULL)) {
     return;
   }
   if (metadata.isVariadic(param.getMetadataID())) {
     if (value instanceof ArrayImpl) {
       ArrayImpl av = (ArrayImpl) value;
       for (Object o : av.getValues()) {
         if (o == null) {
           throw new QueryValidatorException(
               QueryPlugin.Event.TEIID30164,
               QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30164, param));
         }
       }
     }
   } else if (value == null) {
     throw new QueryValidatorException(
         QueryPlugin.Event.TEIID30164, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30164, param));
   }
 }
Example #23
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;
 }
 @Test
 public void testTypeAliases() {
   Create create = getFactory().newCreate();
   create.setTable(getFactory().newGroupSymbol("tempTable")); // $NON-NLS-1$
   List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
   ElementSymbol column = getFactory().newElementSymbol("c1"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.STRING.getTypeClass());
   columns.add(column);
   column = getFactory().newElementSymbol("c2"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.BYTE.getTypeClass());
   columns.add(column);
   column = getFactory().newElementSymbol("c3"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.SHORT.getTypeClass());
   columns.add(column);
   column = getFactory().newElementSymbol("c4"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.FLOAT.getTypeClass());
   columns.add(column);
   column = getFactory().newElementSymbol("c5"); // $NON-NLS-1$
   column.setType(DataTypeManagerService.DefaultDataTypes.BIG_DECIMAL.getTypeClass());
   columns.add(column);
   create.setElementSymbolsAsColumns(columns);
   helpTest(
       "Create local TEMPORARY table tempTable (c1 varchar, c2 tinyint, c3 smallint, c4 real, c5 decimal)",
       "CREATE LOCAL TEMPORARY TABLE tempTable (c1 varchar, c2 tinyint, c3 smallint, c4 real, c5 decimal)",
       create); //$NON-NLS-1$
 }
Example #25
0
  /**
   * @see
   *     org.teiid.query.resolver.VariableResolver#getVariableValues(org.teiid.query.sql.lang.Command,
   *     org.teiid.query.metadata.QueryMetadataInterface)
   */
  public Map<ElementSymbol, Expression> getVariableValues(
      Command command, boolean changingOnly, QueryMetadataInterface metadata)
      throws QueryMetadataException, TeiidComponentException {
    Map<ElementSymbol, Expression> result = new HashMap<ElementSymbol, Expression>();

    Update update = (Update) command;

    Map<ElementSymbol, Expression> changing = update.getChangeList().getClauseMap();

    for (Entry<ElementSymbol, Expression> entry : changing.entrySet()) {
      ElementSymbol leftSymbol = entry.getKey().clone();
      leftSymbol.getGroupSymbol().setName(ProcedureReservedWords.CHANGING);
      leftSymbol.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
      result.put(leftSymbol, new Constant(Boolean.TRUE));
      if (!changingOnly) {
        leftSymbol = entry.getKey().clone();
        leftSymbol.getGroupSymbol().setName(SQLConstants.Reserved.NEW);
        result.put(leftSymbol, entry.getValue());
      }
    }

    Collection<ElementSymbol> insertElmnts =
        ResolverUtil.resolveElementsInGroup(update.getGroup(), metadata);

    insertElmnts.removeAll(changing.keySet());

    Iterator<ElementSymbol> defaultIter = insertElmnts.iterator();
    while (defaultIter.hasNext()) {
      ElementSymbol varSymbol = defaultIter.next().clone();
      varSymbol.getGroupSymbol().setName(ProcedureReservedWords.CHANGING);
      varSymbol.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
      result.put(varSymbol, new Constant(Boolean.FALSE));
    }

    return result;
  }
Example #26
0
  public Object lookupCodeValue(
      CommandContext context,
      String codeTableName,
      String returnElementName,
      String keyElementName,
      Object keyValue)
      throws BlockedException, TeiidComponentException, TeiidProcessingException {
    // we are not using a resolved form of a lookup, so we canonicallize with upper case
    codeTableName = codeTableName.toUpperCase();
    keyElementName = keyElementName.toUpperCase();
    returnElementName = returnElementName.toUpperCase();
    String matTableName =
        CODE_PREFIX
            + codeTableName
            + ElementSymbol.SEPARATOR
            + keyElementName
            + ElementSymbol.SEPARATOR
            + returnElementName;

    TupleSource ts = context.getCodeLookup(matTableName, keyValue);
    if (ts == null) {
      QueryMetadataInterface metadata = context.getMetadata();

      TempMetadataID id =
          context
              .getGlobalTableStore()
              .getCodeTableMetadataId(
                  codeTableName, returnElementName, keyElementName, matTableName);

      ElementSymbol keyElement = new ElementSymbol(keyElementName, new GroupSymbol(matTableName));
      ElementSymbol returnElement =
          new ElementSymbol(returnElementName, new GroupSymbol(matTableName));
      keyElement.setType(
          DataTypeManager.getDataTypeClass(
              metadata.getElementType(
                  metadata.getElementID(
                      codeTableName + ElementSymbol.SEPARATOR + keyElementName))));
      returnElement.setType(
          DataTypeManager.getDataTypeClass(
              metadata.getElementType(
                  metadata.getElementID(
                      codeTableName + ElementSymbol.SEPARATOR + returnElementName))));

      Query query =
          RelationalPlanner.createMatViewQuery(
              id, matTableName, Arrays.asList(returnElement), true);
      query.setCriteria(
          new CompareCriteria(keyElement, CompareCriteria.EQ, new Constant(keyValue)));

      ts = registerQuery(context, context.getTempTableStore(), query);
    }
    try {
      List<?> row = ts.nextTuple();
      Object result = null;
      if (row != null) {
        result = row.get(0);
      }
      ts.closeSource();
      return result;
    } catch (BlockedException e) {
      context.putCodeLookup(matTableName, keyValue, ts);
      throw e;
    }
  }
Example #27
0
 private ElementSymbol exceptionSymbol(GroupSymbol gs, int pos) {
   ElementSymbol es = UpdateProcedureResolver.exceptionGroup.get(pos).clone();
   es.setGroupSymbol(gs);
   return es;
 }
Example #28
0
 static {
   ROWCOUNT.setType(DataTypeManager.DefaultDataClasses.INTEGER);
 }
  /**
   * @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());
 }