private static void ingestCannedData() throws IOException {

    final List<SimpleFeature> points = new ArrayList<>();

    System.out.println("Building SimpleFeatures from canned data set...");

    for (final Entry<String, Coordinate> entry : cannedData.entrySet()) {
      System.out.println("Added point: " + entry.getKey());
      points.add(buildSimpleFeature(entry.getKey(), entry.getValue()));
    }

    System.out.println("Ingesting canned data...");

    try (IndexWriter indexWriter =
        dataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      for (final SimpleFeature sf : points) {
        //
        indexWriter.write(ADAPTER, sf);
      }
    }

    System.out.println("Ingest complete.");
  }
Ejemplo n.º 2
0
 @Override
 protected void nextBand(final SimpleFeature band, final AnalysisInfo analysisInfo) {
   bandWriter.write(band);
   super.nextBand(band, analysisInfo);
 }
  private void runtest() throws IOException {

    final PrimaryIndex index = new SpatialDimensionalityTypeProvider().createPrimaryIndex();
    final WritableDataAdapter<TestGeometry> adapter = new TestGeometryAdapter();

    final Geometry testGeoFilter =
        factory.createPolygon(
            new Coordinate[] {
              new Coordinate(24, 33),
              new Coordinate(28, 33),
              new Coordinate(28, 31),
              new Coordinate(24, 31),
              new Coordinate(24, 33)
            });

    ByteArrayId rowId0, rowId1;
    try (IndexWriter indexWriter =
        mockDataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      rowId0 =
          indexWriter
              .write(
                  adapter,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt"),
                  visWriterAAA)
              .get(0);
      rowId1 =
          indexWriter
              .write(
                  adapter,
                  new TestGeometry(factory.createPoint(new Coordinate(26, 32)), "test_pt_1"),
                  visWriterAAA)
              .get(0);
      indexWriter
          .write(
              adapter,
              new TestGeometry(factory.createPoint(new Coordinate(27, 32)), "test_pt_2"),
              visWriterBBB)
          .get(0);
    }

    final SpatialQuery query = new SpatialQuery(testGeoFilter);

    try (CloseableIterator<?> it1 =
        mockDataStore.query(
            new QueryOptions(adapter, index, -1, null, new String[] {"aaa", "bbb"}), query)) {
      int count = 0;
      while (it1.hasNext()) {
        it1.next();
        count++;
      }
      assertEquals(3, count);
    }

    CountDataStatistics<?> countStats =
        (CountDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), CountDataStatistics.STATS_ID, "aaa", "bbb");
    assertEquals(3, countStats.getCount());

    countStats =
        (CountDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), CountDataStatistics.STATS_ID, "aaa");
    assertEquals(2, countStats.getCount());

    countStats =
        (CountDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), CountDataStatistics.STATS_ID, "bbb");
    assertEquals(1, countStats.getCount());

    BoundingBoxDataStatistics<?> bboxStats =
        (BoundingBoxDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), BoundingBoxDataStatistics.STATS_ID, "aaa");
    assertTrue(
        (bboxStats.getMinX() == 25)
            && (bboxStats.getMaxX() == 26)
            && (bboxStats.getMinY() == 32)
            && (bboxStats.getMaxY() == 32));

    bboxStats =
        (BoundingBoxDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), BoundingBoxDataStatistics.STATS_ID, "bbb");
    assertTrue(
        (bboxStats.getMinX() == 27)
            && (bboxStats.getMaxX() == 27)
            && (bboxStats.getMinY() == 32)
            && (bboxStats.getMaxY() == 32));

    bboxStats =
        (BoundingBoxDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), BoundingBoxDataStatistics.STATS_ID, "aaa", "bbb");
    assertTrue(
        (bboxStats.getMinX() == 25)
            && (bboxStats.getMaxX() == 27)
            && (bboxStats.getMinY() == 32)
            && (bboxStats.getMaxY() == 32));

    final AtomicBoolean found = new AtomicBoolean(false);
    mockDataStore.delete(
        new QueryOptions(
            adapter,
            index,
            -1,
            new ScanCallback<TestGeometry>() {

              @Override
              public void entryScanned(
                  final DataStoreEntryInfo entryInfo, final TestGeometry entry) {
                found.getAndSet(true);
              }
            },
            new String[] {"aaa"}),
        new DataIdQuery(
            adapter.getAdapterId(),
            new ByteArrayId("test_pt_2".getBytes(StringUtils.GEOWAVE_CHAR_SET))));
    assertFalse(found.get());

    try (CloseableIterator<?> it1 =
        mockDataStore.query(
            new QueryOptions(adapter, index, -1, null, new String[] {"aaa", "bbb"}), query)) {
      int count = 0;
      while (it1.hasNext()) {
        it1.next();
        count++;
      }
      assertEquals(3, count);
    }

    mockDataStore.delete(
        new QueryOptions(adapter, index, -1, null, new String[] {"aaa"}),
        new DataIdQuery(
            adapter.getAdapterId(),
            new ByteArrayId("test_pt".getBytes(StringUtils.GEOWAVE_CHAR_SET))));

    try (CloseableIterator<?> it1 =
        mockDataStore.query(
            new QueryOptions(adapter, index, -1, null, new String[] {"aaa", "bbb"}), query)) {
      int count = 0;
      while (it1.hasNext()) {
        it1.next();
        count++;
      }
      assertEquals(2, count);
    }

    countStats =
        (CountDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), CountDataStatistics.STATS_ID, "aaa");
    assertEquals(1, countStats.getCount());

    countStats =
        (CountDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), CountDataStatistics.STATS_ID, "bbb");
    assertEquals(1, countStats.getCount());

    bboxStats =
        (BoundingBoxDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), BoundingBoxDataStatistics.STATS_ID, "aaa");
    assertTrue(
        (bboxStats.getMinX() == 25)
            && (bboxStats.getMaxX() == 26)
            && (bboxStats.getMinY() == 32)
            && (bboxStats.getMaxY() == 32));

    bboxStats =
        (BoundingBoxDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), BoundingBoxDataStatistics.STATS_ID, "bbb");
    assertTrue(
        (bboxStats.getMinX() == 27)
            && (bboxStats.getMaxX() == 27)
            && (bboxStats.getMinY() == 32)
            && (bboxStats.getMaxY() == 32));

    bboxStats =
        (BoundingBoxDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), BoundingBoxDataStatistics.STATS_ID, "aaa", "bbb");
    assertTrue(
        (bboxStats.getMinX() == 25)
            && (bboxStats.getMaxX() == 27)
            && (bboxStats.getMinY() == 32)
            && (bboxStats.getMaxY() == 32));

    found.set(false);

    assertTrue(
        mockDataStore.delete(
            new QueryOptions(
                adapter,
                index,
                -1,
                new ScanCallback<TestGeometry>() {

                  @Override
                  public void entryScanned(
                      final DataStoreEntryInfo entryInfo, final TestGeometry entry) {
                    found.getAndSet(true);
                  }
                },
                new String[] {"aaa", "bbb"}),
            new EverythingQuery()));

    try (CloseableIterator<?> it1 =
        mockDataStore.query(
            new QueryOptions(adapter, index, -1, null, new String[] {"aaa", "bbb"}), query)) {
      int count = 0;
      while (it1.hasNext()) {
        it1.next();
        count++;
      }
      assertEquals(0, count);
    }

    countStats =
        (CountDataStatistics<?>)
            statsStore.getDataStatistics(adapter.getAdapterId(), CountDataStatistics.STATS_ID);
    assertNull(countStats);

    try (IndexWriter indexWriter = mockDataStore.createIndexWriter(index, visWriterBBB)) {
      rowId0 =
          indexWriter
              .write(
                  adapter,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt_2"))
              .get(0);
    }

    countStats =
        (CountDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), CountDataStatistics.STATS_ID, "bbb");
    assertTrue(countStats != null);

    statsStore.deleteObjects(adapter.getAdapterId(), "bbb");

    countStats =
        (CountDataStatistics<?>)
            statsStore.getDataStatistics(
                adapter.getAdapterId(), CountDataStatistics.STATS_ID, "bbb");
    assertNull(countStats);

    final RowRangeDataStatistics<?> rowStats =
        (RowRangeDataStatistics<?>)
            statsStore.getDataStatistics(null, RowRangeDataStatistics.getId(index.getId()), "bbb");

    assertTrue(rowStats != null);
  }
  @Test
  public void testDeleteAll() throws IOException {
    final PrimaryIndex index = new SpatialDimensionalityTypeProvider().createPrimaryIndex();
    final WritableDataAdapter<TestGeometry> adapter0 = new TestGeometryAdapter();
    final WritableDataAdapter<TestGeometry> adapter1 = new AnotherAdapter();

    accumuloOptions.setUseAltIndex(true);

    try (IndexWriter indexWriter =
        mockDataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      final ByteArrayId rowId0 =
          indexWriter
              .write(
                  adapter0,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt_0"))
              .get(0);

      final ByteArrayId rowId1 =
          indexWriter
              .write(
                  adapter1,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt_1"))
              .get(0);
    }

    CloseableIterator it =
        mockDataStore.query(new QueryOptions(adapter0, index), new EverythingQuery());
    int count = 0;
    while (it.hasNext()) {
      it.next();
      count++;
    }
    assertEquals(1, count);

    it = mockDataStore.query(new QueryOptions(adapter1, index), new EverythingQuery());
    count = 0;
    while (it.hasNext()) {
      it.next();
      count++;
    }

    assertEquals(1, count);

    it = mockDataStore.query(new QueryOptions(index), new EverythingQuery());
    count = 0;
    while (it.hasNext()) {
      it.next();
      count++;
    }
    assertEquals(2, count);

    // delete entry by data id & adapter id

    assertTrue(mockDataStore.delete(new QueryOptions(adapter0, index), new EverythingQuery()));

    it = mockDataStore.query(new QueryOptions(index), new EverythingQuery());
    count = 0;
    while (it.hasNext()) {
      it.next();
      count++;
    }
    assertEquals(1, count);

    it = mockDataStore.query(new QueryOptions(adapter0, index), new EverythingQuery());
    count = 0;
    while (it.hasNext()) {
      it.next();
      count++;
    }
    assertEquals(0, count);

    try (IndexWriter indexWriter =
        mockDataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      final ByteArrayId rowId0 =
          indexWriter
              .write(
                  adapter0,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt_2"))
              .get(0);
    }
    it = mockDataStore.query(new QueryOptions(index), new EverythingQuery());
    count = 0;
    while (it.hasNext()) {
      it.next();
      count++;
    }
    assertEquals(2, count);

    assertTrue(mockDataStore.delete(new QueryOptions(), new EverythingQuery()));

    it = mockDataStore.query(new QueryOptions(index), new EverythingQuery());
    count = 0;
    while (it.hasNext()) {
      it.next();
      count++;
    }
    assertEquals(0, count);
  }
  @Test
  public void testAdapterOptions() throws IOException {

    final PrimaryIndex index = new SpatialDimensionalityTypeProvider().createPrimaryIndex();
    final WritableDataAdapter<TestGeometry> adapter = new TestGeometryAdapter();
    accumuloOptions.setPersistAdapter(false);

    try (IndexWriter indexWriter =
        mockDataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      final ByteArrayId rowId1 =
          indexWriter
              .write(
                  adapter,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt_1"))
              .get(0);

      assertFalse(
          mockDataStore
              .query(new QueryOptions(), new RowIdQuery(Collections.singletonList(rowId1)))
              .hasNext());
    }

    try (IndexWriter indexWriter =
        mockDataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      final ByteArrayId rowId1 =
          indexWriter
              .write(
                  adapter,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt_1"))
              .get(0);

      assertFalse(
          mockDataStore
              .query(new QueryOptions(), new RowIdQuery(Collections.singletonList(rowId1)))
              .hasNext());

      try (final CloseableIterator<TestGeometry> geomItr =
          mockDataStore.query(new QueryOptions(adapter, index), new EverythingQuery())) {

        final TestGeometry geom1 = geomItr.next();

        // specifying the adapter, this method returns the entry
        assertEquals("test_pt_1", geom1.id);
      }

      // the adapter should not exist in the metadata table
      assertEquals(false, adapterStore.adapterExists(adapter.getAdapterId()));
    }

    accumuloOptions.setPersistAdapter(true);

    try (IndexWriter indexWriter =
        mockDataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      final ByteArrayId rowId2 =
          indexWriter
              .write(
                  adapter,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt_2"))
              .get(0);

      try (final CloseableIterator<?> geomItr =
          mockDataStore.query(
              new QueryOptions(), new RowIdQuery(Collections.singletonList(rowId2)))) {
        assertTrue(geomItr.hasNext());
        final TestGeometry geom2 = (TestGeometry) geomItr.next();

        // specifying the adapter, this method returns the entry
        assertEquals("test_pt_2", geom2.id);
      }

      try (final CloseableIterator<TestGeometry> geomItr =
          mockDataStore.query(new QueryOptions(adapter, index), null)) {

        while (geomItr.hasNext()) {
          final TestGeometry geom2 = geomItr.next();

          // specifying the adapter, this method returns the entry

          assertTrue(Arrays.asList("test_pt_2", "test_pt_1").contains(geom2.id));
        }
      }

      // the adapter should not exist in the metadata table
      assertEquals(true, adapterStore.adapterExists(adapter.getAdapterId()));
    }

    // the adapter should exist in the metadata table
    assertEquals(true, adapterStore.adapterExists(adapter.getAdapterId()));
  }
  @Test
  public void testLocalityGroups() throws IOException {

    final PrimaryIndex index = new SpatialDimensionalityTypeProvider().createPrimaryIndex();
    final WritableDataAdapter<TestGeometry> adapter = new TestGeometryAdapter();

    final String tableName = StringUtils.stringFromBinary(index.getId().getBytes());
    final byte[] adapterId = adapter.getAdapterId().getBytes();

    accumuloOptions.setUseLocalityGroups(false);

    try (IndexWriter indexWriter =
        mockDataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      final ByteArrayId rowId1 =
          indexWriter
              .write(
                  adapter,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt_1"))
              .get(0);

      try {
        // as we are not using locality groups, we expect that this will
        // return false
        assertEquals(false, accumuloOperations.localityGroupExists(tableName, adapterId));
      } catch (final AccumuloException | TableNotFoundException e) {
        LOGGER.error("Locality Group check failed", e);
      }

      final TestGeometry geom1 =
          (TestGeometry)
              mockDataStore
                  .query(new QueryOptions(), new RowIdQuery(Collections.singletonList(rowId1)))
                  .next();

      // of course, the point is actually stored in this case
      assertEquals("test_pt_1", geom1.id);
    }

    accumuloOptions.setUseLocalityGroups(true);

    try (IndexWriter indexWriter =
        mockDataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      final ByteArrayId rowId2 =
          indexWriter
              .write(
                  adapter,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt_2"))
              .get(0);

      try {
        // now that locality groups are turned on, we expect this to
        // return
        // true
        assertEquals(true, accumuloOperations.localityGroupExists(tableName, adapterId));
      } catch (final AccumuloException | TableNotFoundException e) {
        LOGGER.error("Locality Group check failed", e);
      }
      final TestGeometry geom2 =
          (TestGeometry)
              mockDataStore
                  .query(new QueryOptions(), new RowIdQuery(Collections.singletonList(rowId2)))
                  .next();

      // of course, the point is actually stored in this case
      assertEquals("test_pt_2", geom2.id);
    }
  }
  @Test
  public void testIndexOptions() throws IOException {

    final PrimaryIndex index = new SpatialDimensionalityTypeProvider().createPrimaryIndex();
    final WritableDataAdapter<TestGeometry> adapter = new TestGeometryAdapter();

    accumuloOptions.setCreateTable(false);
    accumuloOptions.setPersistIndex(false);

    try (IndexWriter indexWriter =
        mockDataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      final List<ByteArrayId> rowIds =
          indexWriter.write(
              adapter, new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt"));

      // as the table didn't already exist, the flag indicates not to
      // create
      // it, so no rows will be returned
      assertEquals(0, rowIds.size());

      assertEquals(false, indexStore.indexExists(index.getId()));
    }

    accumuloOptions.setCreateTable(true);

    try (IndexWriter indexWriter =
        mockDataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      final ByteArrayId rowId1 =
          indexWriter
              .write(
                  adapter,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt_1"))
              .get(0);

      assertFalse(
          mockDataStore
              .query(new QueryOptions(), new RowIdQuery(Collections.singletonList(rowId1)))
              .hasNext());

      // as we have chosen not to persist the index, we will not see an
      // index
      // entry in the index store
      assertEquals(false, indexStore.indexExists(index.getId()));

      /** Still can query providing the index */
      final TestGeometry geom1 =
          (TestGeometry)
              mockDataStore
                  .query(
                      new QueryOptions(adapter, index),
                      new RowIdQuery(Collections.singletonList(rowId1)))
                  .next();

      // even though we didn't persist the index, the test point was still
      // stored
      assertEquals("test_pt_1", geom1.id);
    }

    accumuloOptions.setPersistIndex(true);

    try (IndexWriter indexWriter =
        mockDataStore.createIndexWriter(index, DataStoreUtils.DEFAULT_VISIBILITY)) {
      final ByteArrayId rowId2 =
          indexWriter
              .write(
                  adapter,
                  new TestGeometry(factory.createPoint(new Coordinate(25, 32)), "test_pt_2"))
              .get(0);

      final TestGeometry geom2 =
          (TestGeometry)
              mockDataStore
                  .query(new QueryOptions(), new RowIdQuery(Collections.singletonList(rowId2)))
                  .next();

      // as we have chosen to persist the index, we will see the index
      // entry
      // in the index store
      assertEquals(true, indexStore.indexExists(index.getId()));

      // of course, the point is actually stored in this case
      assertEquals("test_pt_2", geom2.id);
    }
  }