use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.
the class IndexRangeFilterIteratorTest method testIterator_simple_between.
@Test
public void testIterator_simple_between() {
HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
IMap<Integer, Value> map = instance.getMap(MAP_NAME);
map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(SORTED).addAttribute("value1"));
InternalIndex index = getIndex(instance);
ExpressionEvalContext evalContext = createExpressionEvalContext();
// Check missing value.
map.put(0, new Value(0));
map.put(1, new Value(10));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext));
// Check left bound
map.put(2, new Value(1));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
map.put(3, new Value(1));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
map.remove(2);
map.remove(3);
// Check right bound
map.put(2, new Value(5));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
map.put(3, new Value(5));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
map.remove(2);
map.remove(3);
// Check middle
map.put(2, new Value(3));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
map.put(3, new Value(3));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
map.remove(2);
map.remove(3);
// Check combined
map.put(2, new Value(1));
map.put(3, new Value(1));
map.put(4, new Value(3));
map.put(5, new Value(3));
map.put(6, new Value(5));
map.put(7, new Value(5));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext), 4, 5);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3, 4, 5);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 4, 5, 6, 7);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3, 4, 5, 6, 7);
// Check null value.
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(null, false), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(null, false), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(null, false), false, intValue(null, false), false).getEntries(index, descendingDirection, evalContext));
}
use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.
the class SqlIndexAbstractTest method getIndexConfig.
private IndexConfig getIndexConfig() {
IndexConfig config = new IndexConfig().setName(INDEX_NAME).setType(indexType);
config.addAttribute("field1");
if (composite) {
config.addAttribute("field2");
}
return config;
}
use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.
the class SqlIndexConverterMismatchTest method before.
@Before
public void before() {
IndexConfig indexConfig = new IndexConfig().setName("index").setType(IndexType.HASH).addAttribute("field1");
if (composite) {
indexConfig.addAttribute("field2");
}
Config config = getConfig();
config.addMapConfig(new MapConfig().setName(MAP_NAME).setBackupCount(0).addIndexConfig(indexConfig));
member1 = factory.newHazelcastInstance(config);
member2 = factory.newHazelcastInstance(config);
map = member1.getMap(MAP_NAME);
}
use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.
the class MapSortedIndexScanIntegrationTest method test_sorted.
@Test
public void test_sorted() {
List<Row> expected = new ArrayList<>();
for (int i = 0; i <= ITEM_COUNT; i++) {
map.put(i, i);
expected.add(new Row(ITEM_COUNT - i, ITEM_COUNT - i));
}
IndexConfig indexConfig = new IndexConfig(IndexType.SORTED, "this").setName(randomName());
map.addIndex(indexConfig);
// we'd try to break order correctness couple of time.
for (int i = 0; i < 5; i++) {
assertRowsOrdered("SELECT * FROM " + MAP_NAME + " ORDER BY this DESC", expected);
}
}
use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.
the class MapIndexScanPTest method test_whenBothFiltersAndSpecificProjectionExists_sorted.
@Test
public void test_whenBothFiltersAndSpecificProjectionExists_sorted() {
List<JetSqlRow> expected = new ArrayList<>();
for (int i = count; i > 0; i--) {
map.put(i, new Person("value-" + i, i));
if (i > count / 2) {
if (i % 2 == 1) {
expected.add(jetRow((count - i + 1), "value-" + (count - i + 1), (count - i + 1)));
}
}
}
IndexConfig indexConfig = new IndexConfig(IndexType.SORTED, "age").setName(randomName());
map.addIndex(indexConfig);
Expression<Boolean> remainingFilter = new FunctionalPredicateExpression(row -> {
int value = row.get(0);
return value % 2 == 0;
});
IndexFilter filter = new IndexRangeFilter(intValue(0), true, intValue(count / 2), true);
MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, remainingFilter, 0, false);
TestSupport.verifyProcessor(adaptSupplier(MapIndexScanP.readMapIndexSupplier(metadata))).hazelcastInstance(instance()).jobConfig(new JobConfig().setArgument(SQL_ARGUMENTS_KEY_NAME, emptyList())).outputChecker(LENIENT_SAME_ITEMS_IN_ORDER).disableSnapshots().disableProgressAssertion().expectOutput(expected);
}
Aggregations