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)));
}
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"))) });
}
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);
}
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();
}
}
}
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);
}
}
Aggregations