示例#1
0
  private static HBaseMRRowRange getRangeMax(
      final Index<?, ?> index,
      final AdapterStore adapterStore,
      final DataStatisticsStore statsStore,
      final String[] authorizations) {

    final RowRangeDataStatistics<?> stats =
        (RowRangeDataStatistics<?>)
            statsStore.getDataStatistics(
                index.getId(), RowRangeDataStatistics.getId(index.getId()), authorizations);
    if (stats == null) {
      LOGGER.warn(
          "Could not determine range of data from 'RowRangeDataStatistics'.  Range will not be clipped. This may result in some splits being empty.");
      return new HBaseMRRowRange();
    }

    final int cardinality = Math.max(stats.getMin().length, stats.getMax().length);
    return new HBaseMRRowRange(
        new ByteArrayId(
            getKeyFromBigInteger(new BigInteger(stats.getMin()).subtract(ONE), cardinality)),
        new ByteArrayId(
            getKeyFromBigInteger(new BigInteger(stats.getMax()).add(ONE), cardinality)));
  }
  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);
  }