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