Search in sources :

Example 26 with ClobType

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

the class TestGeometry method testEwkt.

@Test
public void testEwkt() throws Exception {
    Expression ex = TestFunctionResolving.getExpression("st_asewkt(ST_GeomFromEwkt('POINT(0 0 0)')))");
    assertEquals("POINT (0 0)", ClobType.getString((ClobType) Evaluator.evaluate(ex)));
}
Also used : ClobType(org.teiid.core.types.ClobType) Expression(org.teiid.query.sql.symbol.Expression) Test(org.junit.Test)

Example 27 with ClobType

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

the class TestAggregateProcessing method testStringAggOrdering.

@Test()
public void testStringAggOrdering() throws Exception {
    String sql = "select string_agg(col1, ',' ORDER BY col1 DESC) as orderByDesc," + " string_agg(col1, ',' ORDER BY col1 ASC) as orderByAsc, " + " string_agg(DISTINCT col1, ',' ORDER BY col1 DESC) as distinctOrderByDesc, " + "	string_agg(DISTINCT col1, ',' ORDER BY col1 ASC) as distinctOrderByAsc from (select 'a' as col1 union all select 'b' union all select 'b' union all select 'c') as x";
    TransformationMetadata metadata = RealMetadataFactory.example1Cached();
    HardcodedDataManager hdm = new HardcodedDataManager();
    ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata);
    TestProcessor.helpProcess(plan, TestProcessor.createCommandContext(), hdm, new List<?>[] { Arrays.asList(new ClobType(new ClobImpl("c,b,b,a")), new ClobType(new ClobImpl("a,b,b,c")), new ClobType(new ClobImpl("c,b,a")), new ClobType(new ClobImpl("a,b,c"))) });
}
Also used : ClobType(org.teiid.core.types.ClobType) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) ClobImpl(org.teiid.core.types.ClobImpl) Test(org.junit.Test)

Example 28 with ClobType

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

the class LobWorkItem method createLobStream.

/**
 * Create a object which can create a sequence of LobChunk objects on a given
 * LOB object
 * @throws SQLException
 */
private ByteLobChunkStream createLobStream(String referenceStreamId) throws TeiidComponentException, SQLException {
    // get the reference object in the buffer manager, and try to stream off
    // the original sources.
    Streamable<?> streamable = parent.resultsBuffer.getLobReference(referenceStreamId);
    if (streamable instanceof XMLType) {
        XMLType xml = (XMLType) streamable;
        return new ByteLobChunkStream(xml.getBinaryStream(), chunkSize);
    } else if (streamable instanceof ClobType) {
        ClobType clob = (ClobType) streamable;
        return new ByteLobChunkStream(new ReaderInputStream(clob.getCharacterStream(), Charset.forName(Streamable.ENCODING)), chunkSize);
    }
    BlobType blob = (BlobType) streamable;
    return new ByteLobChunkStream(blob.getBinaryStream(), chunkSize);
}
Also used : ClobType(org.teiid.core.types.ClobType) XMLType(org.teiid.core.types.XMLType) ReaderInputStream(org.teiid.core.util.ReaderInputStream) BlobType(org.teiid.core.types.BlobType)

Example 29 with ClobType

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

the class FunctionMethods method concat.

public static ClobType concat(CommandContext context, ClobType str1, ClobType str2) throws IOException, SQLException {
    BufferManager bm = context.getBufferManager();
    // $NON-NLS-1$
    FileStore fs = bm.createFileStore("clob");
    FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs, Streamable.ENCODING);
    boolean remove = true;
    try (Reader characterStream = str1.getCharacterStream();
        Reader characterStream2 = str2.getCharacterStream()) {
        Writer writer = fsisf.getWriter();
        int chars = ObjectConverterUtil.write(writer, characterStream, -1, false);
        chars += ObjectConverterUtil.write(writer, characterStream2, -1, false);
        writer.close();
        if (fsisf.getStorageMode() == StorageMode.MEMORY) {
            // detach if just in memory
            byte[] bytes = fsisf.getMemoryBytes();
            return new ClobType(new ClobImpl(new String(bytes, Streamable.ENCODING)));
        }
        remove = false;
        context.addCreatedLob(fsisf);
        return new ClobType(new ClobImpl(fsisf, chars));
    } finally {
        if (remove) {
            fs.remove();
        }
    }
}
Also used : ClobType(org.teiid.core.types.ClobType) FileStore(org.teiid.common.buffer.FileStore) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) FilterReader(java.io.FilterReader) Reader(java.io.Reader) BufferManager(org.teiid.common.buffer.BufferManager) ClobImpl(org.teiid.core.types.ClobImpl) Writer(java.io.Writer)

Example 30 with ClobType

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

the class StringAgg method getResult.

/**
 * @see org.teiid.query.function.aggregate.AggregateFunction#getResult(CommandContext)
 */
public Object getResult(CommandContext commandContext) throws TeiidProcessingException {
    if (this.result == null) {
        this.result = buildResult(commandContext);
    }
    try {
        this.result.getWriter().close();
        FileStoreOutputStream fs = this.result.getOuputStream();
        fs.close();
        if (binary) {
            if (fs.bytesWritten()) {
                return new BlobType(new BlobImpl(result));
            }
            return new BlobType(new SerialBlob(Arrays.copyOf(fs.getBuffer(), fs.getCount())));
        }
        if (fs.bytesWritten()) {
            return new ClobType(new ClobImpl(result, -1));
        }
        return new ClobType(new ClobImpl(new String(Arrays.copyOf(fs.getBuffer(), fs.getCount()), Streamable.ENCODING)));
    } catch (IOException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e);
    } catch (SQLException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e);
    }
}
Also used : ClobType(org.teiid.core.types.ClobType) BlobType(org.teiid.core.types.BlobType) SQLException(java.sql.SQLException) SerialBlob(javax.sql.rowset.serial.SerialBlob) FileStoreOutputStream(org.teiid.common.buffer.FileStore.FileStoreOutputStream) IOException(java.io.IOException) BlobImpl(org.teiid.core.types.BlobImpl) ClobImpl(org.teiid.core.types.ClobImpl) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Aggregations

ClobType (org.teiid.core.types.ClobType)49 Test (org.junit.Test)31 ClobImpl (org.teiid.core.types.ClobImpl)20 Expression (org.teiid.query.sql.symbol.Expression)16 SQLException (java.sql.SQLException)8 InputStreamFactory (org.teiid.core.types.InputStreamFactory)8 IOException (java.io.IOException)7 BlobType (org.teiid.core.types.BlobType)6 Reader (java.io.Reader)4 Blob (java.sql.Blob)4 ArrayList (java.util.ArrayList)4 SerialBlob (javax.sql.rowset.serial.SerialBlob)4 SerialClob (javax.sql.rowset.serial.SerialClob)4 BlobImpl (org.teiid.core.types.BlobImpl)4 XMLType (org.teiid.core.types.XMLType)4 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 BlobInputStreamFactory (org.teiid.core.types.InputStreamFactory.BlobInputStreamFactory)3 SQLXMLImpl (org.teiid.core.types.SQLXMLImpl)3 ReaderInputStream (org.teiid.core.util.ReaderInputStream)3