use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class MapTableConverterResolutionTest method checkCompositeConverter.
private void checkCompositeConverter(TypeConverter converter1, TypeConverter converter2, QueryDataType... expectedTypes) {
CompositeConverter converter = new CompositeConverter(new TypeConverter[] { converter1, converter2 });
List<QueryDataType> types = MapTableUtils.indexConverterToSqlTypes(converter);
List<QueryDataType> expectedTypes0 = expectedTypes == null ? Collections.emptyList() : Arrays.asList(expectedTypes);
assertEquals(expectedTypes0, types);
}
use of com.hazelcast.sql.impl.type.QueryDataType 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.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class SqlIndexResolutionTest method checkIndexUsage.
private void checkIndexUsage(SqlStatement statement, String mapName, Usage expectedIndexUsage) {
List<QueryDataType> parameterTypes = asList(QueryDataType.INT, QueryDataType.OBJECT, QueryDataType.INT);
List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("field1", type1.getFieldConverterType(), false, new QueryPath("field1", false)), new MapTableField("field2", type2.getFieldConverterType(), false, new QueryPath("field2", false)));
HazelcastTable table = partitionedTable(mapName, mapTableFields, getPartitionedMapIndexes(mapContainer(instance().getMap(mapName)), mapTableFields), // we can place random number, doesn't matter in current case.
1);
OptimizerTestSupport.Result optimizationResult = optimizePhysical(statement.getSql(), parameterTypes, table);
assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
switch(expectedIndexUsage) {
case NONE:
assertPlan(optimizationResult.getPhysical(), plan(planRow(0, FullScanPhysicalRel.class)));
break;
case ONE:
assertPlan(optimizationResult.getPhysical(), plan(planRow(0, IndexScanMapPhysicalRel.class)));
assertNotNull(((IndexScanMapPhysicalRel) optimizationResult.getPhysical()).getRemainderExp());
break;
case BOTH:
assertPlan(optimizationResult.getPhysical(), plan(planRow(0, IndexScanMapPhysicalRel.class)));
assertNull(((IndexScanMapPhysicalRel) optimizationResult.getPhysical()).getRemainderExp());
break;
}
}
use of com.hazelcast.sql.impl.type.QueryDataType 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());
}
}
use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class SqlSecurityCallbackTest method checkIndexUsage.
private void checkIndexUsage(String sql, boolean expectedIndexUsage) {
List<QueryDataType> parameterTypes = asList(QueryDataType.INT, QueryDataType.INT);
List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("this", QueryDataType.INT, false, QueryPath.VALUE_PATH));
HazelcastTable table = partitionedTable(mapName, mapTableFields, getPartitionedMapIndexes(mapContainer(instance().getMap(mapName)), mapTableFields), mapSize);
OptimizerTestSupport.Result optimizationResult = optimizePhysical(sql, parameterTypes, table);
assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
assertPlan(optimizationResult.getPhysical(), plan(planRow(0, expectedIndexUsage ? IndexScanMapPhysicalRel.class : FullScanPhysicalRel.class)));
}
Aggregations