Search in sources :

Example 1 with GeoWaveRowImpl

use of org.locationtech.geowave.core.store.entities.GeoWaveRowImpl in project geowave by locationtech.

the class PartitionsStatisticTest method testIngest.

@Test
public void testIngest() {
    final PartitionsStatistic statistic = new PartitionsStatistic();
    final PartitionsValue value = statistic.createEmpty();
    for (long i = 0; i < 10000; i++) {
        final GeoWaveRow row = new GeoWaveRowImpl(genKey(i), new GeoWaveValue[] {});
        value.entryIngested(null, 1, row);
    }
    assertEquals(32, value.getValue().size());
    for (byte i = 0; i < 32; i++) {
        Assert.assertTrue(value.getValue().contains(new ByteArray(new byte[] { i })));
    }
}
Also used : GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) GeoWaveRowImpl(org.locationtech.geowave.core.store.entities.GeoWaveRowImpl) PartitionsValue(org.locationtech.geowave.core.store.statistics.index.PartitionsStatistic.PartitionsValue) ByteArray(org.locationtech.geowave.core.index.ByteArray) Test(org.junit.Test)

Example 2 with GeoWaveRowImpl

use of org.locationtech.geowave.core.store.entities.GeoWaveRowImpl in project geowave by locationtech.

the class RowRangeHistogramStatisticTest method testIngest.

@Test
public void testIngest() {
    final RowRangeHistogramStatistic stats = new RowRangeHistogramStatistic("indexName");
    final RowRangeHistogramValue value = stats.createEmpty();
    for (long i = 0; i < 10000; i++) {
        final GeoWaveRow row = new GeoWaveRowImpl(genKey(i), new GeoWaveValue[] {});
        value.entryIngested(null, 1, row);
    }
    System.out.println(stats.toString());
    assertEquals(1.0, value.cdf(genKey(10000).getSortKey()), 0.00001);
    assertEquals(0.0, value.cdf(genKey(0).getSortKey()), 0.00001);
    assertEquals(0.5, value.cdf(genKey(5000).getSortKey()), 0.04);
    final RowRangeHistogramValue value2 = stats.createEmpty();
    for (long j = 10000; j < 20000; j++) {
        final GeoWaveRow row = new GeoWaveRowImpl(genKey(j), new GeoWaveValue[] {});
        value2.entryIngested(null, 1, row);
    }
    assertEquals(0.0, value2.cdf(genKey(10000).getSortKey()), 0.00001);
    value.merge(value2);
    assertEquals(0.5, value.cdf(genKey(10000).getSortKey()), 0.15);
    value2.fromBinary(value.toBinary());
    assertEquals(0.5, value2.cdf(genKey(10000).getSortKey()), 0.15);
}
Also used : GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) GeoWaveRowImpl(org.locationtech.geowave.core.store.entities.GeoWaveRowImpl) RowRangeHistogramValue(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic.RowRangeHistogramValue) Test(org.junit.Test)

Example 3 with GeoWaveRowImpl

use of org.locationtech.geowave.core.store.entities.GeoWaveRowImpl in project geowave by locationtech.

the class DataStoreUtils method mergeSingleRowValues.

public static GeoWaveRow mergeSingleRowValues(final GeoWaveRow singleRow, final RowTransform rowTransform) {
    if (singleRow.getFieldValues().length < 2) {
        return singleRow;
    }
    // merge all values into a single value
    Mergeable merged = null;
    for (final GeoWaveValue fieldValue : singleRow.getFieldValues()) {
        final Mergeable mergeable = rowTransform.getRowAsMergeableObject(singleRow.getAdapterId(), new ByteArray(fieldValue.getFieldMask()), fieldValue.getValue());
        if (merged == null) {
            merged = mergeable;
        } else {
            merged.merge(mergeable);
        }
    }
    final GeoWaveValue[] mergedFieldValues = new GeoWaveValue[] { new GeoWaveValueImpl(singleRow.getFieldValues()[0].getFieldMask(), singleRow.getFieldValues()[0].getVisibility(), rowTransform.getBinaryFromMergedObject(merged)) };
    return new GeoWaveRowImpl(new GeoWaveKeyImpl(singleRow.getDataId(), singleRow.getAdapterId(), singleRow.getPartitionKey(), singleRow.getSortKey(), singleRow.getNumberOfDuplicates()), mergedFieldValues);
}
Also used : Mergeable(org.locationtech.geowave.core.index.Mergeable) GeoWaveRowImpl(org.locationtech.geowave.core.store.entities.GeoWaveRowImpl) GeoWaveValueImpl(org.locationtech.geowave.core.store.entities.GeoWaveValueImpl) GeoWaveKeyImpl(org.locationtech.geowave.core.store.entities.GeoWaveKeyImpl) ByteArray(org.locationtech.geowave.core.index.ByteArray) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue)

Example 4 with GeoWaveRowImpl

use of org.locationtech.geowave.core.store.entities.GeoWaveRowImpl in project geowave by locationtech.

the class ChooseBestMatchIndexQueryStrategyTest method testChooseSpatialTemporalWithStats.

@Test
public void testChooseSpatialTemporalWithStats() {
    final Index temporalindex = new SpatialTemporalIndexBuilder().createIndex();
    final Index spatialIndex = new SpatialIndexBuilder().createIndex();
    final RowRangeHistogramStatistic rangeTempStats = new RowRangeHistogramStatistic(temporalindex.getName());
    rangeTempStats.setBinningStrategy(new CompositeBinningStrategy(new DataTypeBinningStrategy(), new PartitionBinningStrategy()));
    rangeTempStats.setInternal();
    final RowRangeHistogramStatistic rangeStats = new RowRangeHistogramStatistic(spatialIndex.getName());
    rangeStats.setBinningStrategy(new CompositeBinningStrategy(new DataTypeBinningStrategy(), new PartitionBinningStrategy()));
    rangeStats.setInternal();
    final Map<StatisticId<?>, Map<ByteArray, StatisticValue<?>>> statsMap = new HashMap<>();
    final ChooseBestMatchIndexQueryStrategy strategy = new ChooseBestMatchIndexQueryStrategy();
    final ConstraintSet cs1 = new ConstraintSet();
    cs1.addConstraint(LatitudeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.3, 0.5), true));
    cs1.addConstraint(LongitudeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.4, 0.7), true));
    final ConstraintSet cs2a = new ConstraintSet();
    cs2a.addConstraint(TimeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.1, 0.2), true));
    final ConstraintsByClass constraints = new ConstraintsByClass(Arrays.asList(cs2a)).merge(Collections.singletonList(cs1));
    final BasicQueryByClass query = new BasicQueryByClass(constraints);
    final NumericIndexStrategy temporalIndexStrategy = new SpatialTemporalIndexBuilder().createIndex().getIndexStrategy();
    final Random r = new Random(SEED);
    for (int i = 0; i < ROWS; i++) {
        final double x = r.nextDouble();
        final double y = r.nextDouble();
        final double t = r.nextDouble();
        final InsertionIds id = temporalIndexStrategy.getInsertionIds(new BasicNumericDataset(new NumericData[] { new NumericValue(x), new NumericValue(y), new NumericValue(t) }));
        for (final SinglePartitionInsertionIds range : id.getPartitionKeys()) {
            Map<ByteArray, StatisticValue<?>> binValues = statsMap.get(rangeTempStats.getId());
            if (binValues == null) {
                binValues = Maps.newHashMap();
                statsMap.put(rangeTempStats.getId(), binValues);
            }
            final ByteArray bin = CompositeBinningStrategy.getBin(DataTypeBinningStrategy.getBin((String) null), PartitionBinningStrategy.getBin(range.getPartitionKey()));
            RowRangeHistogramValue value = (RowRangeHistogramValue) binValues.get(bin);
            if (value == null) {
                value = rangeTempStats.createEmpty();
                value.setBin(bin);
                binValues.put(bin, value);
            }
            ((StatisticsIngestCallback) value).entryIngested(null, null, new GeoWaveRowImpl(new GeoWaveKeyImpl(new byte[] { 1 }, (short) 1, range.getPartitionKey(), range.getSortKeys().get(0), 0), new GeoWaveValue[] {}));
        }
    }
    final Index index = new SpatialIndexBuilder().createIndex();
    final NumericIndexStrategy indexStrategy = index.getIndexStrategy();
    for (int i = 0; i < ROWS; i++) {
        final double x = r.nextDouble();
        final double y = r.nextDouble();
        final double t = r.nextDouble();
        final InsertionIds id = indexStrategy.getInsertionIds(new BasicNumericDataset(new NumericData[] { new NumericValue(x), new NumericValue(y), new NumericValue(t) }));
        for (final SinglePartitionInsertionIds range : id.getPartitionKeys()) {
            Map<ByteArray, StatisticValue<?>> binValues = statsMap.get(rangeStats.getId());
            if (binValues == null) {
                binValues = Maps.newHashMap();
                statsMap.put(rangeStats.getId(), binValues);
            }
            final ByteArray bin = CompositeBinningStrategy.getBin(DataTypeBinningStrategy.getBin((String) null), PartitionBinningStrategy.getBin(range.getPartitionKey()));
            RowRangeHistogramValue value = (RowRangeHistogramValue) binValues.get(bin);
            if (value == null) {
                value = rangeStats.createEmpty();
                value.setBin(bin);
                binValues.put(bin, value);
            }
            ((StatisticsIngestCallback) value).entryIngested(null, null, new GeoWaveRowImpl(new GeoWaveKeyImpl(new byte[] { 1 }, (short) 1, range.getPartitionKey(), range.getSortKeys().get(0), 0), new GeoWaveValue[] {}));
        }
    }
    final Iterator<Index> it = getIndices(new TestDataStatisticsStore(Lists.newArrayList(rangeStats, rangeTempStats), statsMap), query, strategy);
    assertTrue(it.hasNext());
    assertEquals(temporalindex.getName(), it.next().getName());
    assertFalse(it.hasNext());
}
Also used : SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) HashMap(java.util.HashMap) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) StatisticId(org.locationtech.geowave.core.store.statistics.StatisticId) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) NullIndex(org.locationtech.geowave.core.store.index.NullIndex) Index(org.locationtech.geowave.core.store.api.Index) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) RowRangeHistogramStatistic(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic) Random(java.util.Random) SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) ByteArray(org.locationtech.geowave.core.index.ByteArray) StatisticsIngestCallback(org.locationtech.geowave.core.store.statistics.StatisticsIngestCallback) ConstraintData(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData) RowRangeHistogramValue(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic.RowRangeHistogramValue) DataTypeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.DataTypeBinningStrategy) ConstraintSet(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet) GeoWaveRowImpl(org.locationtech.geowave.core.store.entities.GeoWaveRowImpl) CompositeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.CompositeBinningStrategy) GeoWaveKeyImpl(org.locationtech.geowave.core.store.entities.GeoWaveKeyImpl) SpatialTemporalIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder) PartitionBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.PartitionBinningStrategy) NumericValue(org.locationtech.geowave.core.index.numeric.NumericValue) Map(java.util.Map) HashMap(java.util.HashMap) BasicQueryByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass) NumericIndexStrategy(org.locationtech.geowave.core.index.NumericIndexStrategy) Test(org.junit.Test)

Example 5 with GeoWaveRowImpl

use of org.locationtech.geowave.core.store.entities.GeoWaveRowImpl in project geowave by locationtech.

the class FileSystemRowDeleter method delete.

@Override
public void delete(final GeoWaveRow row) {
    final FileSystemIndexTable table = tableCache.get(new CacheKey(row.getAdapterId(), internalAdapterStore.getTypeName(row.getAdapterId()), indexName, row.getPartitionKey()));
    if (row instanceof GeoWaveRowImpl) {
        final GeoWaveKey key = ((GeoWaveRowImpl) row).getKey();
        if (key instanceof FileSystemRow) {
            deleteRow(table, (FileSystemRow) key);
        } else {
            LOGGER.info("Unable to convert scanned row into FileSystemRow for deletion.  Row is of type GeoWaveRowImpl.");
            table.delete(key.getSortKey(), key.getDataId());
        }
    } else if (row instanceof FileSystemRow) {
        deleteRow(table, (FileSystemRow) row);
    } else {
        LOGGER.info("Unable to convert scanned row into FileSystemRow for deletion. Row is of type " + row.getClass());
        table.delete(row.getSortKey(), row.getDataId());
    }
}
Also used : GeoWaveRowImpl(org.locationtech.geowave.core.store.entities.GeoWaveRowImpl) FileSystemIndexTable(org.locationtech.geowave.datastore.filesystem.util.FileSystemIndexTable) GeoWaveKey(org.locationtech.geowave.core.store.entities.GeoWaveKey) FileSystemRow(org.locationtech.geowave.datastore.filesystem.util.FileSystemRow)

Aggregations

GeoWaveRowImpl (org.locationtech.geowave.core.store.entities.GeoWaveRowImpl)7 Test (org.junit.Test)3 ByteArray (org.locationtech.geowave.core.index.ByteArray)3 GeoWaveValue (org.locationtech.geowave.core.store.entities.GeoWaveValue)3 GeoWaveKey (org.locationtech.geowave.core.store.entities.GeoWaveKey)2 GeoWaveKeyImpl (org.locationtech.geowave.core.store.entities.GeoWaveKeyImpl)2 GeoWaveRow (org.locationtech.geowave.core.store.entities.GeoWaveRow)2 GeoWaveValueImpl (org.locationtech.geowave.core.store.entities.GeoWaveValueImpl)2 RowRangeHistogramValue (org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic.RowRangeHistogramValue)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 ExecutionException (java.util.concurrent.ExecutionException)1 RegionException (org.apache.hadoop.hbase.RegionException)1 TableExistsException (org.apache.hadoop.hbase.TableExistsException)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 Table (org.apache.hadoop.hbase.client.Table)1 MultiRowRangeFilter (org.apache.hadoop.hbase.filter.MultiRowRangeFilter)1