use of org.teiid.common.buffer.TupleSource in project teiid by teiid.
the class TestInsertProcessing method helpInsertIntoWithSubquery.
public void helpInsertIntoWithSubquery(Capability cap, boolean txn) throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(cap, true);
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
HardcodedDataManager dataManager = new HardcodedDataManager() {
@Override
public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
if (command instanceof Insert) {
Insert insert = (Insert) command;
if (insert.getTupleSource() != null) {
commandHistory.add(insert);
TupleSource ts = insert.getTupleSource();
int count = 0;
try {
while (ts.nextTuple() != null) {
count++;
}
return CollectionTupleSource.createUpdateCountArrayTupleSource(count);
} catch (TeiidProcessingException e) {
throw new RuntimeException(e);
}
}
}
return super.registerRequest(context, command, modelName, parameterObject);
}
};
List[] data = new List[txn ? 2 : 50];
for (int i = 1; i <= data.length; i++) {
data[i - 1] = Arrays.asList(String.valueOf(i), i, (i % 2 == 0) ? Boolean.TRUE : Boolean.FALSE, Double.valueOf(i));
}
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", data);
if (cap != null) {
switch(cap) {
case BATCHED_UPDATES:
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"BatchedUpdate{I,I}", new List[] { Arrays.asList(1), Arrays.asList(1) });
break;
case INSERT_WITH_QUERYEXPRESSION:
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"INSERT INTO pm1.g2 (e1, e2, e3, e4) SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", new List[] { Arrays.asList(new Object[] { 2 }) });
break;
}
} else {
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('1', 1, FALSE, 1.0)", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('2', 2, TRUE, 2.0)", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
}
// $NON-NLS-1$
String sql = "INSERT INTO pm1.g2 SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 from pm1.g1";
Command command = helpParse(sql);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
List<?>[] expected = new List[] { Arrays.asList(txn ? 2 : 50) };
CommandContext cc = TestProcessor.createCommandContext();
if (!txn) {
TransactionContext tc = new TransactionContext();
cc.setTransactionContext(tc);
cc.setBufferManager(null);
cc.setProcessorBatchSize(2);
}
helpProcess(plan, cc, dataManager, expected);
// check the command hist to ensure it contains the expected commands
if (cap == Capability.BATCHED_UPDATES) {
BatchedUpdateCommand bu = (BatchedUpdateCommand) dataManager.getCommandHistory().get(1);
assertEquals(2, bu.getUpdateCommands().size());
// $NON-NLS-1$
assertEquals("INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('1', 1, FALSE, 1.0)", bu.getUpdateCommands().get(0).toString());
// $NON-NLS-1$
assertEquals("INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('2', 2, TRUE, 2.0)", bu.getUpdateCommands().get(1).toString());
} else if (cap == Capability.INSERT_WITH_ITERATOR) {
assertEquals(txn ? 6 : 9, dataManager.getCommandHistory().size());
}
}
use of org.teiid.common.buffer.TupleSource in project teiid by teiid.
the class TestWithClauseProcessing method testWithBlockingJoin.
@Test
public void testWithBlockingJoin() throws TeiidException {
// $NON-NLS-1$
String sql = "with a (x, y) as /*+ no_inline */ (select e1, e2 from pm1.g1) SELECT a.x, a.y, pm1.g2.e1 from a left outer join pm1.g2 makenotdep on (rtrim(a.x) = pm1.g2.e1) order by a.y";
HardcodedDataManager dataManager = new HardcodedDataManager() {
@Override
public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
final TupleSource ts = super.registerRequest(context, command, modelName, parameterObject);
return new TupleSource() {
int i = 0;
@Override
public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
if ((i++ % 100) < 3) {
throw BlockedException.INSTANCE;
}
return ts.nextTuple();
}
@Override
public void closeSource() {
ts.closeSource();
}
};
}
};
List<?>[] rows = new List[10];
for (int i = 0; i < rows.length; i++) {
rows[i] = Arrays.asList(String.valueOf(i));
}
dataManager.addData("SELECT g_0.e1 AS c_0 FROM pm1.g2 AS g_0 ORDER BY c_0", rows);
rows = new List[100];
for (int i = 0; i < rows.length; i++) {
rows[i] = Arrays.asList(String.valueOf(i), i);
}
dataManager.addData("SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0", rows);
dataManager.addData("WITH a (x, y) AS (SELECT 1, 2 FROM g1 AS g_0) SELECT g_0.x AS c_0 FROM a AS g_0, a AS g_1 ORDER BY c_0", new List[0]);
ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(TestOptimizer.getTypicalCapabilities()), new String[] { "SELECT a.x, a.y FROM a", "SELECT g_0.e1 AS c_0 FROM pm1.g2 AS g_0 ORDER BY c_0" }, ComparisonMode.EXACT_COMMAND_STRING);
// check the full pushdown command
List<?>[] result = new List[100];
for (int i = 0; i < result.length; i++) {
result[i] = Arrays.asList(String.valueOf(i), i, i < 10 ? String.valueOf(i) : null);
}
helpProcess(plan, dataManager, result);
}
use of org.teiid.common.buffer.TupleSource 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.TupleSource in project teiid by teiid.
the class TestProjectIntoNode method helpTestNextBatch.
private void helpTestNextBatch(int tupleBatchSize, Mode mode) throws Exception {
ProjectIntoNode node = new ProjectIntoNode(2);
TupleSource tupleSource = new FakeDataTupleSource(NUM_ROWS);
RelationalNode child = new FakeRelationalNode(1, tupleSource, tupleBatchSize);
node.addChild(child);
// $NON-NLS-1$
node.setIntoGroup(new GroupSymbol("myGroup"));
// $NON-NLS-1$
ElementSymbol elementSymbol_1 = new ElementSymbol("myGroup.myElement1");
// $NON-NLS-1$
ElementSymbol elementSymbol_2 = new ElementSymbol("myGroup.myElement2");
elementSymbol_1.setType(Integer.class);
elementSymbol_2.setType(String.class);
List<ElementSymbol> elements = Arrays.asList(elementSymbol_1, elementSymbol_2);
node.setIntoElements(elements);
child.setElements(elements);
node.setMode(mode);
// $NON-NLS-1$
node.setModelName("myModel");
CommandContext context = new CommandContext();
BufferManager bm = BufferManagerFactory.getTestBufferManager(tupleBatchSize, tupleBatchSize);
ProcessorDataManager dataManager = new FakePDM(tupleBatchSize);
child.initialize(context, bm, dataManager);
node.initialize(context, bm, dataManager);
node.open();
TupleBatch batch = null;
// Do the remaining batches
while (true) {
try {
batch = node.nextBatch();
break;
} catch (BlockedException e) {
// Normal
}
}
assertNotNull(batch);
List[] tuples = batch.getAllTuples();
assertEquals(1, tuples.length);
Object[] columns = tuples[0].toArray();
assertNotNull(columns);
assertEquals(1, columns.length);
// Should have inserted all rows
assertEquals(new Integer(NUM_ROWS), columns[0]);
}
use of org.teiid.common.buffer.TupleSource in project teiid by teiid.
the class TestSortNode method testSortLimit.
@Test
public void testSortLimit() throws Exception {
// $NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("e1");
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
// $NON-NLS-1$
TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1, es1), "test", TupleSourceType.PROCESSOR);
tsid.addTuple(Arrays.asList(4));
tsid.addTuple(Arrays.asList(3));
tsid.addTuple(Arrays.asList(2));
tsid.addTuple(Arrays.asList(1));
tsid.close();
// $NON-NLS-1$
SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema());
su.setBatchSize(2);
TupleBuffer out = su.sort(2);
TupleSource ts = out.createIndexedTupleSource();
assertEquals(Arrays.asList(1), ts.nextTuple());
assertEquals(Arrays.asList(2), ts.nextTuple());
assertNull(ts.nextTuple());
// $NON-NLS-1$
su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema());
su.setBatchSize(10);
out = su.sort(2);
ts = out.createIndexedTupleSource();
assertEquals(Arrays.asList(1), ts.nextTuple());
assertEquals(Arrays.asList(2), ts.nextTuple());
assertNull(ts.nextTuple());
}
Aggregations