Пример #1
0
def test_delete(test_ds):
    # given
    index = SpatialIndexBuilder().set_name("idx1").create_index()
    index2 = SpatialIndexBuilder().set_name("idx2").create_index()
    adapter = POINT_TYPE_ADAPTER
    test_ds.add_type(adapter, index)
    test_ds.add_type(adapter, index2)
    write_test_data(test_ds, index, index2)

    # when
    qbldr = VectorQueryBuilder()
    constraints_factory = qbldr.constraints_factory()
    # filter encompasses 10 features (1, 1) - (10, 10)
    constraints = constraints_factory.cql_constraints(
        "BBOX(the_geom, 0.5, 0.5, 10.5, 10.5)")
    qbldr.constraints(constraints)
    test_ds.delete(qbldr.build())

    query = VectorQueryBuilder().build()
    res = results_as_list(test_ds.query(query))

    # then
    assert len(test_ds.get_indices()) == 2
    assert len(test_ds.get_types()) == 1
    assert len(res) == (len(TEST_DATA) - 10)
Пример #2
0
def test_stat_recalc_statistics(test_ds):
    # given
    adapter = POINT_TYPE_ADAPTER
    index = SpatialIndexBuilder().set_name('idx').create_index()
    test_ds.add_type(adapter, index)
    write_test_data(test_ds, index)

    duplicate_entry_count_stat = DuplicateEntryCountStatistic('idx')
    duplicate_entry_count_stat.set_tag('test')
    count_stat = CountStatistic(POINT_TYPE_NAME)
    count_stat.set_tag('test')
    numeric_range_statistic = NumericRangeStatistic(POINT_TYPE_NAME, POINT_NUMBER_FIELD)
    numeric_range_statistic.set_tag('test')
    test_ds.add_empty_statistic(duplicate_entry_count_stat, count_stat, numeric_range_statistic)
    assert test_ds.get_statistic_value(duplicate_entry_count_stat) == 0
    assert test_ds.get_statistic_value(count_stat) == 0
    numeric_range = test_ds.get_statistic_value(numeric_range_statistic)
    assert numeric_range.get_minimum() == 0
    assert numeric_range.get_maximum() == 0

    # when
    test_ds.recalc_statistic(duplicate_entry_count_stat, count_stat, numeric_range_statistic)

    # then
    assert test_ds.get_statistic_value(duplicate_entry_count_stat) == 0
    assert test_ds.get_statistic_value(count_stat) == 360
    numeric_range = test_ds.get_statistic_value(numeric_range_statistic)
    assert numeric_range.get_minimum() == -180
    assert numeric_range.get_maximum() == 179
Пример #3
0
def test_copy(test_ds):
    # given
    options = RocksDBOptions()
    options.set_geowave_namespace("geowave.tests")
    options.set_directory(os.path.join(TEST_DIR, "datastore2"))
    ds2 = DataStoreFactory.create_data_store(options)

    adapter = POINT_TYPE_ADAPTER
    index = SpatialIndexBuilder().create_index()
    test_ds.add_type(adapter, index)

    write_test_data(test_ds, index)

    # when
    test_ds.copy_to(ds2)

    indices = ds2.get_indices()
    types = ds2.get_types()
    query = VectorQueryBuilder().build()
    res = results_as_list(ds2.query(query))

    # then
    assert len(test_ds.get_indices()) == 1
    assert len(indices) == 1
    assert indices[0].get_name() == index.get_name()
    assert indices[0].get_index_strategy() == index.get_index_strategy()
    assert indices[0].get_index_model() == index.get_index_model()
    assert len(types) == 1
    assert types[0].get_type_name() == adapter.get_type_name()
    assert len(res) == len(TEST_DATA)

    ds2.delete_all()
Пример #4
0
def test_remove_index(test_ds):
    # given
    index = SpatialIndexBuilder().set_name("idx1").create_index()
    index2 = SpatialIndexBuilder().set_name("idx2").create_index()

    adapter = POINT_TYPE_ADAPTER
    test_ds.add_type(adapter, index)
    test_ds.add_type(adapter, index2)

    # when
    test_ds.remove_index(adapter.get_type_name(), index.get_name())
    indices = test_ds.get_indices()

    # then
    assert len(indices) == 1
    assert indices[0].get_name() == index2.get_name()
    assert indices[0].get_index_strategy() == index2.get_index_strategy()
    assert indices[0].get_index_model() == index2.get_index_model()
Пример #5
0
def test_delete_all(test_ds):
    # given
    index = SpatialIndexBuilder().set_name("idx1").create_index()
    index2 = SpatialIndexBuilder().set_name("idx2").create_index()
    adapter = POINT_TYPE_ADAPTER
    test_ds.add_type(adapter, index)
    test_ds.add_type(adapter, index2)
    write_test_data(test_ds, index, index2)

    # when
    test_ds.delete_all()

    query = VectorQueryBuilder().build()
    res = results_as_list(test_ds.query(query))

    # then
    assert len(test_ds.get_indices()) == 0
    assert len(test_ds.get_types()) == 0
    assert len(res) == 0
Пример #6
0
def test_remove_index_non_exist(test_ds):
    # given
    index = SpatialIndexBuilder().create_index()
    adapter = POINT_TYPE_ADAPTER
    test_ds.add_type(adapter, index)

    # when
    test_ds.remove_index("Corgi")

    # then
    assert len(test_ds.get_indices()) == 1
Пример #7
0
def test_create_writer(test_ds):
    # given
    adapter = POINT_TYPE_ADAPTER
    index = SpatialIndexBuilder().create_index()
    test_ds.add_type(adapter, index)

    # when
    writer = test_ds.create_writer(adapter.get_type_name())

    # then
    assert writer is not None
Пример #8
0
def test_remove_index_last(test_ds):
    with pytest.raises(Exception) as exec:
        # given
        index = SpatialIndexBuilder().create_index()
        adapter = POINT_TYPE_ADAPTER
        test_ds.add_type(adapter, index)

        # when
        test_ds.remove_index(index.get_name())

    # then
    assert 'Adapters require at least one index' in str(exec.value)
Пример #9
0
def setup_query_builder(test_ds):
    # given
    index = SpatialIndexBuilder().set_name("idx1").create_index()
    adapter = POINT_TYPE_ADAPTER
    test_ds.add_type(adapter, index)
    write_test_data(test_ds, index)

    qbldr = VectorAggregationQueryBuilder()
    constraints_factory = qbldr.constraints_factory()
    # filter encompasses 10 features (1, 1) - (10, 10)
    constraints = constraints_factory.cql_constraints("BBOX(the_geom, 0.5, 0.5, 10.5, 10.5)")
    qbldr.constraints(constraints)
    return qbldr
Пример #10
0
def test_add_get_statistics(test_ds):
    # given
    adapter = POINT_TYPE_ADAPTER
    index = SpatialIndexBuilder().set_name('idx').create_index()
    test_ds.add_type(adapter, index)
    write_test_data(test_ds, index)

    duplicate_entry_count_stat = DuplicateEntryCountStatistic('idx')
    duplicate_entry_count_stat.set_tag('test')
    count_stat = CountStatistic(POINT_TYPE_NAME)
    count_stat.set_tag('test')
    numeric_range_statistic = NumericRangeStatistic(POINT_TYPE_NAME,
                                                    POINT_NUMBER_FIELD)
    numeric_range_statistic.set_tag('test')

    # when
    test_ds.add_statistic(duplicate_entry_count_stat, count_stat,
                          numeric_range_statistic)

    # then
    duplicate_entry_count_stat = test_ds.get_index_statistic(
        DuplicateEntryCountStatistic.STATS_TYPE, 'idx', 'test')
    assert isinstance(duplicate_entry_count_stat, DuplicateEntryCountStatistic)
    assert duplicate_entry_count_stat.get_tag() == 'test'
    assert duplicate_entry_count_stat.get_index_name() == 'idx'
    count_stat = test_ds.get_data_type_statistic(CountStatistic.STATS_TYPE,
                                                 POINT_TYPE_NAME, 'test')
    assert isinstance(count_stat, CountStatistic)
    assert count_stat.get_tag() == 'test'
    assert count_stat.get_type_name() == POINT_TYPE_NAME
    numeric_range_statistic = test_ds.get_field_statistic(
        NumericRangeStatistic.STATS_TYPE, POINT_TYPE_NAME, POINT_NUMBER_FIELD,
        'test')
    assert isinstance(numeric_range_statistic, NumericRangeStatistic)
    assert numeric_range_statistic.get_tag() == 'test'
    assert numeric_range_statistic.get_type_name() == POINT_TYPE_NAME
    assert numeric_range_statistic.get_field_name() == POINT_NUMBER_FIELD

    index_stats = test_ds.get_index_statistics('idx')
    assert any(stat.get_tag() == 'test'
               and isinstance(stat, DuplicateEntryCountStatistic)
               for stat in index_stats)
    data_type_stats = test_ds.get_data_type_statistics(POINT_TYPE_NAME)
    assert any(stat.get_tag() == 'test' and isinstance(stat, CountStatistic)
               for stat in data_type_stats)
    field_stats = test_ds.get_field_statistics(POINT_TYPE_NAME,
                                               POINT_NUMBER_FIELD)
    assert any(
        stat.get_tag() == 'test' and isinstance(stat, NumericRangeStatistic)
        for stat in field_stats)
Пример #11
0
def test_add_existing_type(test_ds):
    # given
    index = SpatialIndexBuilder().create_index()
    adapter = POINT_TYPE_ADAPTER
    test_ds.add_type(adapter, index)

    # when
    test_ds.add_type(adapter, index)
    indices = test_ds.get_indices(adapter.get_type_name())

    # then
    assert len(indices) == 1
    assert indices[0].get_name() == index.get_name()
    assert indices[0].get_index_strategy() == index.get_index_strategy()
    assert indices[0].get_index_model() == index.get_index_model()
Пример #12
0
def test_write(test_ds):
    # given
    adapter = POINT_TYPE_ADAPTER
    index = SpatialIndexBuilder().create_index()
    test_ds.add_type(adapter, index)

    # when
    write_test_data(test_ds, index)

    query = VectorQueryBuilder().build()

    res = results_as_list(test_ds.query(query))

    # then
    assert len(res) == len(TEST_DATA)
Пример #13
0
def test_remove_type(test_ds):
    # given
    index = SpatialIndexBuilder().create_index()
    adapter = POINT_TYPE_ADAPTER
    test_ds.add_type(adapter, index)
    write_test_data(test_ds, index)

    # when
    test_ds.remove_type(adapter.get_type_name())
    query = VectorQueryBuilder().build()
    res = results_as_list(test_ds.query(query))

    # then
    assert len(test_ds.get_indices(adapter.get_type_name())) == 0
    assert len(test_ds.get_indices()) == 1
    assert len(res) == 0
Пример #14
0
def test_cql_query(test_ds):
    # given
    index = SpatialIndexBuilder().set_name("idx1").create_index()
    adapter = POINT_TYPE_ADAPTER
    test_ds.add_type(adapter, index)
    write_test_data(test_ds, index)

    # when
    qbldr = VectorQueryBuilder()
    constraints_factory = qbldr.constraints_factory()
    # filter encompasses 10 features (1, 1) - (10, 10)
    constraints = constraints_factory.cql_constraints(
        "BBOX(the_geom, 0.5, 0.5, 10.5, 10.5)")
    qbldr.constraints(constraints)
    res = results_as_list(test_ds.query(qbldr.build()))

    # then
    assert len(res) == 10
Пример #15
0
def test_query_filter(test_ds):
    # given
    index = SpatialIndexBuilder().set_name("idx1").create_index()
    adapter = POINT_TYPE_ADAPTER
    test_ds.add_type(adapter, index)
    write_test_data(test_ds, index)

    # when
    qbldr = VectorQueryBuilder()
    filter_factory = FilterFactory()
    # filter encompasses 10 features (1, 1) - (10, 10)
    bbox_filter = filter_factory.bbox(filter_factory.property("the_geom"), 0.5,
                                      0.5, 10.5, 10.5, "EPSG:4326")
    constraints = qbldr.constraints_factory().filter_constraints(bbox_filter)
    qbldr.constraints(constraints)
    res = results_as_list(test_ds.query(qbldr.build()))

    # then
    assert len(res) == 10
Пример #16
0
def test_query_temporal(test_ds):
    # given
    index = SpatialIndexBuilder().set_name("idx1").create_index()
    adapter = POINT_TYPE_ADAPTER
    test_ds.add_type(adapter, index)
    write_test_data(test_ds, index)

    # when
    qbldr = VectorQueryBuilder()
    stcb = qbldr.constraints_factory().spatial_temporal_constraints()
    # time range encompasses 10 features (1, 1) - (10, 10)
    stcb.add_time_range(datetime.fromtimestamp(1), datetime.fromtimestamp(11))
    qbldr.constraints(stcb.build())
    res = results_as_list(test_ds.query(qbldr.build()))

    for feature in res:
        print(feature.get_id())
        print(feature.get_default_geometry())
    # then
    assert len(res) == 10
Пример #17
0
def test_query_spatial(test_ds):
    # given
    index = SpatialIndexBuilder().set_name("idx1").create_index()
    adapter = POINT_TYPE_ADAPTER
    test_ds.add_type(adapter, index)
    write_test_data(test_ds, index)

    # when
    qbldr = VectorQueryBuilder()
    stcb = qbldr.constraints_factory().spatial_temporal_constraints()
    # polygon encompasses 10 features (1, 1) - (10, 10)
    stcb.spatial_constraints(
        Polygon([[0.5, 0.5], [0.5, 10.5], [10.5, 10.5], [10.5, 0.5],
                 [0.5, 0.5]]))
    stcb.spatial_constraints_compare_operation("CONTAINS")
    qbldr.constraints(stcb.build())
    res = results_as_list(test_ds.query(qbldr.build()))

    # then
    assert len(res) == 10
Пример #18
0
def test_copy_by_query(test_ds):
    # given
    options = RocksDBOptions()
    options.set_geowave_namespace("geowave.tests")
    options.set_directory(os.path.join(TEST_DIR, "datastore2"))
    ds2 = DataStoreFactory.create_data_store(options)

    adapter = POINT_TYPE_ADAPTER
    index = SpatialIndexBuilder().create_index()
    test_ds.add_type(adapter, index)

    write_test_data(test_ds, index)

    # when
    qbldr = VectorQueryBuilder()
    constraints_factory = qbldr.constraints_factory()
    # filter encompasses 10 features (1, 1) - (10, 10)
    constraints = constraints_factory.cql_constraints(
        "BBOX(the_geom, 0.5, 0.5, 10.5, 10.5)")
    qbldr.all_indices().constraints(constraints)
    test_ds.copy_to(ds2, qbldr.build())

    indices = ds2.get_indices()
    types = ds2.get_types()
    query = VectorQueryBuilder().build()
    res = results_as_list(ds2.query(query))

    # then
    assert len(test_ds.get_indices()) == 1
    assert len(indices) == 1
    assert indices[0].get_name() == index.get_name()
    assert indices[0].get_index_strategy() == index.get_index_strategy()
    assert indices[0].get_index_model() == index.get_index_model()
    assert len(types) == 1
    assert types[0].get_type_name() == adapter.get_type_name()
    assert len(res) == 10

    ds2.delete_all()