use of org.teiid.common.buffer.TupleSource in project teiid by teiid.
the class TestDataTierManager method testCaching.
@Test
public void testCaching() throws Exception {
assertEquals(0, connectorManager.getExecuteCount().get());
QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
CacheDirective cd = new CacheDirective();
this.connectorManager.cacheDirective = cd;
helpSetupDataTierManager();
Command command = helpSetupRequest("SELECT stringkey from bqt1.smalla", 1, metadata).getCommand();
RegisterRequestParameter rrp = new RegisterRequestParameter();
rrp.connectorBindingId = "x";
TupleSource ts = dtm.registerRequest(context, command, "foo", rrp);
assertTrue(ts instanceof CachingTupleSource);
assertEquals(10, pullTuples(ts, -1));
assertEquals(1, connectorManager.getExecuteCount().get());
assertFalse(rrp.doNotCache);
assertFalse(((CachingTupleSource) ts).dtts.errored);
assertNull(((CachingTupleSource) ts).dtts.scope);
ts.closeSource();
assertEquals(1, this.rm.getRsCache().getCachePutCount());
assertEquals(1, this.rm.getRsCache().getTotalCacheEntries());
// same session, should be cached
command = helpSetupRequest("SELECT stringkey from bqt1.smalla", 1, metadata).getCommand();
rrp = new RegisterRequestParameter();
rrp.connectorBindingId = "x";
ts = dtm.registerRequest(context, command, "foo", rrp);
assertFalse(ts instanceof CachingTupleSource);
assertEquals(10, pullTuples(ts, -1));
assertEquals(1, connectorManager.getExecuteCount().get());
assertTrue(rrp.doNotCache);
// switch sessions
command = helpSetupRequest("SELECT stringkey from bqt1.smalla", 1, metadata).getCommand();
this.context.getSession().setSessionId("different");
rrp = new RegisterRequestParameter();
rrp.connectorBindingId = "x";
ts = dtm.registerRequest(context, command, "foo", rrp);
assertTrue(ts instanceof CachingTupleSource);
assertEquals(9, pullTuples(ts, 9));
assertEquals(2, connectorManager.getExecuteCount().get());
assertFalse(rrp.doNotCache);
// should force read all
ts.closeSource();
assertFalse(((CachingTupleSource) ts).dtts.errored);
assertNull(((CachingTupleSource) ts).dtts.scope);
assertEquals(2, this.rm.getRsCache().getCachePutCount());
assertEquals(2, this.rm.getRsCache().getTotalCacheEntries());
// proactive invalidation, removes immediately
command = helpSetupRequest("SELECT stringkey from bqt1.smalla", 1, metadata).getCommand();
cd.setInvalidation(Invalidation.IMMEDIATE);
rrp = new RegisterRequestParameter();
rrp.connectorBindingId = "x";
ts = dtm.registerRequest(context, command, "foo", rrp);
assertTrue(ts instanceof CachingTupleSource);
assertEquals(10, pullTuples(ts, -1));
assertEquals(3, connectorManager.getExecuteCount().get());
assertFalse(rrp.doNotCache);
}
use of org.teiid.common.buffer.TupleSource in project teiid by teiid.
the class TestSubqueryPushdown method testSubqueryProducingBuffer.
@Test
public void testSubqueryProducingBuffer() throws Exception {
TransformationMetadata tm = RealMetadataFactory.example1Cached();
String sql = "SELECT e1, (select e2 from pm2.g1 where e1 = pm1.g1.e1 order by e2 limit 1) from pm1.g1 limit 1";
BasicSourceCapabilities bsc = getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
ProcessorPlan plan = // $NON-NLS-1$
TestOptimizer.helpPlan(// $NON-NLS-1$
sql, tm, null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager hdm = new HardcodedDataManager(tm) {
@Override
public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
if (command.toString().equals("SELECT g_0.e2 FROM pm2.g1 AS g_0 WHERE g_0.e1 = 'a'")) {
return new TupleSource() {
@Override
public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
throw new TeiidProcessingException("something's wrong");
}
@Override
public void closeSource() {
}
};
}
return super.registerRequest(context, command, modelName, parameterObject);
}
};
hdm.addData("SELECT g_0.e1 FROM g1 AS g_0", Arrays.asList("a"));
hdm.setBlockOnce(true);
CommandContext cc = TestProcessor.createCommandContext();
cc.setMetadata(tm);
try {
TestProcessor.helpProcess(plan, cc, hdm, new List[] { Arrays.asList(2) });
fail();
} catch (TeiidProcessingException e) {
assert (e.getMessage().contains("something's wrong"));
}
}
use of org.teiid.common.buffer.TupleSource in project teiid by teiid.
the class SortNode method sortPhase.
private void sortPhase() throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (this.sortUtility == null) {
TupleSource ts = null;
TupleBuffer working = null;
if (!getChildren()[0].hasBuffer()) {
ts = new BatchIterator(getChildren()[0]);
} else {
working = getChildren()[0].getBuffer(-1);
}
this.sortUtility = new SortUtility(ts, items, this.mode, getBufferManager(), getConnectionID(), getChildren()[0].getElements());
if (ts == null) {
this.sortUtility.setWorkingBuffer(working);
}
}
this.output = this.sortUtility.sort(rowLimit);
if (this.outputTs == null) {
this.outputTs = this.output.createIndexedTupleSource();
}
this.phase = OUTPUT;
}
use of org.teiid.common.buffer.TupleSource in project teiid by teiid.
the class SortingFilter method getResult.
/**
* @throws TeiidProcessingException
* @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext)
*/
public Object getResult(CommandContext commandContext) throws TeiidComponentException, TeiidProcessingException {
if (collectionBuffer != null) {
this.collectionBuffer.close();
// Sort
if (sortUtility == null) {
sortUtility = new SortUtility(null, sortItems, removeDuplicates ? Mode.DUP_REMOVE_SORT : Mode.SORT, mgr, groupName, collectionBuffer.getSchema());
collectionBuffer.setForwardOnly(true);
this.sortUtility.setWorkingBuffer(collectionBuffer);
}
TupleBuffer sorted = sortUtility.sort();
sorted.setForwardOnly(true);
try {
// Add all input to proxy
TupleSource sortedSource = sorted.createIndexedTupleSource();
while (true) {
List<?> tuple = sortedSource.nextTuple();
if (tuple == null) {
break;
}
// TODO should possibly remove the order by columns from this tuple
this.proxy.addInputDirect(tuple, commandContext);
}
} finally {
sorted.remove();
}
close();
}
// Return
return this.proxy.getResult(commandContext);
}
use of org.teiid.common.buffer.TupleSource in project teiid by teiid.
the class AccessNode method nextBatchDirect.
public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (!open) {
// -- blocked during actual open
openInternal();
open = true;
}
if (multiSource && connectorBindingExpression == null) {
return this.getChildren()[0].nextBatch();
}
while (shouldExecute && (!tupleSources.isEmpty() || hasNextCommand())) {
if (tupleSources.isEmpty() && processCommandsIndividually()) {
registerNext();
}
// drain the tuple source(s)
for (int i = 0; i < this.tupleSources.size(); i++) {
TupleSource tupleSource = tupleSources.get(i);
try {
List<?> tuple = null;
while ((tuple = tupleSource.nextTuple()) != null) {
returnedRows = true;
if (this.projection != null && this.projection.length > 0) {
List<Object> newTuple = new ArrayList<Object>(this.projection.length);
for (Object object : this.projection) {
if (object instanceof Integer) {
newTuple.add(tuple.get((Integer) object));
} else {
newTuple.add(((Constant) object).getValue());
}
}
tuple = newTuple;
}
addBatchRow(tuple);
if (isBatchFull()) {
return pullBatch();
}
}
// end of source
tupleSource.closeSource();
tupleSources.remove(i--);
if (reserved > 0) {
reserved -= schemaSize;
getBufferManager().releaseBuffers(schemaSize);
}
if (!processCommandsIndividually()) {
registerNext();
}
continue;
} catch (BlockedException e) {
if (processCommandsIndividually()) {
if (hasPendingRows()) {
return pullBatch();
}
throw e;
}
continue;
}
}
if (processCommandsIndividually()) {
if (hasPendingRows()) {
return pullBatch();
}
continue;
}
if (!this.tupleSources.isEmpty()) {
if (hasPendingRows()) {
return pullBatch();
}
// $NON-NLS-1$
throw BlockedException.block(getContext().getRequestId(), "Blocking on source request(s).");
}
}
if (isUpdate && !returnedRows) {
List<Integer> tuple = new ArrayList<Integer>(1);
tuple.add(Integer.valueOf(0));
// Add tuple to current batch
addBatchRow(tuple);
}
terminateBatches();
return pullBatch();
}
Aggregations