Search in sources :

Example 1 with AdapterPersistenceEncoding

use of org.locationtech.geowave.core.store.adapter.AdapterPersistenceEncoding in project geowave by locationtech.

the class BaseDataStoreUtils method getWriteInfo.

protected static <T> IntermediaryWriteEntryInfo getWriteInfo(final T entry, final InternalDataAdapter<T> adapter, final AdapterToIndexMapping indexMapping, final Index index, final VisibilityHandler visibilityHandler, final boolean secondaryIndex, final boolean dataIdIndex, final boolean visibilityEnabled) {
    final CommonIndexModel indexModel = index.getIndexModel();
    final short internalAdapterId = adapter.getAdapterId();
    final byte[] dataId = adapter.getDataId(entry);
    final AdapterPersistenceEncoding encodedData = adapter.encode(entry, indexMapping, index);
    if (encodedData == null) {
        // The entry could not be encoded to the index, but this could be due to a null value in one
        // of the index fields, which is possible in attribute indices
        LOGGER.info("Indexing failed to produce insertion ids; entry [" + StringUtils.stringFromBinary(adapter.getDataId(entry)) + "] not saved for index '" + index.getName() + "'.");
        return new IntermediaryWriteEntryInfo(dataId, internalAdapterId, new InsertionIds(), new GeoWaveValueImpl[0]);
    }
    final InsertionIds insertionIds;
    if (index instanceof CustomIndexStrategy) {
        insertionIds = ((CustomIndexStrategy) index).getInsertionIds(entry);
    } else {
        insertionIds = dataIdIndex ? null : encodedData.getInsertionIds(index);
    }
    if (dataIdIndex) {
        return getWriteInfoDataIDIndex(entry, dataId, encodedData, adapter, indexMapping, index, visibilityHandler, visibilityEnabled);
    }
    if (insertionIds.isEmpty()) {
        // we can allow some entries to not be indexed within every index for flexibility, and
        // therefore this should just be info level
        LOGGER.info("Indexing failed to produce insertion ids; entry [" + StringUtils.stringFromBinary(adapter.getDataId(entry)) + "] not saved for index '" + index.getName() + "'.");
        return new IntermediaryWriteEntryInfo(dataId, internalAdapterId, insertionIds, new GeoWaveValueImpl[0]);
    }
    final VisibilityComposer commonIndexVisibility = new VisibilityComposer();
    if (visibilityEnabled && (visibilityHandler != null)) {
        for (final Entry<String, Object> fieldValue : encodedData.getCommonData().getValues().entrySet()) {
            addIndexFieldVisibility(entry, adapter, indexMapping, visibilityHandler, fieldValue.getKey(), commonIndexVisibility);
        }
    }
    if (secondaryIndex && DataIndexUtils.adapterSupportsDataIndex(adapter)) {
        return new IntermediaryWriteEntryInfo(dataId, internalAdapterId, insertionIds, new GeoWaveValue[] { new GeoWaveValueImpl(new byte[0], StringUtils.stringToBinary(commonIndexVisibility.composeVisibility()), new byte[0]) });
    }
    final List<FieldInfo<?>> fieldInfoList = new ArrayList<>();
    addCommonFields(adapter, indexMapping, entry, index, indexModel, visibilityHandler, encodedData, visibilityEnabled, fieldInfoList);
    for (final Entry<String, Object> fieldValue : encodedData.getAdapterExtendedData().getValues().entrySet()) {
        if (fieldValue.getValue() != null) {
            final FieldInfo<?> fieldInfo = getFieldInfo(adapter, adapter, indexMapping, fieldValue.getKey(), fieldValue.getValue(), entry, visibilityHandler, visibilityEnabled, false);
            if (fieldInfo != null) {
                fieldInfoList.add(fieldInfo);
            }
        }
    }
    return new IntermediaryWriteEntryInfo(dataId, internalAdapterId, insertionIds, BaseDataStoreUtils.composeFlattenedFields(fieldInfoList, indexModel, adapter, commonIndexVisibility, dataIdIndex));
}
Also used : IndexedAdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.IndexedAdapterPersistenceEncoding) AdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.AdapterPersistenceEncoding) CustomIndexStrategy(org.locationtech.geowave.core.index.CustomIndexStrategy) ArrayList(java.util.ArrayList) VisibilityComposer(org.locationtech.geowave.core.store.data.visibility.VisibilityComposer) CommonIndexModel(org.locationtech.geowave.core.store.index.CommonIndexModel) GeoWaveValueImpl(org.locationtech.geowave.core.store.entities.GeoWaveValueImpl) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) FieldInfo(org.locationtech.geowave.core.store.base.IntermediaryWriteEntryInfo.FieldInfo)

Example 2 with AdapterPersistenceEncoding

use of org.locationtech.geowave.core.store.adapter.AdapterPersistenceEncoding in project geowave by locationtech.

the class InternalRasterDataAdapter method encode.

@Override
public AdapterPersistenceEncoding encode(final GridCoverage entry, final AdapterToIndexMapping indexMapping, final Index index) {
    final PersistentDataset<Object> adapterExtendedData = new SingleFieldPersistentDataset<>();
    adapterExtendedData.addValue(RasterDataAdapter.DATA_FIELD_ID, ((RasterDataAdapter) adapter).getRasterTileFromCoverage(entry));
    final AdapterPersistenceEncoding encoding;
    if (entry instanceof FitToIndexGridCoverage) {
        encoding = new FitToIndexPersistenceEncoding(getAdapterId(), new byte[0], new MultiFieldPersistentDataset<>(), adapterExtendedData, ((FitToIndexGridCoverage) entry).getPartitionKey(), ((FitToIndexGridCoverage) entry).getSortKey());
    } else {
        // this shouldn't happen
        LOGGER.warn("Grid coverage is not fit to the index");
        encoding = new AdapterPersistenceEncoding(getAdapterId(), new byte[0], new MultiFieldPersistentDataset<>(), adapterExtendedData);
    }
    return encoding;
}
Also used : FitToIndexGridCoverage(org.locationtech.geowave.adapter.raster.FitToIndexGridCoverage) MultiFieldPersistentDataset(org.locationtech.geowave.core.store.data.MultiFieldPersistentDataset) AdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.AdapterPersistenceEncoding) IndexedAdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.IndexedAdapterPersistenceEncoding) FitToIndexPersistenceEncoding(org.locationtech.geowave.core.store.adapter.FitToIndexPersistenceEncoding) SingleFieldPersistentDataset(org.locationtech.geowave.core.store.data.SingleFieldPersistentDataset)

Example 3 with AdapterPersistenceEncoding

use of org.locationtech.geowave.core.store.adapter.AdapterPersistenceEncoding in project geowave by locationtech.

the class FeatureDataAdapterTest method testDifferentProjection.

@Test
public void testDifferentProjection() throws SchemaException {
    final SimpleFeatureType schema = DataUtilities.createType("sp.geostuff", "geometry:Geometry:srid=3005,pop:java.lang.Long");
    final FeatureDataAdapter dataAdapter = new FeatureDataAdapter(schema);
    final Index spatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
    final AdapterToIndexMapping indexMapping = BaseDataStoreUtils.mapAdapterToIndex(dataAdapter.asInternalAdapter((short) -1), spatialIndex);
    final CoordinateReferenceSystem crs = dataAdapter.getFeatureType().getCoordinateReferenceSystem();
    // assertTrue(crs.getIdentifiers().toString().contains("EPSG:4326"));
    @SuppressWarnings("unchecked") final SimpleFeature newFeature = FeatureDataUtils.buildFeature(schema, new Pair[] { Pair.of("geometry", factory.createPoint(new Coordinate(27.25, 41.25))), Pair.of("pop", Long.valueOf(100)) });
    final AdapterPersistenceEncoding persistenceEncoding = dataAdapter.asInternalAdapter((short) -1).encode(newFeature, indexMapping, spatialIndex);
    Geometry geom = null;
    for (final Entry<String, ?> pv : persistenceEncoding.getCommonData().getValues().entrySet()) {
        if (pv.getValue() instanceof Geometry) {
            geom = (Geometry) pv.getValue();
        }
    }
    assertNotNull(geom);
    assertEquals(new Coordinate(-138.0, 44.0), geom.getCentroid().getCoordinate());
}
Also used : AdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.AdapterPersistenceEncoding) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) Index(org.locationtech.geowave.core.store.api.Index) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Geometry(org.locationtech.jts.geom.Geometry) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

Aggregations

AdapterPersistenceEncoding (org.locationtech.geowave.core.store.adapter.AdapterPersistenceEncoding)3 IndexedAdapterPersistenceEncoding (org.locationtech.geowave.core.store.adapter.IndexedAdapterPersistenceEncoding)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 FitToIndexGridCoverage (org.locationtech.geowave.adapter.raster.FitToIndexGridCoverage)1 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)1 CustomIndexStrategy (org.locationtech.geowave.core.index.CustomIndexStrategy)1 InsertionIds (org.locationtech.geowave.core.index.InsertionIds)1 AdapterToIndexMapping (org.locationtech.geowave.core.store.AdapterToIndexMapping)1 FitToIndexPersistenceEncoding (org.locationtech.geowave.core.store.adapter.FitToIndexPersistenceEncoding)1 Index (org.locationtech.geowave.core.store.api.Index)1 FieldInfo (org.locationtech.geowave.core.store.base.IntermediaryWriteEntryInfo.FieldInfo)1 MultiFieldPersistentDataset (org.locationtech.geowave.core.store.data.MultiFieldPersistentDataset)1 SingleFieldPersistentDataset (org.locationtech.geowave.core.store.data.SingleFieldPersistentDataset)1 VisibilityComposer (org.locationtech.geowave.core.store.data.visibility.VisibilityComposer)1 GeoWaveValueImpl (org.locationtech.geowave.core.store.entities.GeoWaveValueImpl)1 CommonIndexModel (org.locationtech.geowave.core.store.index.CommonIndexModel)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 Geometry (org.locationtech.jts.geom.Geometry)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1