Search in sources :

Example 11 with ExecutionFactory

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());
}
Also used : ExecutionFactory(org.teiid.translator.ExecutionFactory) BufferManager(org.teiid.common.buffer.BufferManager) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) InputStreamFactory(org.teiid.core.types.InputStreamFactory) ClobType(org.teiid.core.types.ClobType) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) List(java.util.List) ArrayList(java.util.ArrayList) QueryExpression(org.teiid.language.QueryExpression) ClobImpl(org.teiid.core.types.ClobImpl) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Example 12 with ExecutionFactory

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));
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ExecutionFactory(org.teiid.translator.ExecutionFactory) Test(org.junit.Test)

Example 13 with ExecutionFactory

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"));
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ExecutionFactory(org.teiid.translator.ExecutionFactory) Test(org.junit.Test)

Example 14 with ExecutionFactory

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);
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) LanguageObject(org.teiid.query.sql.LanguageObject) ExecutionFactory(org.teiid.translator.ExecutionFactory) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 15 with ExecutionFactory

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());
    }
}
Also used : ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) Translator(org.teiid.adminapi.Translator) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) IdentityHashMap(java.util.IdentityHashMap) ExecutionFactory(org.teiid.translator.ExecutionFactory) StartException(org.jboss.msc.service.StartException)

Aggregations

ExecutionFactory (org.teiid.translator.ExecutionFactory)29 Test (org.junit.Test)18 TranslatorException (org.teiid.translator.TranslatorException)11 ExecutionContext (org.teiid.translator.ExecutionContext)9 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)8 ResultSetExecution (org.teiid.translator.ResultSetExecution)8 List (java.util.List)7 QueryExpression (org.teiid.language.QueryExpression)7 ArrayList (java.util.ArrayList)6 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)6 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)6 MetadataFactory (org.teiid.metadata.MetadataFactory)6 Connection (java.sql.Connection)5 VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)5 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)5 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 OracleExecutionFactory (org.teiid.translator.jdbc.oracle.OracleExecutionFactory)4 TeiidExecutionFactory (org.teiid.translator.jdbc.teiid.TeiidExecutionFactory)4 FileInputStream (java.io.FileInputStream)3