Exemplo n.º 1
0
  public void helpTestProcessor(FakeProcessorPlan plan, List[] expectedResults)
      throws TeiidException {
    BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
    FakeDataManager dataManager = new FakeDataManager();

    CommandContext context =
        new CommandContext("pid", "group", null, null, 1); // $NON-NLS-1$ //$NON-NLS-2$
    QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
    BatchCollector collector = processor.createBatchCollector();
    TupleBuffer tsID = null;
    while (true) {
      try {
        tsID = collector.collectTuples();
        break;
      } catch (BlockedException e) {
      }
    }

    // Compare # of rows in actual and expected
    assertEquals(
        "Did not get expected # of rows",
        expectedResults.length,
        tsID.getRowCount()); // $NON-NLS-1$

    // Compare actual with expected results
    TupleSource actual = tsID.createIndexedTupleSource();
    if (expectedResults.length > 0) {
      for (int i = 0; i < expectedResults.length; i++) {
        List actRecord = actual.nextTuple();
        List expRecord = expectedResults[i];
        assertEquals("Did not match row at row index " + i, expRecord, actRecord); // $NON-NLS-1$
      }
    }
    tsID.remove();
  }
Exemplo n.º 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;
    }
Exemplo n.º 3
0
 @Override
 public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
   if (actual == null) {
     actual = createTupleSource();
   }
   return actual.nextTuple();
 }
Exemplo n.º 4
0
 private void closeRequest() {
   if (this.buffer != null) {
     this.buffer.remove();
     this.buffer = null;
   }
   if (this.tupleSource != null) {
     tupleSource.closeSource();
     this.tupleSource = null;
   }
 }
Exemplo n.º 5
0
 private void checkExitConditions()
     throws TeiidComponentException, BlockedException, TeiidProcessingException {
   if (tupleSource != null) {
     Integer count = (Integer) tupleSource.nextTuple().get(0);
     insertCount += count.intValue();
     closeRequest();
     // Mark as processed
     tupleSourcesProcessed++; // This should set tupleSourcesProcessed to be the same as
     // requestsRegistered
   }
   // RESPONSE_PROCESSING: process tuple sources
   if (tupleSourcesProcessed < requestsRegistered) {
     throw BlockedException.block(
         getContext().getRequestId(), "Blocking on insert update count"); // $NON-NLS-1$
   }
 }
Exemplo n.º 6
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;
    }
  }
Exemplo n.º 7
0
 @Override
 public void closeSource() {
   if (actual != null) {
     actual.closeSource();
   }
 }