use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TempTableDataManager method loadGlobalTable.
private TupleSource loadGlobalTable(final CommandContext context, final GroupSymbol group, final String tableName, final GlobalTableStore globalStore) throws TeiidComponentException, TeiidProcessingException {
LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30013, tableName));
final QueryMetadataInterface metadata = context.getMetadata();
final List<ElementSymbol> allColumns = ResolverUtil.resolveElementsInGroup(group, metadata);
final TempTable table = globalStore.createMatTable(tableName, group);
table.setUpdatable(false);
return new ProxyTupleSource() {
TupleSource insertTupleSource;
boolean success;
QueryProcessor qp;
boolean closed;
boolean errored;
@Override
protected TupleSource createTupleSource() throws TeiidComponentException, TeiidProcessingException {
long rowCount = -1;
try {
if (insertTupleSource == null) {
String fullName = metadata.getFullName(group.getMetadataID());
String transformation = metadata.getVirtualPlan(group.getMetadataID()).getQuery();
qp = context.getQueryProcessorFactory().createQueryProcessor(transformation, fullName, context);
insertTupleSource = new BatchCollector.BatchProducerTupleSource(qp);
}
table.insert(insertTupleSource, allColumns, false, false, null);
table.getTree().compact();
rowCount = table.getRowCount();
Determinism determinism = qp.getContext().getDeterminismLevel();
context.setDeterminismLevel(determinism);
// TODO: could pre-process indexes to remove overlap
for (Object index : metadata.getIndexesInGroup(group.getMetadataID())) {
List<ElementSymbol> columns = GlobalTableStoreImpl.resolveIndex(metadata, allColumns, index);
table.addIndex(columns, false);
}
for (Object key : metadata.getUniqueKeysInGroup(group.getMetadataID())) {
List<ElementSymbol> columns = GlobalTableStoreImpl.resolveIndex(metadata, allColumns, key);
table.addIndex(columns, true);
}
CacheHint hint = table.getCacheHint();
if (hint != null && table.getPkLength() > 0) {
table.setUpdatable(hint.isUpdatable(false));
}
if (determinism.compareTo(Determinism.VDB_DETERMINISTIC) < 0 && (hint == null || hint.getScope() == null || Scope.VDB.compareTo(hint.getScope()) <= 0)) {
// $NON-NLS-1$
LogManager.logInfo(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31143, determinism, tableName));
}
globalStore.loaded(tableName, table);
success = true;
LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30014, tableName, rowCount));
return CollectionTupleSource.createUpdateCountTupleSource((int) Math.min(Integer.MAX_VALUE, rowCount));
} catch (BlockedException e) {
throw e;
} catch (Exception e) {
errored = true;
if (executor == null || !executor.isShutdown()) {
// if we're shutting down, no need to log
LogManager.logError(LogConstants.CTX_MATVIEWS, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30015, tableName));
}
closeSource();
rethrow(e);
throw new AssertionError();
}
}
@Override
public void closeSource() {
if (closed) {
return;
}
if (!errored && !success) {
LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31153, tableName));
}
closed = true;
if (!success) {
globalStore.failedLoad(tableName);
table.remove();
}
if (qp != null) {
qp.closeProcessing();
}
super.closeSource();
}
};
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestBatchIterator method testNoSaveForwardOnly.
@Test
public void testNoSaveForwardOnly() throws Exception {
BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] { Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1) }, 2) {
@Override
public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
TupleBatch tb = super.nextBatchDirect();
tb.setRowOffset(tb.getBeginRow() + 3);
return tb;
}
});
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
TupleBuffer tb = bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x", null, DataTypeManager.DefaultDataClasses.INTEGER)), "test", TupleSourceType.PROCESSOR);
tb.setForwardOnly(true);
// $NON-NLS-1$
bi.setBuffer(tb, false);
tb.addTuple(Arrays.asList(2));
tb.addTuple(Arrays.asList(2));
tb.addTuple(Arrays.asList(2));
assertEquals(3, bi.getBuffer().getManagedRowCount());
bi.nextTuple();
// pull the first batch
assertEquals(2, bi.available());
assertEquals(0, bi.getBuffer().getManagedRowCount());
for (int i = 0; i < 2; i++) {
assertNotNull(bi.nextTuple());
assertEquals(0, bi.getBuffer().getManagedRowCount());
}
bi.readAhead(3);
assertEquals(2, bi.getBuffer().getManagedRowCount());
for (int i = 0; i < 4; i++) {
assertNotNull(bi.nextTuple());
assertEquals(0, bi.getBuffer().getManagedRowCount());
}
assertNull(bi.nextTuple());
assertEquals(0, bi.getBuffer().getManagedRowCount());
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestQueryProcessor method helpTestProcessor.
public void helpTestProcessor(FakeProcessorPlan plan, List[] expectedResults) throws TeiidException {
BufferManager bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
FakeDataManager dataManager = new FakeDataManager();
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("pid", "group", null, null, 1);
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
// $NON-NLS-1$
assertEquals("Did not get expected # of rows", expectedResults.length, tsID.getRowCount());
// 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];
// $NON-NLS-1$
assertEquals("Did not match row at row index " + i, expRecord, actRecord);
}
}
tsID.remove();
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestGroupingNode method helpProcess.
private void helpProcess(BufferManager mgr, GroupingNode node, CommandContext context, List[] expected, FakeTupleSource dataSource, ProcessorDataManager dataMgr) throws TeiidComponentException, BlockedException, TeiidProcessingException {
RelationalNode dataNode = new FakeRelationalNode(0, dataSource, mgr.getProcessorBatchSize());
dataNode.setElements(dataSource.getSchema());
node.addChild(dataNode);
node.initialize(context, mgr, dataMgr);
node.open();
int currentRow = 1;
while (true) {
try {
TupleBatch batch = node.nextBatch();
for (int row = currentRow; row <= batch.getEndRow(); row++) {
List tuple = batch.getTuple(row);
// $NON-NLS-1$
assertEquals("Rows don't match at " + row, expected[row - 1], tuple);
}
currentRow += batch.getRowCount();
if (batch.getTerminationFlag()) {
break;
}
} catch (BlockedException e) {
// ignore
}
}
assertEquals(expected.length, currentRow - 1);
}
use of org.teiid.common.buffer.BlockedException in project teiid by teiid.
the class TestJoinNode method testSortMergeWithDistinct.
@Test
public void testSortMergeWithDistinct() throws TeiidComponentException, TeiidProcessingException {
this.leftTuples = new List[] { Arrays.asList(1, 2), Arrays.asList(1, 3) };
this.rightTuples = new List[] { Arrays.asList(1, 4), Arrays.asList(1, 5) };
expected = new List[] { Arrays.asList(1, 2, 1, 4), Arrays.asList(1, 2, 1, 5), Arrays.asList(1, 3, 1, 4), Arrays.asList(1, 3, 1, 5) };
// $NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("e1");
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
// $NON-NLS-1$
ElementSymbol es2 = new ElementSymbol("e2");
es2.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List leftElements = Arrays.asList(es1, es2);
leftNode = new BlockingFakeRelationalNode(1, leftTuples);
leftNode.setElements(leftElements);
// $NON-NLS-1$
ElementSymbol es3 = new ElementSymbol("e3");
es3.setType(DataTypeManager.DefaultDataClasses.INTEGER);
// $NON-NLS-1$
ElementSymbol es4 = new ElementSymbol("e4");
es4.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List rightElements = Arrays.asList(es3, es4);
rightNode = new BlockingFakeRelationalNode(2, rightTuples) {
@Override
public boolean hasBuffer() {
return false;
}
@Override
public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
fail();
throw new AssertionError();
}
};
rightNode.setElements(rightElements);
List joinElements = new ArrayList();
joinElements.addAll(leftElements);
joinElements.addAll(rightElements);
joinType = JoinType.JOIN_INNER;
joinStrategy = new MergeJoinStrategy(SortOption.SORT_DISTINCT, SortOption.SORT_DISTINCT, false);
join = new JoinNode(3);
join.setElements(joinElements);
join.setJoinType(joinType);
join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es3));
join.setJoinStrategy(joinStrategy);
helpTestJoinDirect(expected, 100, 100000);
}
Aggregations