Search in sources :

Example 1 with AdapterWithObjectWritable

use of org.locationtech.geowave.analytic.AdapterWithObjectWritable in project geowave by locationtech.

the class DBScanMapReduceTest method test8With4.

@Test
public void test8With4() throws IOException {
    final Random r = new Random(3434);
    for (int i = 0; i < 8; i++) {
        final SimpleFeature feature = createTestFeature("f" + i, new Coordinate(round(30.0 + (r.nextGaussian() * 0.00001)), round(30.0 + (r.nextGaussian() * 0.00001))));
        mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature.getID())), feature);
    }
    final List<Pair<PartitionDataWritable, AdapterWithObjectWritable>> mapperResults = mapDriver.run();
    final List<Pair<PartitionDataWritable, List<AdapterWithObjectWritable>>> partitions = getReducerDataFromMapperInput(mapperResults);
    reduceDriver.addAll(partitions);
    reduceDriver.getConfiguration().setInt(GeoWaveConfiguratorBase.enumToConfKey(NNMapReduce.class, ClusteringParameters.Clustering.MINIMUM_SIZE), 4);
    final List<Pair<GeoWaveInputKey, ObjectWritable>> reduceResults = reduceDriver.run();
    assertEquals(1, reduceResults.size());
}
Also used : AdapterWithObjectWritable(org.locationtech.geowave.analytic.AdapterWithObjectWritable) Random(java.util.Random) Coordinate(org.locationtech.jts.geom.Coordinate) ByteArray(org.locationtech.geowave.core.index.ByteArray) GeoWaveInputKey(org.locationtech.geowave.mapreduce.input.GeoWaveInputKey) SimpleFeature(org.opengis.feature.simple.SimpleFeature) NNMapReduce(org.locationtech.geowave.analytic.mapreduce.nn.NNMapReduce) Pair(org.apache.hadoop.mrunit.types.Pair) Test(org.junit.Test)

Example 2 with AdapterWithObjectWritable

use of org.locationtech.geowave.analytic.AdapterWithObjectWritable in project geowave by locationtech.

the class DBScanMapReduceTest method getListFor.

private List<AdapterWithObjectWritable> getListFor(final PartitionDataWritable pd, final List<Pair<PartitionDataWritable, List<AdapterWithObjectWritable>>> reducerInputSet) {
    for (final Pair<PartitionDataWritable, List<AdapterWithObjectWritable>> pair : reducerInputSet) {
        if (pair.getFirst().compareTo(pd) == 0) {
            return pair.getSecond();
        }
    }
    final List<AdapterWithObjectWritable> newPairList = new ArrayList<>();
    reducerInputSet.add(new Pair(pd, newPairList));
    return newPairList;
}
Also used : AdapterWithObjectWritable(org.locationtech.geowave.analytic.AdapterWithObjectWritable) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PartitionDataWritable(org.locationtech.geowave.analytic.mapreduce.nn.NNMapReduce.PartitionDataWritable) Pair(org.apache.hadoop.mrunit.types.Pair)

Example 3 with AdapterWithObjectWritable

use of org.locationtech.geowave.analytic.AdapterWithObjectWritable in project geowave by locationtech.

the class DBScanMapReduceTest method testReducer.

@Test
public void testReducer() throws IOException {
    final SimpleFeature feature1 = createTestFeature("f1", new Coordinate(30.0, 30.00000001));
    final SimpleFeature feature2 = createTestFeature("f2", new Coordinate(50.001, 50.001));
    final SimpleFeature feature3 = createTestFeature("f3", new Coordinate(30.00000001, 30.00000001));
    final SimpleFeature feature4 = createTestFeature("f4", new Coordinate(50.0011, 50.00105));
    final SimpleFeature feature5 = createTestFeature("f5", new Coordinate(50.00112, 50.00111));
    final SimpleFeature feature6 = createTestFeature("f6", new Coordinate(30.00000001, 30.00000002));
    final SimpleFeature feature7 = createTestFeature("f7", new Coordinate(50.00113, 50.00114));
    final SimpleFeature feature8 = createTestFeature("f8", new Coordinate(40.00000001, 40.000000002));
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature1.getID())), feature1);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature2.getID())), feature2);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature3.getID())), feature3);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature4.getID())), feature4);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature5.getID())), feature5);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature6.getID())), feature6);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature7.getID())), feature7);
    mapDriver.addInput(new GeoWaveInputKey(adapterId, new ByteArray(feature8.getID())), feature8);
    final List<Pair<PartitionDataWritable, AdapterWithObjectWritable>> mapperResults = mapDriver.run();
    assertNotNull(getPartitionDataFor(mapperResults, feature1.getID(), true));
    assertNotNull(getPartitionDataFor(mapperResults, feature2.getID(), true));
    assertNotNull(getPartitionDataFor(mapperResults, feature2.getID(), true));
    assertNotNull(getPartitionDataFor(mapperResults, feature3.getID(), true));
    assertEquals(getPartitionDataFor(mapperResults, feature1.getID(), true).getCompositeKey(), getPartitionDataFor(mapperResults, feature3.getID(), true).getCompositeKey());
    assertEquals(getPartitionDataFor(mapperResults, feature6.getID(), true).getCompositeKey(), getPartitionDataFor(mapperResults, feature3.getID(), true).getCompositeKey());
    assertEquals(getPartitionDataFor(mapperResults, feature5.getID(), true).getCompositeKey(), getPartitionDataFor(mapperResults, feature7.getID(), true).getCompositeKey());
    assertEquals(getPartitionDataFor(mapperResults, feature5.getID(), true).getCompositeKey(), getPartitionDataFor(mapperResults, feature4.getID(), true).getCompositeKey());
    final List<Pair<PartitionDataWritable, List<AdapterWithObjectWritable>>> partitions = getReducerDataFromMapperInput(mapperResults);
    reduceDriver.addAll(partitions);
    reduceDriver.getConfiguration().setInt(GeoWaveConfiguratorBase.enumToConfKey(NNMapReduce.class, ClusteringParameters.Clustering.MINIMUM_SIZE), 2);
    final List<Pair<GeoWaveInputKey, ObjectWritable>> reduceResults = reduceDriver.run();
    assertEquals(2, reduceResults.size());
/*
     * assertEquals( feature3.getID(), find( reduceResults, feature1.getID()).toString());
     *
     * assertEquals( feature1.getID(), find( reduceResults, feature3.getID()).toString());
     *
     * assertEquals( feature4.getID(), find( reduceResults, feature2.getID()).toString());
     *
     * assertEquals( feature2.getID(), find( reduceResults, feature4.getID()).toString());
     */
}
Also used : AdapterWithObjectWritable(org.locationtech.geowave.analytic.AdapterWithObjectWritable) Coordinate(org.locationtech.jts.geom.Coordinate) ByteArray(org.locationtech.geowave.core.index.ByteArray) GeoWaveInputKey(org.locationtech.geowave.mapreduce.input.GeoWaveInputKey) SimpleFeature(org.opengis.feature.simple.SimpleFeature) NNMapReduce(org.locationtech.geowave.analytic.mapreduce.nn.NNMapReduce) Pair(org.apache.hadoop.mrunit.types.Pair) Test(org.junit.Test)

Example 4 with AdapterWithObjectWritable

use of org.locationtech.geowave.analytic.AdapterWithObjectWritable in project geowave by locationtech.

the class NNMapReduceTest method testMapper.

@Test
public void testMapper() throws IOException {
    final SimpleFeature feature1 = createTestFeature(new Coordinate(30.0, 30.00000001));
    final SimpleFeature feature2 = createTestFeature(new Coordinate(179.9999999999, 30.0000001));
    final SimpleFeature feature3 = createTestFeature(new Coordinate(30.00000001, 30.00000001));
    final SimpleFeature feature4 = createTestFeature(new Coordinate(-179.9999999999, 30.0000001));
    final GeoWaveInputKey inputKey1 = new GeoWaveInputKey();
    inputKey1.setInternalAdapterId(internalAdapterId);
    inputKey1.setDataId(new ByteArray(feature1.getID()));
    final GeoWaveInputKey inputKey2 = new GeoWaveInputKey();
    inputKey2.setInternalAdapterId(internalAdapterId);
    inputKey2.setDataId(new ByteArray(feature2.getID()));
    final GeoWaveInputKey inputKey3 = new GeoWaveInputKey();
    inputKey3.setInternalAdapterId(internalAdapterId);
    inputKey3.setDataId(new ByteArray(feature4.getID()));
    final GeoWaveInputKey inputKey4 = new GeoWaveInputKey();
    inputKey4.setInternalAdapterId(internalAdapterId);
    inputKey4.setDataId(new ByteArray(feature4.getID()));
    mapDriver.addInput(inputKey1, feature1);
    mapDriver.addInput(inputKey2, feature2);
    mapDriver.addInput(inputKey3, feature3);
    mapDriver.addInput(inputKey4, feature4);
    final List<Pair<PartitionDataWritable, AdapterWithObjectWritable>> mapperResults = mapDriver.run();
    assertEquals(// includes overlap
    10, mapperResults.size());
    assertFalse(getPartitionDataFor(mapperResults, feature1.getID(), true).isEmpty());
    assertFalse(getPartitionDataFor(mapperResults, feature2.getID(), true).isEmpty());
    assertFalse(getPartitionDataFor(mapperResults, feature2.getID(), false).isEmpty());
    assertFalse(getPartitionDataFor(mapperResults, feature3.getID(), true).isEmpty());
    assertTrue(intersects(getPartitionDataFor(mapperResults, feature1.getID(), true), getPartitionDataFor(mapperResults, feature3.getID(), true)));
    assertTrue(intersects(getPartitionDataFor(mapperResults, feature2.getID(), false), getPartitionDataFor(mapperResults, feature4.getID(), false)));
    final List<Pair<PartitionDataWritable, List<AdapterWithObjectWritable>>> partitions = getReducerDataFromMapperInput(mapperResults);
    assertEquals(3, partitions.size());
    reduceDriver.addAll(partitions);
    final List<Pair<Text, Text>> reduceResults = reduceDriver.run();
    assertEquals(4, reduceResults.size());
    assertEquals(feature3.getID(), find(reduceResults, feature1.getID()).toString());
    assertEquals(feature1.getID(), find(reduceResults, feature3.getID()).toString());
    assertEquals(feature4.getID(), find(reduceResults, feature2.getID()).toString());
    assertEquals(feature2.getID(), find(reduceResults, feature4.getID()).toString());
}
Also used : AdapterWithObjectWritable(org.locationtech.geowave.analytic.AdapterWithObjectWritable) Coordinate(org.locationtech.jts.geom.Coordinate) ByteArray(org.locationtech.geowave.core.index.ByteArray) GeoWaveInputKey(org.locationtech.geowave.mapreduce.input.GeoWaveInputKey) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Pair(org.apache.hadoop.mrunit.types.Pair) Test(org.junit.Test)

Example 5 with AdapterWithObjectWritable

use of org.locationtech.geowave.analytic.AdapterWithObjectWritable in project geowave by locationtech.

the class NNMapReduceTest method getListFor.

private List<AdapterWithObjectWritable> getListFor(final PartitionDataWritable pd, final List<Pair<PartitionDataWritable, List<AdapterWithObjectWritable>>> reducerInputSet) {
    for (final Pair<PartitionDataWritable, List<AdapterWithObjectWritable>> pair : reducerInputSet) {
        if (pair.getFirst().compareTo(pd) == 0) {
            return pair.getSecond();
        }
    }
    final List<AdapterWithObjectWritable> newPairList = new ArrayList<>();
    reducerInputSet.add(new Pair(pd, newPairList));
    return newPairList;
}
Also used : AdapterWithObjectWritable(org.locationtech.geowave.analytic.AdapterWithObjectWritable) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PartitionDataWritable(org.locationtech.geowave.analytic.mapreduce.nn.NNMapReduce.PartitionDataWritable) Pair(org.apache.hadoop.mrunit.types.Pair)

Aggregations

Pair (org.apache.hadoop.mrunit.types.Pair)6 AdapterWithObjectWritable (org.locationtech.geowave.analytic.AdapterWithObjectWritable)6 Test (org.junit.Test)4 ByteArray (org.locationtech.geowave.core.index.ByteArray)4 GeoWaveInputKey (org.locationtech.geowave.mapreduce.input.GeoWaveInputKey)4 Coordinate (org.locationtech.jts.geom.Coordinate)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 NNMapReduce (org.locationtech.geowave.analytic.mapreduce.nn.NNMapReduce)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Random (java.util.Random)2 PartitionDataWritable (org.locationtech.geowave.analytic.mapreduce.nn.NNMapReduce.PartitionDataWritable)2