Search in sources :

Example 1 with InsertionIds

use of org.locationtech.geowave.core.index.InsertionIds in project geowave by locationtech.

the class IndexCompositeWriter method internalWrite.

protected WriteResults internalWrite(final T entry, final Function<Writer<T>, WriteResults> internalWriter) {
    final Map<String, List<SinglePartitionInsertionIds>> insertionIdsPerIndex = new HashMap<>();
    for (final Writer<T> indexWriter : writers) {
        final WriteResults ids = internalWriter.apply(indexWriter);
        for (final String indexName : ids.getWrittenIndexNames()) {
            List<SinglePartitionInsertionIds> partitionInsertionIds = insertionIdsPerIndex.get(indexName);
            if (partitionInsertionIds == null) {
                partitionInsertionIds = new ArrayList<>();
                insertionIdsPerIndex.put(indexName, partitionInsertionIds);
            }
            partitionInsertionIds.addAll(ids.getInsertionIdsWritten(indexName).getPartitionKeys());
        }
    }
    return new WriteResults(Maps.transformValues(insertionIdsPerIndex, v -> new InsertionIds(v)));
}
Also used : Arrays(java.util.Arrays) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) HashMap(java.util.HashMap) Function(java.util.function.Function) Maps(com.google.common.collect.Maps) ArrayList(java.util.ArrayList) WriteResults(org.locationtech.geowave.core.store.api.WriteResults) List(java.util.List) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) Writer(org.locationtech.geowave.core.store.api.Writer) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) Map(java.util.Map) Index(org.locationtech.geowave.core.store.api.Index) WriteResults(org.locationtech.geowave.core.store.api.WriteResults) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) HashMap(java.util.HashMap) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with InsertionIds

use of org.locationtech.geowave.core.index.InsertionIds in project geowave by locationtech.

the class DataStoreUtils method keysToInsertionIds.

public static InsertionIds keysToInsertionIds(final GeoWaveKey... geoWaveKeys) {
    final Map<ByteArray, List<byte[]>> sortKeysPerPartition = new HashMap<>();
    for (final GeoWaveKey key : geoWaveKeys) {
        final ByteArray partitionKey = new ByteArray(key.getPartitionKey());
        List<byte[]> sortKeys = sortKeysPerPartition.get(partitionKey);
        if (sortKeys == null) {
            sortKeys = new ArrayList<>();
            sortKeysPerPartition.put(partitionKey, sortKeys);
        }
        sortKeys.add(key.getSortKey());
    }
    final Set<SinglePartitionInsertionIds> insertionIds = new HashSet<>();
    for (final Entry<ByteArray, List<byte[]>> e : sortKeysPerPartition.entrySet()) {
        insertionIds.add(new SinglePartitionInsertionIds(e.getKey().getBytes(), e.getValue()));
    }
    return new InsertionIds(insertionIds);
}
Also used : SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) HashMap(java.util.HashMap) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) GeoWaveKey(org.locationtech.geowave.core.store.entities.GeoWaveKey) ByteArray(org.locationtech.geowave.core.index.ByteArray) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 3 with InsertionIds

use of org.locationtech.geowave.core.index.InsertionIds in project geowave by locationtech.

the class AbstractPartitioner method partition.

@Override
public void partition(final T entry, final PartitionDataCallback callback) throws Exception {
    final NumericDataHolder numericData = getNumericData(entry);
    if (numericData == null) {
        return;
    }
    final InsertionIds primaryIds = getIndex().getIndexStrategy().getInsertionIds(numericData.primary);
    for (final SinglePartitionInsertionIds partitionInsertionIds : primaryIds.getPartitionKeys()) {
        for (final byte[] sortKey : partitionInsertionIds.getSortKeys()) {
            callback.partitionWith(new PartitionData(new ByteArray(partitionInsertionIds.getPartitionKey()), new ByteArray(sortKey), true));
        }
    }
    for (final MultiDimensionalNumericData expansionData : numericData.expansion) {
        final InsertionIds expansionIds = getIndex().getIndexStrategy().getInsertionIds(expansionData);
        for (final SinglePartitionInsertionIds partitionInsertionIds : expansionIds.getPartitionKeys()) {
            for (final byte[] sortKey : partitionInsertionIds.getSortKeys()) {
                callback.partitionWith(new PartitionData(new ByteArray(partitionInsertionIds.getPartitionKey()), new ByteArray(sortKey), false));
            }
        }
    }
}
Also used : MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) ByteArray(org.locationtech.geowave.core.index.ByteArray)

Example 4 with InsertionIds

use of org.locationtech.geowave.core.index.InsertionIds in project geowave by locationtech.

the class CQLQueryFilterTest method getEncodings.

private static List<IndexedAdapterPersistenceEncoding> getEncodings(final Index index, final AdapterPersistenceEncoding encoding) {
    final InsertionIds ids = encoding.getInsertionIds(index);
    final ArrayList<IndexedAdapterPersistenceEncoding> encodings = new ArrayList<>();
    for (final SinglePartitionInsertionIds partitionIds : ids.getPartitionKeys()) {
        for (final byte[] sortKey : partitionIds.getSortKeys()) {
            encodings.add(new IndexedAdapterPersistenceEncoding(encoding.getInternalAdapterId(), encoding.getDataId(), partitionIds.getPartitionKey(), sortKey, ids.getSize(), encoding.getCommonData(), encoding.getUnknownData(), encoding.getAdapterExtendedData()));
        }
    }
    return encodings;
}
Also used : SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) ArrayList(java.util.ArrayList) IndexedAdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.IndexedAdapterPersistenceEncoding)

Example 5 with InsertionIds

use of org.locationtech.geowave.core.index.InsertionIds in project geowave by locationtech.

the class TieredSFCIndexStrategyTest method testPredefinedSpatialEntries.

@Test
public void testPredefinedSpatialEntries() throws Exception {
    final NumericIndexStrategy strategy = TieredSFCIndexFactory.createDefinedPrecisionTieredStrategy(new NumericDimensionDefinition[] { new LongitudeDefinition(), new LatitudeDefinition(true) }, new int[][] { DEFINED_BITS_OF_PRECISION.clone(), DEFINED_BITS_OF_PRECISION.clone() }, SFCType.HILBERT);
    for (int sfcIndex = 0; sfcIndex < DEFINED_BITS_OF_PRECISION.length; sfcIndex++) {
        final NumericData[] dataPerDimension = new NumericData[2];
        final double precision = 360 / Math.pow(2, DEFINED_BITS_OF_PRECISION[sfcIndex]);
        if (precision > 180) {
            dataPerDimension[0] = new NumericRange(-180, 180);
            dataPerDimension[1] = new NumericRange(-90, 90);
        } else {
            dataPerDimension[0] = new NumericRange(0, precision);
            dataPerDimension[1] = new NumericRange(-precision, 0);
        }
        final MultiDimensionalNumericData indexedData = new BasicNumericDataset(dataPerDimension);
        final InsertionIds ids = strategy.getInsertionIds(indexedData);
        final NumericData[] queryRangePerDimension = new NumericData[2];
        queryRangePerDimension[0] = new NumericRange(dataPerDimension[0].getMin() + QUERY_RANGE_EPSILON, dataPerDimension[0].getMax() - QUERY_RANGE_EPSILON);
        queryRangePerDimension[1] = new NumericRange(dataPerDimension[1].getMin() + QUERY_RANGE_EPSILON, dataPerDimension[1].getMax() - QUERY_RANGE_EPSILON);
        final MultiDimensionalNumericData queryData = new BasicNumericDataset(queryRangePerDimension);
        final QueryRanges queryRanges = strategy.getQueryRanges(queryData);
        final Set<Byte> queryRangeTiers = new HashSet<>();
        boolean rangeAtTierFound = false;
        for (final ByteArrayRange range : queryRanges.getCompositeQueryRanges()) {
            final byte tier = range.getStart()[0];
            queryRangeTiers.add(range.getStart()[0]);
            if (tier == DEFINED_BITS_OF_PRECISION[sfcIndex]) {
                if (rangeAtTierFound) {
                    throw new Exception("multiple ranges were found unexpectedly for tier " + tier);
                }
                assertArrayEquals("this range is an exact fit, so it should have exactly one value for tier " + DEFINED_BITS_OF_PRECISION[sfcIndex], range.getStart(), range.getEnd());
                rangeAtTierFound = true;
            }
        }
        if (!rangeAtTierFound) {
            throw new Exception("no ranges were found at the expected exact fit tier " + DEFINED_BITS_OF_PRECISION[sfcIndex]);
        }
        // of precision
        if ((ids.getCompositeInsertionIds().get(0)[0] == 0) || ((sfcIndex == (DEFINED_BITS_OF_PRECISION.length - 1)) || (DEFINED_BITS_OF_PRECISION[sfcIndex + 1] != (DEFINED_BITS_OF_PRECISION[sfcIndex] + 1)))) {
            assertEquals("Insertion ID expected to be exact match at tier " + DEFINED_BITS_OF_PRECISION[sfcIndex], DEFINED_BITS_OF_PRECISION[sfcIndex], ids.getCompositeInsertionIds().get(0)[0]);
            assertEquals("Insertion ID size expected to be 1 at tier " + DEFINED_BITS_OF_PRECISION[sfcIndex], 1, ids.getCompositeInsertionIds().size());
        } else {
            assertEquals("Insertion ID expected to be duplicated at tier " + DEFINED_BITS_OF_PRECISION[sfcIndex + 1], DEFINED_BITS_OF_PRECISION[sfcIndex + 1], ids.getCompositeInsertionIds().get(0)[0]);
            // if the precision is within the bounds of longitude but not
            // within latitude we will end up with 2 (rectangular
            // decomposition)
            // otherwise we will get a square decomposition of 4 ids
            final int expectedIds = (precision > 90) && (precision <= 180) ? 2 : 4;
            assertEquals("Insertion ID size expected to be " + expectedIds + " at tier " + DEFINED_BITS_OF_PRECISION[sfcIndex + 1], expectedIds, ids.getCompositeInsertionIds().size());
        }
    }
}
Also used : LatitudeDefinition(org.locationtech.geowave.core.geotime.index.dimension.LatitudeDefinition) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) QueryRanges(org.locationtech.geowave.core.index.QueryRanges) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange) ParseException(java.text.ParseException) NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) NumericIndexStrategy(org.locationtech.geowave.core.index.NumericIndexStrategy) LongitudeDefinition(org.locationtech.geowave.core.geotime.index.dimension.LongitudeDefinition) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

InsertionIds (org.locationtech.geowave.core.index.InsertionIds)22 SinglePartitionInsertionIds (org.locationtech.geowave.core.index.SinglePartitionInsertionIds)16 MultiDimensionalNumericData (org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData)9 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)7 Test (org.junit.Test)7 NumericIndexStrategy (org.locationtech.geowave.core.index.NumericIndexStrategy)7 BasicNumericDataset (org.locationtech.geowave.core.index.numeric.BasicNumericDataset)7 ByteArray (org.locationtech.geowave.core.index.ByteArray)6 NumericData (org.locationtech.geowave.core.index.numeric.NumericData)6 HashMap (java.util.HashMap)5 BinnedNumericDataset (org.locationtech.geowave.core.index.numeric.BinnedNumericDataset)5 NumericRange (org.locationtech.geowave.core.index.numeric.NumericRange)5 List (java.util.List)4 Map (java.util.Map)4 Index (org.locationtech.geowave.core.store.api.Index)3 Maps (com.google.common.collect.Maps)2 Arrays (java.util.Arrays)2 Calendar (java.util.Calendar)2 Function (java.util.function.Function)2