use of com.hazelcast.config.IndexType in project hazelcast by hazelcast.
the class SqlCreateIndex method getIndexType.
/**
* @return the index type, if specified, the default index type if not.
*/
@Nonnull
private IndexType getIndexType() {
if (type == null) {
return IndexConfig.DEFAULT_TYPE;
}
String indexType = type.toString().toLowerCase();
IndexType type;
switch(indexType) {
case "sorted":
type = IndexType.SORTED;
break;
case "hash":
type = IndexType.HASH;
break;
case "bitmap":
type = IndexType.BITMAP;
break;
default:
throw QueryException.error("Can't create index: wrong index type. Only HASH, SORTED and BITMAP types are supported.");
}
return type;
}
use of com.hazelcast.config.IndexType in project hazelcast by hazelcast.
the class SqlCreateIndex method validate.
@Override
public void validate(SqlValidator validator, SqlValidatorScope scope) {
if (getReplace()) {
throw validator.newValidationError(this, RESOURCE.notSupported("OR REPLACE", "CREATE INDEX"));
}
Set<String> columnNames = new HashSet<>();
for (SqlNode column : columns.getList()) {
String name = ((SqlIdentifier) requireNonNull(column)).getSimple();
if (!columnNames.add(name)) {
throw validator.newValidationError(column, RESOURCE.duplicateIndexAttribute(name));
}
}
IndexType indexType = getIndexType();
if (!indexType.equals(IndexType.BITMAP) && !options.getList().isEmpty()) {
throw validator.newValidationError(options, RESOURCE.unsupportedIndexType(indexType.name(), options().keySet().iterator().next()));
}
Set<String> optionNames = new HashSet<>();
for (SqlNode option : options.getList()) {
String name = ((SqlOption) option).keyString();
if (!optionNames.add(name)) {
throw validator.newValidationError(option, RESOURCE.duplicateOption(name));
}
}
}
use of com.hazelcast.config.IndexType in project hazelcast by hazelcast.
the class IndexTest method testIt.
private void testIt(boolean ordered) {
IndexType type = ordered ? IndexType.SORTED : IndexType.HASH;
IndexConfig config = IndexUtils.createTestIndexConfig(type, QueryConstants.THIS_ATTRIBUTE_NAME.value());
IndexImpl index = new IndexImpl(config, ss, newExtractor(), copyBehavior, PerIndexStats.EMPTY, MemberPartitionStateImpl.DEFAULT_PARTITION_COUNT);
assertEquals(0, index.getRecords(0L).size());
assertEquals(0, index.getRecords(0L, true, 1000L, true).size());
CachedQueryEntry<?, ?> record5 = newRecord(5L, 55L);
index.putEntry(record5, null, record5, Index.OperationSource.USER);
assertEquals(Collections.<QueryableEntry>singleton(record5), index.getRecords(55L));
CachedQueryEntry<?, ?> record6 = newRecord(6L, 66L);
index.putEntry(record6, null, record6, Index.OperationSource.USER);
assertEquals(Collections.<QueryableEntry>singleton(record6), index.getRecords(66L));
CachedQueryEntry<?, ?> newRecord5 = newRecord(5L, 555L);
index.putEntry(newRecord5, record5, newRecord5, Index.OperationSource.USER);
record5 = newRecord5;
assertEquals(0, index.getRecords(55L).size());
assertEquals(Collections.<QueryableEntry>singleton(record5), index.getRecords(555L));
assertEquals(1, index.getRecords(555L).size());
assertEquals(2, index.getRecords(55L, true, 555L, true).size());
assertEquals(2, index.getRecords(66L, true, 555L, true).size());
assertEquals(1, index.getRecords(555L, true, 555L, true).size());
CachedQueryEntry<?, ?> record50 = newRecord(50L, 555L);
index.putEntry(record50, null, record50, Index.OperationSource.USER);
assertEquals(new HashSet<QueryableEntry>(asList(record5, record50)), index.getRecords(555L));
Map<Data, QueryableEntry> records = getRecordMap(index, 555L);
assertNotNull(records);
assertEquals(2, records.size());
assertEquals(record5, records.get(record5.getKeyData()));
assertEquals(record50, records.get(record50.getKeyData()));
assertEquals(2, index.getRecords(555L).size());
assertEquals(3, index.getRecords(55L, true, 555L, true).size());
assertEquals(3, index.getRecords(66L, true, 555L, true).size());
assertEquals(2, index.getRecords(555L, true, 555L, true).size());
assertEquals(0, index.getRecords(Comparison.LESS, 66L).size());
assertEquals(1, index.getRecords(Comparison.LESS_OR_EQUAL, 66L).size());
assertEquals(1, index.getRecords(Comparison.LESS_OR_EQUAL, 67L).size());
assertEquals(2, index.getRecords(Comparison.GREATER, 66L).size());
assertEquals(3, index.getRecords(Comparison.GREATER_OR_EQUAL, 66L).size());
assertEquals(3, index.getRecords(Comparison.GREATER_OR_EQUAL, 61L).size());
assertEquals(3, index.getRecords(new Comparable[] { 66L, 555L, 34234L }).size());
assertEquals(2, index.getRecords(new Comparable[] { 555L, 34234L }).size());
index.removeEntry(record5, Index.OperationSource.USER);
assertEquals(Collections.<QueryableEntry>singleton(record50), index.getRecords(555L));
records = getRecordMap(index, 555L);
assertNotNull(records);
assertNull(records.get(5L));
assertEquals(record50, records.get(toData(50L)));
assertEquals(1, index.getRecords(555L).size());
assertEquals(2, index.getRecords(55L, true, 555L, true).size());
assertEquals(2, index.getRecords(66L, true, 555L, true).size());
assertEquals(1, index.getRecords(555L, true, 555L, true).size());
assertEquals(0, index.getRecords(Comparison.LESS, 66L).size());
assertEquals(1, index.getRecords(Comparison.LESS_OR_EQUAL, 66L).size());
assertEquals(1, index.getRecords(Comparison.LESS_OR_EQUAL, 67L).size());
assertEquals(1, index.getRecords(Comparison.GREATER, 66L).size());
assertEquals(2, index.getRecords(Comparison.GREATER_OR_EQUAL, 66L).size());
assertEquals(2, index.getRecords(Comparison.GREATER_OR_EQUAL, 61L).size());
index.removeEntry(record50, Index.OperationSource.USER);
assertEquals(0, index.getRecords(555L).size());
records = getRecordMap(index, 555L);
assertNull(records);
assertEquals(0, index.getRecords(555L).size());
assertEquals(1, index.getRecords(55L, true, 555L, true).size());
assertEquals(1, index.getRecords(66L, true, 555L, true).size());
assertEquals(0, index.getRecords(555L, true, 555L, true).size());
index.removeEntry(record6, Index.OperationSource.USER);
assertEquals(0, index.getRecords(66L).size());
assertNull(getRecordMap(index, 66L));
assertEquals(0, index.getRecords(555L).size());
assertEquals(0, index.getRecords(55L, true, 555L, true).size());
assertEquals(0, index.getRecords(66L, true, 555L, true).size());
assertEquals(0, index.getRecords(555L, true, 555L, true).size());
}
use of com.hazelcast.config.IndexType in project hazelcast by hazelcast.
the class MapTableIndexTest method testEquals.
@Test
public void testEquals() {
String name1 = "index1";
String name2 = "index2";
IndexType type1 = SORTED;
IndexType type2 = HASH;
int components1 = 1;
int components2 = 2;
List<Integer> ordinals1 = singletonList(1);
List<Integer> ordinals2 = singletonList(2);
List<QueryDataType> types1 = singletonList(INT);
List<QueryDataType> types2 = singletonList(BIGINT);
MapTableIndex index = new MapTableIndex(name1, type1, components1, ordinals1, types1);
checkEquals(index, new MapTableIndex(name1, type1, components1, ordinals1, types1), true);
checkEquals(index, new MapTableIndex(name2, type1, components1, ordinals1, types1), false);
checkEquals(index, new MapTableIndex(name1, type2, components1, ordinals1, types1), false);
checkEquals(index, new MapTableIndex(name1, type1, components2, ordinals1, types1), false);
checkEquals(index, new MapTableIndex(name1, type1, components1, ordinals2, types1), false);
checkEquals(index, new MapTableIndex(name1, type1, components1, ordinals1, types2), false);
}
use of com.hazelcast.config.IndexType in project hazelcast by hazelcast.
the class SqlIndexResolutionTest method checkIndex.
private void checkIndex(IMap<?, ?> map, List<QueryDataType> expectedFieldConverterTypes) {
String mapName = map.getName();
List<PartitionedMapTable> tables = resolver.getTables().stream().filter(t -> t instanceof PartitionedMapTable).map(t -> (PartitionedMapTable) t).filter(t -> t.getMapName().equals(mapName)).collect(Collectors.toList());
assertEquals(1, tables.size());
PartitionedMapTable table = tables.get(0);
assertEquals(1, table.getIndexes().size());
MapTableIndex index = table.getIndexes().get(0);
assertEquals(indexName, index.getName());
assertEquals(indexType, index.getType());
// Components count depends on the index attribute count
assertEquals(composite ? 2 : 1, index.getComponentsCount());
int field1Ordinal = findFieldOrdinal(table, "field1");
int field2Ordinal = findFieldOrdinal(table, "field2");
// Check resolved field converter types. We do not test more than two components.
assertTrue(expectedFieldConverterTypes.size() <= 2);
assertEquals(expectedFieldConverterTypes, index.getFieldConverterTypes());
// Resolved field ordinals depend on the number of resolved converter types
if (expectedFieldConverterTypes.isEmpty()) {
assertTrue(index.getFieldOrdinals().isEmpty());
} else if (expectedFieldConverterTypes.size() == 1) {
assertEquals(singletonList(field1Ordinal), index.getFieldOrdinals());
} else {
assertEquals(Arrays.asList(field1Ordinal, field2Ordinal), index.getFieldOrdinals());
}
}
Aggregations