Search in sources :

Example 21 with BlobType

use of org.teiid.core.types.BlobType in project teiid by teiid.

the class CouchbaseProcedureExecution method next.

@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
    if (this.results != null && this.results.hasNext()) {
        final N1qlQueryRow row = this.results.next();
        String procName = this.call.getProcedureName();
        if (procName.equalsIgnoreCase(GETDOCUMENTS) || procName.equalsIgnoreCase(GETDOCUMENT)) {
            ArrayList<Object> result = new ArrayList<>(1);
            InputStreamFactory isf = new InputStreamFactory() {

                @Override
                public InputStream getInputStream() throws IOException {
                    return new ByteArrayInputStream(row.byteValue());
                }
            };
            Object value = new BlobType(new BlobImpl(isf));
            result.add(value);
            return result;
        }
    }
    return null;
}
Also used : N1qlQueryRow(com.couchbase.client.java.query.N1qlQueryRow) BlobType(org.teiid.core.types.BlobType) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) InputStreamFactory(org.teiid.core.types.InputStreamFactory) BlobImpl(org.teiid.core.types.BlobImpl)

Example 22 with BlobType

use of org.teiid.core.types.BlobType in project teiid by teiid.

the class TestJSONProcessing method testJSONParseBlob.

@Test
public void testJSONParseBlob() throws Exception {
    HardcodedDataManager dataManager = new HardcodedDataManager();
    // $NON-NLS-1$
    String sql = "select jsonParse(cast(? as blob), false) x";
    String json = "{\"name\":123}";
    List<?>[] expected = new List[] { Arrays.asList(json) };
    processPreparedStatement(sql, expected, dataManager, new DefaultCapabilitiesFinder(), RealMetadataFactory.example1Cached(), Arrays.asList(new BlobType(new SerialBlob(json.getBytes(Charset.forName("UTF-16BE"))))));
}
Also used : BlobType(org.teiid.core.types.BlobType) List(java.util.List) SerialBlob(javax.sql.rowset.serial.SerialBlob) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 23 with BlobType

use of org.teiid.core.types.BlobType in project teiid by teiid.

the class TestJDBCSocketTransport method testStreamingLob.

@Test
public void testStreamingLob() throws Exception {
    HardCodedExecutionFactory ef = new HardCodedExecutionFactory();
    ef.addData("SELECT helloworld.x FROM helloworld", Arrays.asList(Arrays.asList(new BlobType(new BinaryWSProcedureExecution.StreamingBlob(new ByteArrayInputStream(new byte[100]))))));
    server.addTranslator("custom", ef);
    server.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\"><source name=\"test\" translator-name=\"custom\"/><metadata type=\"DDL\"><![CDATA[CREATE foreign table helloworld (x blob);]]> </metadata></model></vdb>".getBytes("UTF-8")));
    conn = TeiidDriver.getInstance().connect("jdbc:teiid:test@mm://" + addr.getHostName() + ":" + jdbcTransport.getPort(), null);
    Statement s = conn.createStatement();
    ResultSet rs = s.executeQuery("select to_chars(x, 'UTF-8') from helloworld");
    rs.next();
    // TODO: if we use getString streaming will still fail because the string logic gets the length first
    assertEquals(100, ObjectConverterUtil.convertToCharArray(rs.getCharacterStream(1), -1).length);
}
Also used : BlobType(org.teiid.core.types.BlobType) ByteArrayInputStream(java.io.ByteArrayInputStream) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Test(org.junit.Test)

Aggregations

BlobType (org.teiid.core.types.BlobType)23 BlobImpl (org.teiid.core.types.BlobImpl)11 InputStreamFactory (org.teiid.core.types.InputStreamFactory)10 Test (org.junit.Test)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 IOException (java.io.IOException)7 SerialBlob (javax.sql.rowset.serial.SerialBlob)7 Clob (java.sql.Clob)6 SQLException (java.sql.SQLException)6 ClobImpl (org.teiid.core.types.ClobImpl)6 ClobType (org.teiid.core.types.ClobType)6 XMLType (org.teiid.core.types.XMLType)6 InputStream (java.io.InputStream)5 Blob (java.sql.Blob)5 ArrayList (java.util.ArrayList)4 ReaderInputStream (org.teiid.core.util.ReaderInputStream)4 SerialClob (javax.sql.rowset.serial.SerialClob)3 FileStoreOutputStream (org.teiid.common.buffer.FileStore.FileStoreOutputStream)3 SQLXMLImpl (org.teiid.core.types.SQLXMLImpl)3 N1qlQueryRow (com.couchbase.client.java.query.N1qlQueryRow)2