Package org.teiid.common.buffer

Examples of org.teiid.common.buffer.TupleBuffer


        // Run query
        BufferManager bufferMgr = createCustomBufferMgr(2);
        QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
        processor.setNonBlocking(true);
        BatchCollector collector = processor.createBatchCollector();
        TupleBuffer id = collector.collectTuples();

        TestProcessor.examineResults((List[])expected.toArray(new List[expected.size()]), bufferMgr, id);
    }
View Full Code Here


   
    @Test public void testDupRemove() throws Exception {
      ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$
        es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
        BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
        TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1), "test", TupleSourceType.PROCESSOR); //$NON-NLS-1$
        tsid.addTuple(Arrays.asList(1));
      SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.DUP_REMOVE, bm, "test", tsid.getSchema()); //$NON-NLS-1$
      TupleBuffer out = su.sort();
      TupleSource ts = out.createIndexedTupleSource();
      assertEquals(Arrays.asList(1), ts.nextTuple());
      try {
        ts.nextTuple();
        fail();
      } catch (BlockedException e) {
View Full Code Here

    String id = fqn.getLastElementAsString();
    int index = id.indexOf(',');
    if (index != -1) {
      String uuid = id.substring(0, index);
      int row = Integer.parseInt(id.substring(index+1));
      TupleBuffer tb = this.bufferMgr.getTupleBuffer(uuid);
      if (tb != null) {
        Map map = new HashMap();
        TupleBatch b = tb.getBatch(row);
        b.preserveTypes();
        map.put(id, b);
        return map;
      }
      return super.get(fqn);
View Full Code Here

    FakeBufferService fbs = new FakeBufferService();
   
    ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
    x.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List<ElementSymbol> schema = Arrays.asList(x);
    TupleBuffer tb = new TupleBuffer(new FakeBatchManager(), "x", schema, null, 4); //$NON-NLS-1$
    tb.setForwardOnly(false);
   
    tb.addTuple(Arrays.asList(1))
    tb.addTuple(Arrays.asList(2));
    tb.addTuple(Arrays.asList(3));
    tb.addTuple(Arrays.asList(4));
    tb.addTuple(Arrays.asList(5));
    tb.addTuple(Arrays.asList(6));
    tb.addTuple(Arrays.asList(7));
    tb.addTuple(Arrays.asList(8));
    tb.addTuple(Arrays.asList(9));
    tb.addTuple(Arrays.asList(10));
   
    tb.close();
   
    BufferManager bm = fbs.getBufferManager();
    CachedResults results = new CachedResults();
    ProcessorPlan plan = new FakeProcessorPlan(0);
    CommandContext cc = new CommandContext();
    Table t = RealMetadataFactory.exampleBQT().getGroupID("bqt1.smalla");
    cc.accessedDataObject(t);
    plan.setContext(cc);
    results.setResults(tb, plan);
    results.setCommand(new Query());
    Cache cache = new DefaultCache("dummy"); //$NON-NLS-1$
    long ts = results.getAccessInfo().getCreationTime();
    // simulate the jboss-cache remote transport, where the batches are remotely looked up
    // in cache
    for (int row=1; row<=tb.getRowCount();row+=4) {
      cache.put(results.getId()+","+row, tb.getBatch(row), null); //$NON-NLS-1$
    }
   
    results.prepare(cache, bm);
   
    CachedResults cachedResults = UnitTestUtil.helpSerialize(results);
   
    FakeMetadataFactory.buildWorkContext(RealMetadataFactory.exampleBQT());
   
    cachedResults.restore(cache, bm);
   
    // since restored, simulate a async cache flush
    cache.clear();
   
    TupleBuffer cachedTb = cachedResults.getResults();
   
    assertTrue(cachedTb.isFinal());
    assertEquals(tb.getRowCount(), cachedTb.getRowCount());
    assertEquals(tb.getBatchSize(), cachedTb.getBatchSize());
   
    assertArrayEquals(tb.getBatch(1).getAllTuples(), cachedTb.getBatch(1).getAllTuples());
    assertArrayEquals(tb.getBatch(9).getAllTuples(), cachedTb.getBatch(9).getAllTuples());
    assertTrue(ts - cachedResults.getAccessInfo().getCreationTime() <= 5000);
 
View Full Code Here

        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();
    }
View Full Code Here

    public TupleBuffer createTupleBuffer(final List elements, String groupName,
        TupleSourceType tupleSourceType) {
      final String newID = String.valueOf(this.tsId.getAndIncrement());
      int[] lobIndexes = LobManager.getLobIndexes(elements);
      BatchManager batchManager = new BatchManagerImpl(newID, elements.size(), lobIndexes);
        TupleBuffer tupleBuffer = new TupleBuffer(batchManager, newID, elements, lobIndexes, getProcessorBatchSize());
        LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Creating TupleBuffer:", newID, "of type ", tupleSourceType); //$NON-NLS-1$ //$NON-NLS-2$
        return tupleBuffer;
    }
View Full Code Here

    CacheID cid = new CacheID(new ParseInfo(), fullName + hash, context.getVdbName(),
        context.getVdbVersion(), context.getConnectionID(), context.getUserName());
    cid.setParameters(vals);
    CachedResults results = cache.get(cid);
    if (results != null) {
      TupleBuffer buffer = results.getResults();
      return buffer.createIndexedTupleSource();
    }
    //construct a query with a no cache hint
    //note that it's safe to use the stringified form of the parameters because
    //it's not possible to use xml/clob/blob/object
    CacheHint hint = proc.getCacheHint();
    proc.setCacheHint(null);
    Option option = new Option();
    option.setNoCache(true);
    option.addNoCacheGroup(fullName);
    proc.setOption(option);
    Determinism determinismLevel = context.resetDeterminismLevel();
    QueryProcessor qp = context.getQueryProcessorFactory().createQueryProcessor(proc.toString(), fullName.toUpperCase(), context);
    qp.setNonBlocking(true);
    qp.getContext().setDataObjects(null);
    BatchCollector bc = qp.createBatchCollector();
    TupleBuffer tb = bc.collectTuples();
    CachedResults cr = new CachedResults();
    cr.setResults(tb, qp.getProcessorPlan());
    cr.setHint(hint);
    if (hint != null && hint.getDeterminism() != null) {
      LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Cache hint modified the query determinism from ",determinismLevel, " to ", hint.getDeterminism() }); //$NON-NLS-1$ //$NON-NLS-2$
      determinismLevel = hint.getDeterminism();
    }
    cache.put(cid, determinismLevel, cr, hint != null?hint.getTtl():null);
    context.setDeterminismLevel(determinismLevel);
    return tb.createIndexedTupleSource();
  }
View Full Code Here

        qp.setNonBlocking(true);
        qp.getContext().setDataObjects(null);
        if (distributedCache != null) {
          CachedResults cr = new CachedResults();
          BatchCollector bc = qp.createBatchCollector();
          TupleBuffer tb = bc.collectTuples();
          cr.setResults(tb, qp.getProcessorPlan());
          touchTable(context, fullName, true);
          this.distributedCache.put(cid, Determinism.VDB_DETERMINISTIC, cr, info.getTtl());
          ts = tb.createIndexedTupleSource();
        } else {
          ts = new BatchCollector.BatchProducerTupleSource(qp);
        }
      }
     
View Full Code Here

    TupleBrowser browser = ii.createTupleBrowser();
    TupleSource ts = new QueryTupleSource(browser, columnMap, agg?getColumns():projectedCols, condition);
   
    boolean usingQueryTupleSource = false;
    try {
      TupleBuffer tb = null;
      if (ii.ordering == null && orderBy != null) {
        SortUtility sort = new SortUtility(ts, orderBy.getOrderByItems(), Mode.SORT, bm, sessionID, projectedCols);
        tb = sort.sort();
      } else if (agg) {
        int count = 0;
        while (ts.nextTuple() != null) {
          count++;
        }
        return new CollectionTupleSource(Arrays.asList(Collections.nCopies(projectedCols.size(), count)).iterator());
      } else if (updatable) {
        tb = bm.createTupleBuffer(projectedCols, sessionID, TupleSourceType.PROCESSOR);
        List<?> next = null;
        while ((next = ts.nextTuple()) != null) {
          tb.addTuple(next);
        }
      } else {
        usingQueryTupleSource = true;
        return ts;
      }
      tb.close();
      return tb.createIndexedTupleSource(true);
    } finally {
      if (!usingQueryTupleSource) {
        //ensure the buffers get released
        ts.closeSource();
      }
View Full Code Here

    private void helpProcessException(ProcessorPlan plan, ProcessorDataManager dataManager) {
        helpProcessException(plan, dataManager, null);
    }
   
    private void helpProcessException(ProcessorPlan plan, ProcessorDataManager dataManager, String expectedErrorMessage) {
      TupleBuffer tsId = null;
      BufferManager bufferMgr = null;
        try {  
            bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
            CommandContext context = new CommandContext("0", "test", null, null, 1); //$NON-NLS-1$ //$NON-NLS-2$
            QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
            processor.setNonBlocking(true);
            BatchCollector collector = processor.createBatchCollector();
            tsId = collector.collectTuples();
            fail("Expected error during processing, but got none."); //$NON-NLS-1$
        } catch(TeiidException e) {
            // ignore - this is expected
            if(expectedErrorMessage != null) {
                assertEquals(expectedErrorMessage, e.getMessage());
            }
        } finally {
          if (tsId != null) {
            tsId.remove();
          }
        }
    }
View Full Code Here

TOP

Related Classes of org.teiid.common.buffer.TupleBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.