Search in sources :

Example 1 with GeometryType

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());
}
Also used : GeometryType(org.teiid.core.types.GeometryType) Test(org.junit.Test)

Example 2 with GeometryType

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);
    }
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) InputStreamFactory(org.teiid.core.types.InputStreamFactory) Timestamp(java.sql.Timestamp) GeometryType(org.teiid.core.types.GeometryType) ClobImpl(org.teiid.core.types.ClobImpl) BlobImpl(org.teiid.core.types.BlobImpl) Blob(java.sql.Blob) SQLXMLImpl(org.teiid.core.types.SQLXMLImpl) TransformationException(org.teiid.core.types.TransformationException) BinaryType(org.teiid.core.types.BinaryType) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Date(java.sql.Date) BigInteger(java.math.BigInteger) BlobType(org.teiid.core.types.BlobType) ByteArrayInputStream(java.io.ByteArrayInputStream) BigInteger(java.math.BigInteger) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with GeometryType

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;
}
Also used : GeometryType(org.teiid.core.types.GeometryType)

Example 4 with GeometryType

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);
}
Also used : GeometryType(org.teiid.core.types.GeometryType) List(java.util.List) Test(org.junit.Test)

Example 5 with 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));
}
Also used : NamedTable(org.teiid.language.NamedTable) NamedTable(org.teiid.language.NamedTable) Table(org.teiid.metadata.Table) ArrayList(java.util.ArrayList) ClobType(org.teiid.core.types.ClobType) GeometryType(org.teiid.core.types.GeometryType) Function(org.teiid.language.Function) TableReference(org.teiid.language.TableReference) Comparison(org.teiid.language.Comparison) Literal(org.teiid.language.Literal) Select(org.teiid.language.Select) DerivedColumn(org.teiid.language.DerivedColumn) ClobImpl(org.teiid.core.types.ClobImpl) ColumnReference(org.teiid.language.ColumnReference) Test(org.junit.Test)

Aggregations

GeometryType (org.teiid.core.types.GeometryType)17 Test (org.junit.Test)8 Blob (java.sql.Blob)4 BinaryType (org.teiid.core.types.BinaryType)4 BasicDBList (com.mongodb.BasicDBList)3 BasicDBObject (com.mongodb.BasicDBObject)3 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 SQLException (java.sql.SQLException)3 BlobImpl (org.teiid.core.types.BlobImpl)3 ClobImpl (org.teiid.core.types.ClobImpl)3 ClobType (org.teiid.core.types.ClobType)3 InputStreamFactory (org.teiid.core.types.InputStreamFactory)3 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)2 DBObject (com.mongodb.DBObject)2 InputStream (java.io.InputStream)2 BigDecimal (java.math.BigDecimal)2 PreparedStatement (java.sql.PreparedStatement)2 GridFS (com.mongodb.gridfs.GridFS)1 GridFSInputFile (com.mongodb.gridfs.GridFSInputFile)1