use of org.teiid.core.types.GeometryType in project teiid by teiid.
the class TestAccumuloQueryExecution method testAccumuloDataTypeManager.
@Test
public void testAccumuloDataTypeManager() throws SQLException {
GeometryType gt = new GeometryType(new byte[10]);
gt.setSrid(4000);
byte[] bytes = AccumuloDataTypeManager.serialize(gt);
GeometryType gt1 = (GeometryType) AccumuloDataTypeManager.deserialize(bytes, GeometryType.class);
assertEquals(4000, gt1.getSrid());
assertEquals(10, gt1.length());
}
use of org.teiid.core.types.GeometryType in project teiid by teiid.
the class AccumuloDataTypeManager method deserialize.
public static Object deserialize(final byte[] value, final Class<?> expectedType) {
if (value == null || Arrays.equals(value, EMPTY_BYTES)) {
return null;
}
try {
if (expectedType.isAssignableFrom(Clob.class)) {
return new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return ObjectConverterUtil.convertToInputStream(value);
}
}, -1);
} else if (expectedType.isAssignableFrom(Blob.class)) {
return new BlobType(new BlobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return ObjectConverterUtil.convertToInputStream(value);
}
}));
} else if (expectedType.isAssignableFrom(SQLXML.class)) {
return new SQLXMLImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return ObjectConverterUtil.convertToInputStream(value);
}
});
} else if (expectedType.isAssignableFrom(BinaryType.class)) {
return new BinaryType(value);
} else if (expectedType.isAssignableFrom(GeometryType.class)) {
GeometryType result = new GeometryType(Arrays.copyOf(value, value.length - 4));
int srid = (((value[value.length - 4] & 0xff) << 24) + ((value[value.length - 3] & 0xff) << 16) + ((value[value.length - 2] & 0xff) << 8) + ((value[value.length - 1] & 0xff) << 0));
result.setSrid(srid);
return result;
} else if (expectedType.isAssignableFrom(byte[].class)) {
return value;
} else if (expectedType.isAssignableFrom(String.class) || expectedType.isAssignableFrom(Boolean.class) || expectedType.isAssignableFrom(Boolean.class) || expectedType.isAssignableFrom(Byte.class) || expectedType.isAssignableFrom(Short.class) || expectedType.isAssignableFrom(Character.class) || expectedType.isAssignableFrom(Integer.class) || expectedType.isAssignableFrom(Long.class) || expectedType.isAssignableFrom(BigInteger.class) || expectedType.isAssignableFrom(BigDecimal.class) || expectedType.isAssignableFrom(Float.class) || expectedType.isAssignableFrom(Double.class) || expectedType.isAssignableFrom(Date.class) || expectedType.isAssignableFrom(Time.class) || expectedType.isAssignableFrom(Timestamp.class)) {
return DataTypeManager.transformValue(new String(value, UTF_8), expectedType);
} else {
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(value));
Object obj = ois.readObject();
ois.close();
return obj;
}
} catch (ClassNotFoundException e) {
throw new TeiidRuntimeException(e);
} catch (IOException e) {
throw new TeiidRuntimeException(e);
} catch (TransformationException e) {
throw new TeiidRuntimeException(e);
}
}
use of org.teiid.core.types.GeometryType in project teiid by teiid.
the class GeometryFunctionMethods method setSrid.
@TeiidFunction(name = SourceSystemFunctions.ST_SETSRID, category = FunctionCategoryConstants.GEOMETRY, nullOnNull = true, pushdown = PushDown.CAN_PUSHDOWN)
public static GeometryType setSrid(GeometryType geom1, int srid) {
GeometryType gt = new GeometryType();
gt.setReference(geom1.getReference());
gt.setSrid(srid);
return gt;
}
use of org.teiid.core.types.GeometryType in project teiid by teiid.
the class TestBatchSerializer method testGeometry.
@Test
public void testGeometry() throws IOException, ClassNotFoundException {
GeometryType geometryType = new GeometryType(new byte[0]);
geometryType.setReferenceStreamId(null);
geometryType.setSrid(10000);
Object val = helpTestSerialization(new String[] { DataTypeManager.DefaultDataTypes.GEOMETRY }, new List[] { Arrays.asList(geometryType) }, BatchSerializer.CURRENT_VERSION).get(0).get(0);
assertTrue(val instanceof GeometryType);
assertEquals(10000, ((GeometryType) val).getSrid());
// object serialization - should fail on the client side
helpTestSerialization(new String[] { DataTypeManager.DefaultDataTypes.GEOMETRY }, new List[] { Arrays.asList(geometryType) }, (byte) 0);
// blob serialization
val = helpTestSerialization(new String[] { DataTypeManager.DefaultDataTypes.GEOMETRY }, new List[] { Arrays.asList(geometryType) }, (byte) 1);
assertFalse(val instanceof GeometryType);
// blob serialization
val = helpTestSerialization(new String[] { DataTypeManager.DefaultDataTypes.OBJECT }, new List[] { Arrays.asList(geometryType) }, (byte) 1);
assertFalse(val instanceof GeometryType);
}
use of org.teiid.core.types.GeometryType 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));
}
Aggregations