use of org.teiid.query.sql.lang.BatchedUpdateCommand in project teiid by teiid.
the class TestInsertProcessing method helpSelectInto_Case5569Processor.
public void helpSelectInto_Case5569Processor(boolean doBatching, boolean doBulkInsert) {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.BATCHED_UPDATES, doBatching);
caps.setCapabilitySupport(Capability.BULK_UPDATE, doBulkInsert);
caps.setCapabilitySupport(Capability.INSERT_WITH_ITERATOR, doBulkInsert);
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "1", new Integer(1), Boolean.FALSE, new Double(1) }), // $NON-NLS-1$
Arrays.asList(new Object[] { "2", new Integer(2), Boolean.TRUE, new Double(2) }) });
if (doBulkInsert) {
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES (...)", new List[] { Arrays.asList(1), Arrays.asList(1) });
} else if (doBatching) {
// $NON-NLS-1$
dataManager.addData(// $NON-NLS-1$
"BatchedUpdate{I,I}", new List[] { Arrays.asList(1), Arrays.asList(1) });
} 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 = "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 INTO pm1.g2 from pm1.g1";
Command command = helpParse(sql);
ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
List<?>[] expected = new List[] { Arrays.asList(new Object[] { new Integer(2) }) };
helpProcess(plan, dataManager, expected);
// check the command hist to ensure it contains the expected commands
if (!doBulkInsert && doBatching) {
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());
}
}
use of org.teiid.query.sql.lang.BatchedUpdateCommand 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());
}
}
Aggregations