@Test
 public void testDeleteUnion() throws Exception {
   String userSql = "delete from vm1.gx where e4 is null"; // $NON-NLS-1$
   String viewSql =
       "select * from pm1.g1 where e3 < 5 union all select * from pm1.g2 where e1 > 1";
   String expectedSql = "BatchedUpdate{D,D}";
   BatchedUpdateCommand buc = (BatchedUpdateCommand) helpTest(userSql, viewSql, expectedSql, null);
   assertEquals(
       "DELETE FROM pm1.g2 WHERE (pm1.g2.e4 IS NULL) AND (e1 > '1')",
       buc.getUpdateCommands().get(1).toString());
 }
Пример #2
0
    public TupleSource registerRequest(
        CommandContext context,
        Command command,
        String modelName,
        RegisterRequestParameter parameterObject)
        throws TeiidComponentException, TeiidProcessingException {
      callCount++;

      int batchSize = 1;

      // ensure that we have the right kind of insert, and that the data for this row is valid
      if (command instanceof Insert) {
        Insert insert = (Insert) command;
        if (isBulk(insert)) {
          List batch = getBulkRows(insert, insert.getVariables());
          batchSize = batch.size();
          assertEquals(
              "Unexpected batch on call " + callCount, expectedBatchSize, batchSize); // $NON-NLS-1$

          for (int i = 0; i < batchSize; i++) {
            ensureValue2((List) batch.get(i), 2, ((callCount - 1) * batchSize) + i + 1);
          }
        } else if (insert.getTupleSource() != null) {
          TupleSource ts = insert.getTupleSource();
          List tuple = null;
          int i = 0;
          while ((tuple = ts.nextTuple()) != null) {
            ensureValue2(tuple, 2, ++i);
          }
          batchSize = i;
        } else {
          ensureValue(insert, 2, callCount);
        }
      } else if (command instanceof BatchedUpdateCommand) {
        BatchedUpdateCommand bu = (BatchedUpdateCommand) command;
        List<Command> batch = bu.getUpdateCommands();

        batchSize = batch.size();
        assertEquals(
            "Unexpected batch on call " + callCount, expectedBatchSize, batchSize); // $NON-NLS-1$
      } else {
        fail("Unexpected command type"); // $NON-NLS-1$
      }
      if (batchSize > 1) {
        return CollectionTupleSource.createUpdateCountArrayTupleSource(batchSize);
      }
      List counts = Arrays.asList(new Object[] {new Integer(batchSize)});
      FakeTupleSource fakeTupleSource = new FakeTupleSource(null, new List[] {counts});
      return fakeTupleSource;
    }