Search in sources :

Example 21 with BufferManagerImpl

use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.

the class TestDQPCore method testSerialThreadBoundClose.

@Test
public void testSerialThreadBoundClose() throws Exception {
    agds.setSleep(100);
    agds.threadBound = true;
    core.setUserRequestSourceConcurrency(1);
    // $NON-NLS-1$
    String sql = "SELECT IntKey FROM BQT1.SmallA";
    // $NON-NLS-1$
    String userName = "logon";
    ((BufferManagerImpl) core.getBufferManager()).setProcessorBatchSize(1);
    RequestMessage reqMsg = exampleRequestMessage(sql);
    // execute by don't finish the work
    execute(userName, 1, reqMsg);
    // make sure the source request is still closed
    assertEquals(1, agds.getCloseCount().get());
}
Also used : BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) RequestMessage(org.teiid.client.RequestMessage) Test(org.junit.Test)

Example 22 with BufferManagerImpl

use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.

the class TestDQPCore method testBufferLimit.

@Test
public void testBufferLimit() throws Exception {
    // the sql should return 400 rows
    // $NON-NLS-1$
    String sql = "SELECT A.IntKey FROM BQT1.SmallA as A, BQT1.SmallA as B, (select intkey from BQT1.SmallA limit 4) as C";
    // $NON-NLS-1$
    String userName = "1";
    // $NON-NLS-1$
    String sessionid = "1";
    RequestMessage reqMsg = exampleRequestMessage(sql);
    reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
    DQPWorkContext.getWorkContext().getSession().setSessionId(sessionid);
    DQPWorkContext.getWorkContext().getSession().setUserName(userName);
    ((BufferManagerImpl) core.getBufferManager()).setProcessorBatchSize(1);
    Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
    ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
    assertNull(rm.getException());
    int rowsPerBatch = 8;
    assertEquals(rowsPerBatch, rm.getResultsList().size());
    RequestWorkItem item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
    message = core.processCursorRequest(reqMsg.getExecutionId(), 9, rowsPerBatch);
    rm = message.get(500000, TimeUnit.MILLISECONDS);
    assertNull(rm.getException());
    assertEquals(rowsPerBatch, rm.getResultsList().size());
    // ensure that we are idle
    for (int i = 0; i < 10 && item.getThreadState() != ThreadState.IDLE; i++) {
        Thread.sleep(100);
    }
    assertEquals(ThreadState.IDLE, item.getThreadState());
    assertTrue(item.resultsBuffer.getManagedRowCount() <= rowsPerBatch * 23);
    // pull the rest of the results
    int start = 17;
    while (true) {
        item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
        message = core.processCursorRequest(reqMsg.getExecutionId(), start, rowsPerBatch);
        rm = message.get(5000, TimeUnit.MILLISECONDS);
        assertNull(rm.getException());
        assertTrue(rowsPerBatch >= rm.getResultsList().size());
        start += rm.getResultsList().size();
        if (rm.getFinalRow() == rm.getLastRow()) {
            break;
        }
    }
    // insensitive should not block
    reqMsg.setCursorType(ResultSet.TYPE_SCROLL_INSENSITIVE);
    reqMsg.setExecutionId(id++);
    message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
    rm = message.get(500000, TimeUnit.MILLISECONDS);
    assertNull(rm.getException());
    assertEquals(rowsPerBatch, rm.getResultsList().size());
    item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
    message = core.processCursorRequest(reqMsg.getExecutionId(), 9, rowsPerBatch);
    rm = message.get(500000, TimeUnit.MILLISECONDS);
    assertNull(rm.getException());
    assertEquals(rowsPerBatch, rm.getResultsList().size());
    // ensure that we are idle
    for (int i = 0; i < 10 && item.getThreadState() != ThreadState.IDLE; i++) {
        Thread.sleep(100);
    }
    assertEquals(ThreadState.IDLE, item.getThreadState());
    // should buffer the same as forward only until a further batch is requested
    assertTrue(item.resultsBuffer.getManagedRowCount() <= rowsPerBatch * 23);
    // local should not buffer
    reqMsg = exampleRequestMessage(sql);
    reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
    reqMsg.setSync(true);
    message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
    rm = message.get(0, TimeUnit.MILLISECONDS);
    assertNull(rm.getException());
    assertEquals(rowsPerBatch, rm.getResultsList().size());
    item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));
    assertEquals(0, item.resultsBuffer.getManagedRowCount());
    assertEquals(8, item.resultsBuffer.getRowCount());
}
Also used : BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) ResultsMessage(org.teiid.client.ResultsMessage) RequestMessage(org.teiid.client.RequestMessage) Test(org.junit.Test)

Example 23 with BufferManagerImpl

use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.

the class TestDQPCore method testUsingFinalBuffer.

@Test
public void testUsingFinalBuffer() throws Exception {
    String sql = "select intkey from bqt1.smalla order by intkey";
    ((BufferManagerImpl) core.getBufferManager()).setProcessorBatchSize(2);
    agds.sleep = 50;
    RequestMessage reqMsg = exampleRequestMessage(sql);
    Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
    ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
    assertNull(rm.getException());
    assertEquals(10, rm.getResultsList().size());
    message = core.processCursorRequest(reqMsg.getExecutionId(), 3, 2);
    rm = message.get(500000, TimeUnit.MILLISECONDS);
    assertNull(rm.getException());
    assertEquals(2, rm.getResultsList().size());
}
Also used : BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) ResultsMessage(org.teiid.client.ResultsMessage) RequestMessage(org.teiid.client.RequestMessage) Test(org.junit.Test)

Example 24 with BufferManagerImpl

use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.

the class TestDQPCore method testBufferReuse1.

@Test
public void testBufferReuse1() throws Exception {
    // the sql should return 100 rows
    String sql = "SELECT IntKey FROM texttable('1112131415' columns intkey integer width 2 no row delimiter) t " + "union " + // $NON-NLS-1$
    "SELECT IntKey FROM bqt1.smalla order by intkey";
    // $NON-NLS-1$
    String userName = "1";
    // $NON-NLS-1$
    String sessionid = "1";
    agds.sleep = 50;
    agds.setUseIntCounter(true);
    RequestMessage reqMsg = exampleRequestMessage(sql);
    reqMsg.setRowLimit(11);
    reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY);
    DQPWorkContext.getWorkContext().getSession().setSessionId(sessionid);
    DQPWorkContext.getWorkContext().getSession().setUserName(userName);
    BufferManagerImpl bufferManager = (BufferManagerImpl) core.getBufferManager();
    bufferManager.setProcessorBatchSize(20);
    Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
    ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS);
    assertNull(rm.getException());
    assertEquals(10, rm.getResultsList().size());
    message = core.processCursorRequest(reqMsg.getExecutionId(), 6, 5);
    rm = message.get(500000, TimeUnit.MILLISECONDS);
    assertNull(rm.getException());
    assertEquals(5, rm.getResultsList().size());
    message = core.processCursorRequest(reqMsg.getExecutionId(), 11, 5);
    rm = message.get(500000, TimeUnit.MILLISECONDS);
    assertNull(rm.getException());
    assertEquals(1, rm.getResultsList().size());
    assertEquals(11, rm.getFirstRow());
    assertEquals(11, rm.getFinalRow());
}
Also used : BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) ResultsMessage(org.teiid.client.ResultsMessage) RequestMessage(org.teiid.client.RequestMessage) Test(org.junit.Test)

Example 25 with BufferManagerImpl

use of org.teiid.common.buffer.impl.BufferManagerImpl in project teiid by teiid.

the class TestOrderByProcessing method testDefaultNullOrdering.

@Test
public void testDefaultNullOrdering() throws Exception {
    // $NON-NLS-1$
    String sql = "select e1 from pm1.g1 order by e1";
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    CommandContext cc = createCommandContext();
    BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
    bm.setOptions(new Options().defaultNullOrder(NullOrder.FIRST));
    cc.setBufferManager(bm);
    ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, new DefaultCapabilitiesFinder(), cc);
    HardcodedDataManager manager = new HardcodedDataManager(metadata);
    manager.addData("SELECT g1.e1 FROM g1", new List[] { Arrays.asList("a"), Arrays.asList("b"), Arrays.asList((String) null) });
    helpProcess(plan, cc, manager, new List[] { Arrays.asList((String) null), Arrays.asList("a"), Arrays.asList("b") });
    plan = helpGetPlan(helpParse("select e1 from pm1.g1 order by e1 desc"), metadata, new DefaultCapabilitiesFinder(), cc);
    helpProcess(plan, cc, manager, new List[] { Arrays.asList((String) null), Arrays.asList("b"), Arrays.asList("a") });
    bm.getOptions().setDefaultNullOrder(NullOrder.LAST);
    plan = helpGetPlan(helpParse("select e1 from pm1.g1 order by e1 desc"), metadata, new DefaultCapabilitiesFinder(), cc);
    helpProcess(plan, cc, manager, new List[] { Arrays.asList("b"), Arrays.asList("a"), Arrays.asList((String) null) });
    bm.getOptions().setDefaultNullOrder(NullOrder.HIGH);
    plan = helpGetPlan(helpParse("select e1 from pm1.g1 order by e1"), metadata, new DefaultCapabilitiesFinder(), cc);
    helpProcess(plan, cc, manager, new List[] { Arrays.asList("a"), Arrays.asList("b"), Arrays.asList((String) null) });
}
Also used : Options(org.teiid.query.util.Options) CommandContext(org.teiid.query.util.CommandContext) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Aggregations

BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)34 Test (org.junit.Test)24 CommandContext (org.teiid.query.util.CommandContext)13 List (java.util.List)11 ArrayList (java.util.ArrayList)8 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)8 RequestMessage (org.teiid.client.RequestMessage)6 ResultsMessage (org.teiid.client.ResultsMessage)5 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)5 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)4 TupleSource (org.teiid.common.buffer.TupleSource)3 BufferFrontedFileStoreCache (org.teiid.common.buffer.impl.BufferFrontedFileStoreCache)3 FileStorageManager (org.teiid.common.buffer.impl.FileStorageManager)3 RegisterRequestParameter (org.teiid.query.processor.RegisterRequestParameter)3 Command (org.teiid.query.sql.lang.Command)3 BufferServiceImpl (org.teiid.services.BufferServiceImpl)3 HashMap (java.util.HashMap)2 BlockedException (org.teiid.common.buffer.BlockedException)2 BufferManager (org.teiid.common.buffer.BufferManager)2 TupleBatch (org.teiid.common.buffer.TupleBatch)2