use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestConnectorWorkItem method testLobs.
@Test
public void testLobs() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
final List<Object> result = Arrays.asList(AutoGenDataService.CLOB_VAL);
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 {
return new ResultSetExecution() {
private boolean returned;
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (returned) {
return null;
}
returned = true;
return result;
}
};
}
};
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 CLOB_COLUMN FROM LOB_TESTING_ONE", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] resutls = message.getResults();
List<?> tuple = resutls[0];
ClobType clob = (ClobType) tuple.get(0);
assertEquals(StorageMode.MEMORY, InputStreamFactory.getStorageMode(clob));
assertTrue(message.supportsImplicitClose());
result.set(0, AutoGenDataService.CLOB_VAL);
ef.setCopyLobs(false);
cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
message = cwi.more();
resutls = message.getResults();
tuple = resutls[0];
clob = (ClobType) tuple.get(0);
assertEquals(StorageMode.OTHER, InputStreamFactory.getStorageMode(clob));
assertFalse(message.supportsImplicitClose());
result.set(0, new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(new byte[0]);
}
@Override
public StorageMode getStorageMode() {
// TODO: introduce an explicit streaming
return StorageMode.FREE;
}
}, -1));
requestMsg.setCopyStreamingLobs(true);
cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
message = cwi.more();
resutls = message.getResults();
tuple = resutls[0];
clob = (ClobType) tuple.get(0);
// switched from FREE to PERSISTENT
assertEquals(StorageMode.PERSISTENT, InputStreamFactory.getStorageMode(clob));
assertFalse(message.supportsImplicitClose());
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestConnectorCapabilitiesFinder method testConverts.
@Test
public void testConverts() throws Exception {
ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@Override
public boolean supportsConvert(int fromType, int toType) {
return false;
}
@Override
public List<String> getSupportedFunctions() {
return Arrays.asList("convert");
}
};
ef.start();
// $NON-NLS-1$
BasicSourceCapabilities bsc = CapabilitiesConverter.convertCapabilities(ef, "conn");
// $NON-NLS-1$
assertTrue(bsc.supportsFunction("convert"));
assertFalse(bsc.supportsConvert(TypeFacility.RUNTIME_CODES.BIG_DECIMAL, TypeFacility.RUNTIME_CODES.BIG_INTEGER));
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestConnectorCapabilitiesFinder method testPushdownFunctionSupport.
@Test
public void testPushdownFunctionSupport() throws Exception {
ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@Override
public void start() throws TranslatorException {
super.start();
addPushDownFunction("ns", "func", DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING);
}
};
ef.start();
// $NON-NLS-1$
BasicSourceCapabilities bsc = CapabilitiesConverter.convertCapabilities(ef, "conn");
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue("Did not get expected capabilities", bsc.supportsFunction("ns.func"));
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestOptimizer method testParseFormat.
@Test
public void testParseFormat() throws Exception {
BasicSourceCapabilities caps = getTypicalCapabilities();
caps.setCapabilitySupport(Capability.ONLY_FORMAT_LITERALS, true);
caps.setFunctionSupport(SourceSystemFunctions.FORMATTIMESTAMP, true);
caps.setFunctionSupport(SourceSystemFunctions.PARSEBIGDECIMAL, true);
caps.setTranslator(new ExecutionFactory<Object, Object>() {
@Override
public boolean supportsFormatLiteral(String literal, org.teiid.translator.ExecutionFactory.Format format) {
return (format == Format.DATE && literal.equals("yyyy")) || (format == Format.NUMBER && literal.equals("$"));
}
});
ProcessorPlan plan = // $NON-NLS-1$
TestOptimizer.helpPlan(// $NON-NLS-1$
"SELECT stringkey from bqt1.smalla where formattimestamp(timestampvalue, 'yyyy') = '1921' and parsebigdecimal(stringkey, '$') = 1 and formattimestamp(timestampvalue, 'yy') = '19'", RealMetadataFactory.exampleBQTCached(), null, new DefaultCapabilitiesFinder(caps), new String[] { "SELECT g_0.TimestampValue, g_0.StringKey FROM BQT1.SmallA AS g_0 WHERE (formattimestamp(g_0.TimestampValue, 'yyyy') = '1921') AND (parsebigdecimal(g_0.StringKey, '$') = 1)" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
checkNodeTypes(plan, new int[] { // Access
1, // DependentAccess
0, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
0, // NestedLoopJoinStrategy
0, // MergeJoinStrategy
0, // Null
0, // PlanExecution
0, // Project
1, // Select
1, // Sort
0, // UnionAll
0 });
caps.setFunctionSupport(SourceSystemFunctions.PARSETIMESTAMP, true);
// test case sensitity
plan = // $NON-NLS-1$
TestOptimizer.helpPlan(// $NON-NLS-1$
"SELECT ParseTimeStamp(stringkey, 'yyyy') from bqt1.smalla where FormatTimestamp(timestampvalue, 'yyyy') = '1921'", RealMetadataFactory.exampleBQTCached(), null, new DefaultCapabilitiesFinder(caps), new String[] { "SELECT ParseTimeStamp(g_0.StringKey, 'yyyy') FROM BQT1.SmallA AS g_0 WHERE FormatTimestamp(g_0.TimestampValue, 'yyyy') = '1921'" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
checkNodeTypes(plan, FULL_PUSHDOWN);
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class VDBService method createConnectorManagers.
private void createConnectorManagers(ConnectorManagerRepository cmr, final TranslatorRepository repo, final VDBMetaData deployment) throws StartException {
final IdentityHashMap<Translator, ExecutionFactory<Object, Object>> map = new IdentityHashMap<Translator, ExecutionFactory<Object, Object>>();
try {
ConnectorManagerRepository.ExecutionFactoryProvider provider = new ConnectorManagerRepository.ExecutionFactoryProvider() {
@Override
public ExecutionFactory<Object, Object> getExecutionFactory(String name) throws ConnectorManagerException {
return TranslatorUtil.getExecutionFactory(name, repo, getTranslatorRepository(), deployment, map, new HashSet<String>());
}
};
cmr.setProvider(provider);
cmr.createConnectorManagers(deployment, provider);
} catch (ConnectorManagerException e) {
if (e.getCause() != null) {
// $NON-NLS-1$
throw new StartException(IntegrationPlugin.Event.TEIID50035.name() + " " + e.getMessage(), e.getCause());
}
throw new StartException(e.getMessage());
}
}
Aggregations