use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class DeferredMetadataProvider method loadFullMetadata.
private void loadFullMetadata() throws SQLException {
MetadataResult results;
try {
results = this.statement.getDQP().getMetadata(this.requestID);
} catch (TeiidComponentException e) {
throw TeiidSQLException.create(e);
} catch (TeiidProcessingException e) {
throw TeiidSQLException.create(e);
}
this.metadata = results.getColumnMetadata();
}
use of org.teiid.core.TeiidProcessingException in project teiid by teiid.
the class TestFunctionPushdown method testMustPushdownOverGrouping.
@Test
public void testMustPushdownOverGrouping() throws Exception {
TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign function func (param integer) returns integer; create foreign table g1 (e1 integer)", "x", "y");
BasicSourceCapabilities bsc = new BasicSourceCapabilities();
bsc.setCapabilitySupport(Capability.SELECT_WITHOUT_FROM, true);
bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
final DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
CommandContext cc = TestProcessor.createCommandContext();
cc.setQueryProcessorFactory(new QueryProcessor.ProcessorFactory() {
@Override
public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
return null;
}
@Override
public CapabilitiesFinder getCapabiltiesFinder() {
return capFinder;
}
@Override
public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
// TODO Auto-generated method stub
return null;
}
});
cc.setMetadata(tm);
// $NON-NLS-1$
String sql = "select func(e1) from g1 group by e1";
ProcessorPlan plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT y.g1.e1 FROM y.g1" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData("SELECT y.g1.e1 FROM y.g1", new List[] { Arrays.asList(1), Arrays.asList(2) });
dataManager.addData("SELECT func(1)", new List[] { Arrays.asList(2) });
dataManager.addData("SELECT func(2)", new List[] { Arrays.asList(3) });
TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(2), Arrays.asList(3) });
}
use of org.teiid.core.TeiidProcessingException 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.core.TeiidProcessingException 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.core.TeiidProcessingException in project teiid by teiid.
the class TestProcedureProcessor method testBeginAtomic.
@Test
public void testBeginAtomic() throws Exception {
String proc = // $NON-NLS-1$
"CREATE VIRTUAL PROCEDURE " + // $NON-NLS-1$
"BEGIN ATOMIC" + // $NON-NLS-1$
" select e1, e2, e3, e4 into #t1 from pm1.g1;\n" + // $NON-NLS-1$
" update #t1 set e1 = 1 where e4 < 2;\n" + // $NON-NLS-1$
" delete from #t1 where e4 > 2;\n" + // $NON-NLS-1$
" select e2/\"in\" from #t1;\n" + // $NON-NLS-1$
"END";
TransformationMetadata tm = RealMetadataFactory.example1();
addProc(tm, "sq1", proc, new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER }, new String[] { "in" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
FakeDataManager dataMgr = exampleDataManager(tm);
// $NON-NLS-1$
CommandContext context = new CommandContext("pID", null, null, null, 1);
QueryMetadataInterface metadata = new TempMetadataAdapter(tm, new TempMetadataStore());
context.setMetadata(metadata);
TransactionContext tc = new TransactionContext();
TransactionService ts = Mockito.mock(TransactionService.class);
context.setTransactionService(ts);
context.setTransactionContext(tc);
// $NON-NLS-1$
String userQuery = "EXEC pm1.sq1(1)";
ProcessorPlan plan = getProcedurePlan(userQuery, tm, TestOptimizer.getGenericFinder());
List[] expected = new List[] { Arrays.asList(5) };
TestProcessor.helpProcess(plan, context, dataMgr, expected);
Mockito.verify(ts, Mockito.times(3)).begin(tc);
Mockito.verify(ts, Mockito.times(3)).commit(tc);
tc = new TransactionContext();
ts = Mockito.mock(TransactionService.class);
context.setTransactionService(ts);
context.setTransactionContext(tc);
// $NON-NLS-1$
userQuery = "EXEC pm1.sq1(0)";
plan = getProcedurePlan(userQuery, tm, TestOptimizer.getGenericFinder());
expected = null;
try {
TestProcessor.helpProcess(plan, context, dataMgr, expected);
fail();
} catch (TeiidProcessingException e) {
}
Mockito.verify(ts).begin(tc);
Mockito.verify(ts, Mockito.times(2)).resume(tc);
Mockito.verify(ts, Mockito.times(0)).commit(tc);
Mockito.verify(ts).rollback(tc);
}
Aggregations