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);
}
}
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();
}
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;
}
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;
}
}
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());
}
Aggregations