use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestNativeCassandra method testDirect.
@Test
public void testDirect() throws TranslatorException {
CassandraExecutionFactory cef = new CassandraExecutionFactory();
cef.setSupportsDirectQueryProcedure(true);
String input = "call native('select $1', 'a')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
CassandraConnection connection = Mockito.mock(CassandraConnection.class);
ResultSetFuture rsf = Mockito.mock(ResultSetFuture.class);
Mockito.stub(rsf.isDone()).toReturn(true);
ResultSet rs = Mockito.mock(ResultSet.class);
Mockito.stub(rsf.getUninterruptibly()).toReturn(rs);
Row row = Mockito.mock(Row.class);
ColumnDefinitions cd = Mockito.mock(ColumnDefinitions.class);
Mockito.stub(row.getColumnDefinitions()).toReturn(cd);
Mockito.stub(rs.one()).toReturn(row).toReturn(null);
Mockito.stub(connection.executeQuery("select 'a'")).toReturn(rsf);
ResultSetExecution execution = (ResultSetExecution) cef.createExecution(command, ec, rm, connection);
execution.execute();
List<?> vals = execution.next();
assertTrue(vals.get(0) instanceof Object[]);
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestSimpleDBExecution method testSelect.
@Test
public void testSelect() throws Exception {
SelectResult result = new SelectResult();
result.setItems(mockResult());
String query = "select * from item where attribute > 'name'";
Mockito.stub(connection.performSelect(Mockito.anyString(), Mockito.anyString())).toReturn(result);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
Mockito.stub(context.getBatchSize()).toReturn(10);
ResultSetExecution exec = translator.createResultSetExecution((Select) cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
exec.next();
Mockito.verify(connection).performSelect("SELECT attribute, somedate, strarray FROM item WHERE attribute > 'name' LIMIT 10", null);
// cap at 2500
Mockito.stub(context.getBatchSize()).toReturn(4000);
exec = translator.createResultSetExecution((Select) cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
exec.next();
Mockito.verify(connection).performSelect("SELECT attribute, somedate, strarray FROM item WHERE attribute > 'name' LIMIT 2500", null);
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestConnectorWorkItem method testConversionError.
@Test
public void testConversionError() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
List<String> list1 = new ArrayList<String>();
list1.add("1");
List<String> list2 = new ArrayList<String>();
list2.add("a");
final Iterator<List<String>> iter = Arrays.asList(list1, list2).iterator();
return new ResultSetExecution() {
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (iter.hasNext()) {
return iter.next();
}
return null;
}
};
}
};
ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector") {
public ExecutionFactory getExecutionFactory() {
return ef;
}
public Object getConnectionFactory() {
return null;
}
};
cm.start();
ef.setCopyLobs(true);
AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
// $NON-NLS-1$
requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] results = message.getResults();
assertEquals(1, results.length);
List<?> tuple = results[0];
assertEquals(1, tuple.get(0));
assertEquals(-1, message.getFinalRow());
try {
cwi.more();
fail();
} catch (TranslatorException e) {
// should throw the conversion error
}
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestConnectorWorkItem method testUnmodifibleList.
@Test
public void testUnmodifibleList() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
List<String> list1 = Collections.singletonList("1");
final Iterator<List<String>> iter = Arrays.asList(list1).iterator();
return new ResultSetExecution() {
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (iter.hasNext()) {
return iter.next();
}
return null;
}
};
}
};
ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector") {
public ExecutionFactory getExecutionFactory() {
return ef;
}
public Object getConnectionFactory() {
return null;
}
};
cm.start();
AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
// $NON-NLS-1$
requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] results = message.getResults();
assertEquals(1, results.length);
List<?> tuple = results[0];
assertEquals(1, tuple.get(0));
assertEquals(1, message.getFinalRow());
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class ConnectorHost method readResultsFromExecution.
private List<List> readResultsFromExecution(Execution execution) throws TranslatorException {
List<List> results = new ArrayList<List>();
while (true) {
try {
if (execution instanceof ResultSetExecution) {
ResultSetExecution rs = (ResultSetExecution) execution;
List result = null;
while ((result = rs.next()) != null) {
results.add(result);
}
break;
}
UpdateExecution rs = (UpdateExecution) execution;
int[] result = rs.getUpdateCounts();
for (int i = 0; i < result.length; i++) {
results.add(Arrays.asList(result[i]));
}
break;
} catch (DataNotAvailableException e) {
if (e.getRetryDelay() > 0) {
try {
Thread.sleep(e.getRetryDelay());
} catch (InterruptedException e1) {
throw new TranslatorException(e1);
}
}
}
}
return results;
}
Aggregations