Search in sources :

Example 21 with QueryDataType

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);
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) CompositeConverter(com.hazelcast.query.impl.CompositeConverter)

Example 22 with QueryDataType

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);
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) IndexType(com.hazelcast.config.IndexType) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with QueryDataType

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;
    }
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) OptimizerTestSupport(com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Example 24 with QueryDataType

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());
    }
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) SqlStatement(com.hazelcast.sql.SqlStatement) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) RunWith(org.junit.runner.RunWith) ExpressionBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue) SqlConnectorCache(com.hazelcast.jet.sql.impl.connector.SqlConnectorCache) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) ExpressionBiValue.createBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue.createBiValue) IndexType(com.hazelcast.config.IndexType) OptimizerTestSupport(com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport) Arrays.asList(java.util.Arrays.asList) QueryPath(com.hazelcast.sql.impl.extract.QueryPath) Assert.fail(org.junit.Assert.fail) PartitionedMapTable(com.hazelcast.sql.impl.schema.map.PartitionedMapTable) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) NodeEngine(com.hazelcast.spi.impl.NodeEngine) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) TableResolverImpl(com.hazelcast.jet.sql.impl.schema.TableResolverImpl) MapTableUtils.getPartitionedMapIndexes(com.hazelcast.sql.impl.schema.map.MapTableUtils.getPartitionedMapIndexes) Assert.assertTrue(org.junit.Assert.assertTrue) HazelcastParallelParametersRunnerFactory(com.hazelcast.test.HazelcastParallelParametersRunnerFactory) Test(org.junit.Test) ExpressionBiValue.createBiClass(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue.createBiClass) IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) Category(org.junit.experimental.categories.Category) FullScanPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel) Collectors(java.util.stream.Collectors) TableField(com.hazelcast.sql.impl.schema.TableField) TableResolver(com.hazelcast.sql.impl.schema.TableResolver) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Util.getNodeEngine(com.hazelcast.jet.impl.util.Util.getNodeEngine) FullScanLogicalRel(com.hazelcast.jet.sql.impl.opt.logical.FullScanLogicalRel) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) MapTableIndex(com.hazelcast.sql.impl.schema.map.MapTableIndex) ExpressionType(com.hazelcast.jet.sql.impl.support.expressions.ExpressionType) TablesStorage(com.hazelcast.jet.sql.impl.schema.TablesStorage) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) MapTableIndex(com.hazelcast.sql.impl.schema.map.MapTableIndex) PartitionedMapTable(com.hazelcast.sql.impl.schema.map.PartitionedMapTable)

Example 25 with QueryDataType

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)));
}
Also used : IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) FullScanPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel) OptimizerTestSupport(com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Aggregations

QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)61 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)23 MappingField (com.hazelcast.sql.impl.schema.MappingField)17 ArrayList (java.util.ArrayList)16 TableField (com.hazelcast.sql.impl.schema.TableField)14 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)13 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)10 RelDataType (org.apache.calcite.rel.type.RelDataType)7 OptimizerTestSupport (com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport)6 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)6 FullScanPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel)5 Nonnull (javax.annotation.Nonnull)5 IndexEqualsFilter (com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter)4 Test (org.junit.Test)4 IndexType (com.hazelcast.config.IndexType)3 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 HashMap (java.util.HashMap)3 List (java.util.List)3