use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class GeometryUtils method geometryToGml.
public static ClobType geometryToGml(CommandContext ctx, GeometryType geometry, boolean withGmlPrefix) throws FunctionExecutionException {
Geometry jtsGeometry = getGeometry(geometry);
GMLWriter writer = new GMLWriter();
if (!withGmlPrefix) {
if (geometry.getSrid() != SRID_4326) {
if (geometry.getSrid() == GeometryType.UNKNOWN_SRID) {
throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31161));
}
jtsGeometry = GeometryTransformUtils.transform(ctx, jtsGeometry, SRID_4326);
}
writer.setPrefix(null);
} else if (geometry.getSrid() != GeometryType.UNKNOWN_SRID) {
// TODO: should include the srsName
// writer.setSrsName(String.valueOf(geometry.getSrid()));
}
String gmlText = writer.write(jtsGeometry);
return new ClobType(new ClobImpl(gmlText));
}
use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class JSONFunctionMethods method jsonParse.
@TeiidFunction(category = FunctionCategoryConstants.JSON)
public static ClobType jsonParse(BlobType val, boolean wellformed) throws SQLException, IOException, ParseException {
InputStreamReader r = XMLSystemFunctions.getJsonReader(val);
try {
if (!wellformed) {
JSONParser parser = new JSONParser();
parser.parse(r, validatingContentHandler);
}
ClobImpl clobImpl = new ClobImpl();
clobImpl.setStreamFactory(new InputStreamFactory.BlobInputStreamFactory(val.getReference()));
clobImpl.setEncoding(r.getEncoding());
ClobType ct = new ClobType(clobImpl);
ct.setType(Type.JSON);
return ct;
} finally {
r.close();
}
}
use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class TestObjectDecoderInputStream method testReplaceObject.
@Test
public void testReplaceObject() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectEncoderOutputStream out = new ObjectEncoderOutputStream(new DataOutputStream(baos), 512);
ClobImpl clob = new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
// $NON-NLS-1$
return new ReaderInputStream(new StringReader("Clob contents"), Charset.forName(Streamable.ENCODING));
}
}, -1);
out.writeObject(clob);
ObjectDecoderInputStream in = new ObjectDecoderInputStream(new AccessibleBufferedInputStream(new ByteArrayInputStream(baos.toByteArray()), 1024), Thread.currentThread().getContextClassLoader(), 1024);
Object result = in.readObject();
assertTrue(result instanceof ClobImpl);
}
use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class TestMongoDBQueryExecution method testGeoFunctionInWhereWithGeometry.
@Test
public void testGeoFunctionInWhereWithGeometry() throws Exception {
Table table = this.utility.createRuntimeMetadata().getTable("northwind.Categories");
NamedTable namedTable = new NamedTable("Categories", "g0", table);
ColumnReference colRef = new ColumnReference(namedTable, "CategoryName", table.getColumnByName("CategoryName"), String.class);
DerivedColumn col = new DerivedColumn("CategoryName", colRef);
Select select = new Select();
select.setDerivedColumns(Arrays.asList(col));
List<TableReference> tables = new ArrayList<TableReference>();
tables.add(namedTable);
select.setFrom(tables);
final GeometryType geo = GeometryUtils.geometryFromClob(new ClobType(new ClobImpl("POLYGON ((1.0 2.0,3.0 4.0,5.0 6.0,1.0 2.0))")));
Function function = new // $NON-NLS-1$
Function(// $NON-NLS-1$
"mongo.geoWithin", // $NON-NLS-1$
Arrays.asList(colRef, new Literal(geo, GeometryType.class)), // $NON-NLS-2$
Boolean.class);
function.setMetadataObject(getFunctionMethod("mongo.geoWithin"));
Comparison c = new Comparison(function, new Literal(true, Boolean.class), Comparison.Operator.EQ);
select.setWhere(c);
DBCollection dbCollection = helpExecute(select, new String[] { "Categories" }, 2);
BasicDBObjectBuilder builder = new BasicDBObjectBuilder();
builder.push("CategoryName");
// $NON-NLS-1$
builder.push("$geoWithin");
// $NON-NLS-1$
builder.add("$geometry", "{\"type\":\"Polygon\",\"coordinates\":[[[1.0,2.0],[3.0,4.0],[5.0,6.0],[1.0,2.0]]]}");
BasicDBObject result = new BasicDBObject();
result.append("CategoryName", "$CategoryName");
List<DBObject> pipeline = buildArray(new BasicDBObject("$match", builder.get()), new BasicDBObject("$project", result));
Mockito.verify(dbCollection).aggregate(Mockito.eq(pipeline), Mockito.any(AggregationOptions.class));
}
use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class TextTableNode method initReader.
private void initReader() throws ExpressionEvaluationException, BlockedException, TeiidComponentException, TeiidProcessingException {
setReferenceValues(this.table);
ClobType file = (ClobType) getEvaluator(Collections.emptyMap()).evaluate(table.getFile(), null);
if (file == null) {
return;
}
// get the reader
try {
// $NON-NLS-1$
this.systemId = "Unknown";
if (file.getReference() instanceof ClobImpl) {
this.systemId = ((ClobImpl) file.getReference()).getStreamFactory().getSystemId();
if (this.systemId == null) {
// $NON-NLS-1$
this.systemId = "Unknown";
}
}
Reader r = file.getCharacterStream();
if (!(r instanceof BufferedReader)) {
reader = new BufferedReader(r);
} else {
reader = (BufferedReader) r;
}
} catch (SQLException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30180, e);
}
// process the skip field
if (skip <= 0) {
return;
}
while (textLine < skip) {
boolean isHeader = textLine == header;
if (isHeader) {
StringBuilder line = readLine(DataTypeManager.MAX_STRING_LENGTH * 16, false);
if (line == null) {
// just return an empty batch
reset();
return;
}
processHeader(parseLine(line));
} else {
while (readChar() != newLine) {
}
}
}
}
Aggregations