use of org.teiid.core.types.ClobType 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.ClobType in project teiid by teiid.
the class JSONFunctionMethods method jsonParse.
@TeiidFunction(category = FunctionCategoryConstants.JSON)
public static ClobType jsonParse(ClobType val, boolean wellformed) throws SQLException, IOException, ParseException {
Reader r = null;
if (val.getType() == Type.JSON) {
return val;
}
if (!wellformed) {
r = val.getCharacterStream();
}
try {
if (!wellformed) {
JSONParser parser = new JSONParser();
parser.parse(r, validatingContentHandler);
}
ClobType ct = new ClobType(val.getReference());
ct.setType(Type.JSON);
return ct;
} finally {
if (r != null) {
r.close();
}
}
}
use of org.teiid.core.types.ClobType 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.ClobType in project teiid by teiid.
the class TestFunctionLibrary method testClobConcat.
@Test
public void testClobConcat() throws Exception {
CommandContext c = new CommandContext();
c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
ClobType result = (ClobType) helpInvokeMethod("concat", new Class<?>[] { DataTypeManager.DefaultDataClasses.CLOB, DataTypeManager.DefaultDataClasses.CLOB }, new Object[] { DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>", DataTypeManager.DefaultDataClasses.CLOB), DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>", DataTypeManager.DefaultDataClasses.CLOB) }, c);
String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\">" + "<Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs><?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + "<xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>", xml);
}
use of org.teiid.core.types.ClobType in project teiid by teiid.
the class TestFunctionMethods method testUpperLowerClob.
@Test
public void testUpperLowerClob() throws Exception {
char[] val = new char[] { 87, 122, 147, 0xD801, 0xDC37 };
assertEquals(new String(val).toUpperCase(), ClobType.getString(FunctionMethods.upperCase(new ClobType(ClobImpl.createClob(val)))));
assertEquals(new String(val).toLowerCase(), ClobType.getString(FunctionMethods.lowerCase(new ClobType(ClobImpl.createClob(val)))));
}
Aggregations