Search in sources :

Example 6 with QueryExpression

use of org.teiid.language.QueryExpression in project teiid by teiid.

the class LoopbackExecution method determineOutputTypes.

private void determineOutputTypes() {
    // Get select columns and lookup the types in metadata
    if (command instanceof QueryExpression) {
        QueryExpression query = (QueryExpression) command;
        types = Arrays.asList(query.getColumnTypes());
        return;
    }
    if (command instanceof Call) {
        types = Arrays.asList(((Call) command).getResultSetColumnTypes());
        return;
    }
    types = new ArrayList<Class<?>>(1);
    types.add(Integer.class);
}
Also used : Call(org.teiid.language.Call) QueryExpression(org.teiid.language.QueryExpression)

Example 7 with QueryExpression

use of org.teiid.language.QueryExpression 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 8 with QueryExpression

use of org.teiid.language.QueryExpression in project teiid by teiid.

the class TestBaseDelegatingExecutionFactory method testExecution.

@Test
public void testExecution() throws TranslatorException {
    BaseDelegatingExecutionFactory<Void, Void> ef = new BaseDelegatingExecutionFactory<Void, Void>() {

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Void connection) throws TranslatorException {
            return null;
        }
    };
    ef.setDelegate(new ExecutionFactory<Void, Void>() {

        @Override
        public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Void connection) throws TranslatorException {
            throw new AssertionError();
        }
    });
    ef.createExecution(new Select(null, false, null, null, null, null, null), null, null, null);
}
Also used : RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Command(org.teiid.language.Command) Select(org.teiid.language.Select) QueryExpression(org.teiid.language.QueryExpression) Test(org.junit.Test)

Example 9 with QueryExpression

use of org.teiid.language.QueryExpression in project teiid by teiid.

the class TestHotrodExecution method testServer_Teiid_5165.

// TEIID-5165 - test large cache delete
@Test
public void testServer_Teiid_5165() throws Exception {
    EF.setSupportsUpsert(false);
    ResultSetExecution exec = null;
    Command command = null;
    UpdateExecution update = null;
    InfinispanConnection connection = getConnection("foo");
    // the below also test one-2-one relation.
    command = UTILITY.parseCommand("DELETE FROM G2");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    int rows = 12000;
    for (int i = 0; i < rows; i++) {
        command = UTILITY.parseCommand("INSERT INTO G2 (e1, e2, g3_e1, g3_e2) values (" + i + ", 'row" + i + "', 1, 'one')");
        update = EF.createUpdateExecution(command, EC, METADATA, connection);
        update.execute();
    }
    Thread.sleep(5000);
    command = UTILITY.parseCommand("SELECT e1, e2 FROM G2");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    int cnt = 0;
    while (true) {
        List<?> results = exec.next();
        if (results == null)
            break;
        cnt++;
    }
    assertEquals(new Integer(rows), new Integer(cnt));
    command = UTILITY.parseCommand("DELETE FROM G2");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT count(*) as cnt FROM G2");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertNull(exec.next());
}
Also used : BigInteger(java.math.BigInteger) ResultSetExecution(org.teiid.translator.ResultSetExecution) Command(org.teiid.language.Command) InfinispanConnection(org.teiid.infinispan.api.InfinispanConnection) UpdateExecution(org.teiid.translator.UpdateExecution) QueryExpression(org.teiid.language.QueryExpression) Test(org.junit.Test)

Example 10 with QueryExpression

use of org.teiid.language.QueryExpression in project teiid by teiid.

the class TestODataIntegration method testErrorCodes.

@Test
public void testErrorCodes() throws Exception {
    HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {

        @Override
        public ResultSetExecution createResultSetExecution(final QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            List<? extends List<?>> list = getData(command);
            if (list == null) {
                throw new RuntimeException(command.toString());
            }
            final Iterator<? extends List<?>> result = list.iterator();
            return new ResultSetExecution() {

                @Override
                public void execute() throws TranslatorException {
                    throw new TranslatorException(ODataPlugin.Event.TEIID16001, "execution failed");
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (result.hasNext()) {
                        return result.next();
                    }
                    return null;
                }
            };
        }
    };
    hc.addData("SELECT x.a, x.b FROM x", Arrays.asList(Arrays.asList("a", 1)));
    teiid.addTranslator("x1", hc);
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("m");
        mmd.addSourceMetadata("ddl", "create foreign table x (a string, b integer, primary key (a));");
        mmd.addSourceMapping("x1", "x1", null);
        teiid.deployVDB("northwind", mmd);
        localClient = getClient(teiid.getDriver(), "northwind", new Properties());
        ContentResponse response = http.newRequest(baseURL + "/northwind/m/x").method("GET").send();
        assertEquals(400, response.getStatus());
        assertEquals("{\"error\":{\"code\":\"TEIID30504\"," + "\"message\":\"TEIID30504 x1: TEIID16001 execution failed\"}}", response.getContentAsString());
        response = http.newRequest(baseURL + "/northwind/m/x?$format=xml").method("GET").send();
        assertEquals(400, response.getStatus());
        assertEquals("<?xml version='1.0' encoding='UTF-8'?>" + "<error xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\">" + "<code>TEIID30504</code>" + "<message>TEIID30504 x1: TEIID16001 execution failed</message>" + "</error>", response.getContentAsString());
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) TranslatorException(org.teiid.translator.TranslatorException) QueryExpression(org.teiid.language.QueryExpression) Test(org.junit.Test)

Aggregations

QueryExpression (org.teiid.language.QueryExpression)16 ResultSetExecution (org.teiid.translator.ResultSetExecution)12 Test (org.junit.Test)11 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)11 ExecutionContext (org.teiid.translator.ExecutionContext)10 TranslatorException (org.teiid.translator.TranslatorException)9 List (java.util.List)7 ExecutionFactory (org.teiid.translator.ExecutionFactory)7 ArrayList (java.util.ArrayList)6 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)5 Command (org.teiid.language.Command)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 BeforeClass (org.junit.BeforeClass)3 BufferManager (org.teiid.common.buffer.BufferManager)3 FakeServer (org.teiid.jdbc.FakeServer)3 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)3 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)3 UpdateExecution (org.teiid.translator.UpdateExecution)3 BigInteger (java.math.BigInteger)2