Search in sources :

Example 1 with Persistable

use of org.locationtech.geowave.core.index.persist.Persistable in project geowave by locationtech.

the class AggregationIterator method setOptions.

public void setOptions(final Map<String, String> options) {
    try {
        final String aggregrationBytes = options.get(AGGREGATION_OPTION_NAME);
        aggregationFunction = (Aggregation) PersistenceUtils.fromClassId(ByteArrayUtils.byteArrayFromString(aggregrationBytes));
        final String parameterStr = options.get(PARAMETER_OPTION_NAME);
        if ((parameterStr != null) && !parameterStr.isEmpty()) {
            final byte[] parameterBytes = ByteArrayUtils.byteArrayFromString(parameterStr);
            final Persistable aggregationParams = PersistenceUtils.fromBinary(parameterBytes);
            aggregationFunction.setParameters(aggregationParams);
        }
        if (options.containsKey(ADAPTER_OPTION_NAME)) {
            final String adapterStr = options.get(ADAPTER_OPTION_NAME);
            final byte[] adapterBytes = ByteArrayUtils.byteArrayFromString(adapterStr);
            adapter = (InternalDataAdapter) PersistenceUtils.fromBinary(adapterBytes);
            final String mappingStr = options.get(ADAPTER_INDEX_MAPPING_OPTION_NAME);
            final byte[] mappingBytes = ByteArrayUtils.byteArrayFromString(mappingStr);
            indexMapping = (AdapterToIndexMapping) PersistenceUtils.fromBinary(mappingBytes);
        }
    } catch (final Exception e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : Persistable(org.locationtech.geowave.core.index.persist.Persistable) IOException(java.io.IOException)

Example 2 with Persistable

use of org.locationtech.geowave.core.index.persist.Persistable in project geowave by locationtech.

the class AbstractDataTypeAdapter method fromBinary.

@Override
public void fromBinary(byte[] bytes) {
    final ByteBuffer buffer = ByteBuffer.wrap(bytes);
    final byte[] typeNameBytes = new byte[VarintUtils.readUnsignedInt(buffer)];
    buffer.get(typeNameBytes);
    this.typeName = StringUtils.stringFromBinary(typeNameBytes);
    final byte[] fieldDescriptorBytes = new byte[VarintUtils.readUnsignedInt(buffer)];
    buffer.get(fieldDescriptorBytes);
    final List<Persistable> fieldDescriptorList = PersistenceUtils.fromBinaryAsList(fieldDescriptorBytes);
    this.fieldDescriptors = fieldDescriptorList.toArray(new FieldDescriptor<?>[fieldDescriptorList.size()]);
    final byte[] dataIDFieldBytes = new byte[VarintUtils.readUnsignedInt(buffer)];
    buffer.get(dataIDFieldBytes);
    final String dataIDField = StringUtils.stringFromBinary(dataIDFieldBytes);
    if (buffer.hasRemaining()) {
        final byte[] dataIDFieldDescriptorBytes = new byte[VarintUtils.readUnsignedInt(buffer)];
        buffer.get(dataIDFieldDescriptorBytes);
        this.dataIDFieldDescriptor = (FieldDescriptor<?>) PersistenceUtils.fromBinary(dataIDFieldDescriptorBytes);
    } else {
        for (int i = 0; i < fieldDescriptors.length; i++) {
            if (fieldDescriptors[i].fieldName().equals(dataIDField)) {
                this.dataIDFieldDescriptor = fieldDescriptors[i];
            }
        }
        this.serializeDataIDAsString = true;
    }
    populateFieldDescriptorIndices();
}
Also used : Persistable(org.locationtech.geowave.core.index.persist.Persistable) ByteBuffer(java.nio.ByteBuffer)

Example 3 with Persistable

use of org.locationtech.geowave.core.index.persist.Persistable in project geowave by locationtech.

the class BBOXQuery method runQuery.

@Override
protected long runQuery(final GeotoolsFeatureDataAdapter adapter, final String typeName, final String indexName, final DataStore dataStore, final boolean debug, final DataStorePluginOptions pluginOptions) {
    final StopWatch stopWatch = new StopWatch();
    getBoxGeom();
    long count = 0;
    if (useAggregation) {
        final VectorAggregationQueryBuilder<Persistable, Long> bldr = (VectorAggregationQueryBuilder) VectorAggregationQueryBuilder.newBuilder().count(typeName).indexName(indexName);
        final Long countResult = dataStore.aggregate(bldr.constraints(bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(geom).build()).build());
        if (countResult != null) {
            count += countResult;
        }
    } else {
        final VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder().addTypeName(typeName).indexName(indexName);
        stopWatch.start();
        try (final CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(geom).build()).build())) {
            stopWatch.stop();
            System.out.println("Ran BBOX query in " + stopWatch.toString());
            stopWatch.reset();
            stopWatch.start();
            while (it.hasNext()) {
                if (debug) {
                    System.out.println(it.next());
                } else {
                    it.next();
                }
                count++;
            }
            stopWatch.stop();
            System.out.println("BBOX query results iteration took " + stopWatch.toString());
        }
    }
    return count;
}
Also used : VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) Persistable(org.locationtech.geowave.core.index.persist.Persistable) VectorAggregationQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorAggregationQueryBuilder) SimpleFeature(org.opengis.feature.simple.SimpleFeature) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 4 with Persistable

use of org.locationtech.geowave.core.index.persist.Persistable in project geowave by locationtech.

the class CQLQuery method runQuery.

@Override
protected long runQuery(final GeotoolsFeatureDataAdapter adapter, final String typeName, final String indexName, final DataStore dataStore, final boolean debug, final DataStorePluginOptions pluginOptions) {
    long count = 0;
    if (useAggregation) {
        final VectorAggregationQueryBuilder<Persistable, Long> bldr = (VectorAggregationQueryBuilder) VectorAggregationQueryBuilder.newBuilder().count(typeName).indexName(indexName);
        final Long countResult = dataStore.aggregate(bldr.constraints(bldr.constraintsFactory().cqlConstraints(cqlStr)).build());
        if (countResult != null) {
            count += countResult;
        }
        return count;
    } else {
        final VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder().addTypeName(typeName).indexName(indexName);
        try (final CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().cqlConstraints(cqlStr)).build())) {
            while (it.hasNext()) {
                if (debug) {
                    System.out.println(it.next());
                } else {
                    it.next();
                }
                count++;
            }
        }
        return count;
    }
}
Also used : VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) Persistable(org.locationtech.geowave.core.index.persist.Persistable) VectorAggregationQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorAggregationQueryBuilder) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 5 with Persistable

use of org.locationtech.geowave.core.index.persist.Persistable in project geowave by locationtech.

the class MigrationTest method testLegacyFeatureDataAdapterMigration.

@Test
public void testLegacyFeatureDataAdapterMigration() {
    final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder();
    builder.setName("testType");
    builder.setNamespaceURI("geowave.namespace");
    builder.add(attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("strAttr"));
    builder.add(attributeTypeBuilder.binding(Integer.class).nillable(true).buildDescriptor("intAttr"));
    builder.add(attributeTypeBuilder.binding(Date.class).nillable(false).buildDescriptor("dateAttr"));
    builder.add(attributeTypeBuilder.binding(Point.class).nillable(false).buildDescriptor("geom"));
    builder.crs(GeometryUtils.getDefaultCRS());
    final SimpleFeatureType featureType = builder.buildFeatureType();
    final AttributeDescriptor stringAttr = featureType.getDescriptor("strAttr");
    // Configure legacy visiblity
    stringAttr.getUserData().put("visibility", Boolean.TRUE);
    featureType.getUserData().put("visibilityManagerClass", "org.locationtech.geowave.adapter.vector.plugin.visibility.JsonDefinitionColumnVisibilityManagement");
    LegacyFeatureDataAdapter adapter = new LegacyFeatureDataAdapter(featureType, "EPSG:3257");
    final byte[] adapterBinary = PersistenceUtils.toBinary(adapter);
    final Persistable persistableAdapter = PersistenceUtils.fromBinary(adapterBinary);
    assertTrue(persistableAdapter instanceof LegacyFeatureDataAdapter);
    adapter = (LegacyFeatureDataAdapter) persistableAdapter;
    assertNotNull(adapter.getUpdatedAdapter());
    final FeatureDataAdapter updatedAdapter = adapter.getUpdatedAdapter();
    assertEquals(4, updatedAdapter.getFieldDescriptors().length);
    assertEquals(String.class, updatedAdapter.getFieldDescriptor("strAttr").bindingClass());
    assertEquals(Integer.class, updatedAdapter.getFieldDescriptor("intAttr").bindingClass());
    assertTrue(TemporalFieldDescriptor.class.isAssignableFrom(updatedAdapter.getFieldDescriptor("dateAttr").getClass()));
    final TemporalFieldDescriptor<?> temporalField = (TemporalFieldDescriptor<?>) updatedAdapter.getFieldDescriptor("dateAttr");
    assertEquals(Date.class, temporalField.bindingClass());
    assertTrue(temporalField.indexHints().contains(TimeField.TIME_DIMENSION_HINT));
    assertTrue(SpatialFieldDescriptor.class.isAssignableFrom(updatedAdapter.getFieldDescriptor("geom").getClass()));
    final SpatialFieldDescriptor<?> spatialField = (SpatialFieldDescriptor<?>) updatedAdapter.getFieldDescriptor("geom");
    assertEquals(Point.class, spatialField.bindingClass());
    assertEquals(GeometryUtils.getDefaultCRS(), spatialField.crs());
    assertTrue(spatialField.indexHints().contains(SpatialField.LATITUDE_DIMENSION_HINT));
    assertTrue(spatialField.indexHints().contains(SpatialField.LONGITUDE_DIMENSION_HINT));
    assertEquals("testType", updatedAdapter.getTypeName());
    assertEquals(SimpleFeature.class, updatedAdapter.getDataClass());
    assertTrue(updatedAdapter.hasTemporalConstraints());
    assertNotNull(adapter.getVisibilityHandler());
    final VisibilityHandler visibilityHandler = adapter.getVisibilityHandler();
    assertTrue(visibilityHandler instanceof JsonFieldLevelVisibilityHandler);
    assertEquals("strAttr", ((JsonFieldLevelVisibilityHandler) visibilityHandler).getVisibilityAttribute());
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) LegacyFeatureDataAdapter(org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter) Persistable(org.locationtech.geowave.core.index.persist.Persistable) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) Point(org.locationtech.jts.geom.Point) Date(java.util.Date) AttributeTypeBuilder(org.geotools.feature.AttributeTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SpatialFieldDescriptor(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) JsonFieldLevelVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.JsonFieldLevelVisibilityHandler) JsonFieldLevelVisibilityHandler(org.locationtech.geowave.core.store.data.visibility.JsonFieldLevelVisibilityHandler) TemporalFieldDescriptor(org.locationtech.geowave.core.geotime.adapter.TemporalFieldDescriptor) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) LegacyFeatureDataAdapter(org.locationtech.geowave.migration.legacy.adapter.vector.LegacyFeatureDataAdapter) Test(org.junit.Test)

Aggregations

Persistable (org.locationtech.geowave.core.index.persist.Persistable)16 Test (org.junit.Test)5 IOException (java.io.IOException)4 Point (java.awt.Point)2 DataBuffer (java.awt.image.DataBuffer)2 ByteBuffer (java.nio.ByteBuffer)2 Date (java.util.Date)2 AttributeTypeBuilder (org.geotools.feature.AttributeTypeBuilder)2 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)2 VectorAggregationQueryBuilder (org.locationtech.geowave.core.geotime.store.query.api.VectorAggregationQueryBuilder)2 VectorQueryBuilder (org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder)2 ByteArray (org.locationtech.geowave.core.index.ByteArray)2 Aggregation (org.locationtech.geowave.core.store.api.Aggregation)2 CommonIndexedPersistenceEncoding (org.locationtech.geowave.core.store.data.CommonIndexedPersistenceEncoding)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 ByteString (com.google.protobuf.ByteString)1 Rectangle (java.awt.Rectangle)1 AffineTransform (java.awt.geom.AffineTransform)1 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)1 BufferedImage (java.awt.image.BufferedImage)1