Search in sources :

Example 1 with MapIndexScanMetadata

use of com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata in project hazelcast by hazelcast.

the class IMapSqlConnector method indexScanReader.

@Nonnull
@SuppressWarnings("checkstyle:ParameterNumber")
public Vertex indexScanReader(@Nonnull DAG dag, @Nonnull Address localMemberAddress, @Nonnull Table table0, @Nonnull MapTableIndex tableIndex, @Nullable Expression<Boolean> remainingFilter, @Nonnull List<Expression<?>> projection, @Nullable IndexFilter indexFilter, @Nullable ComparatorEx<JetSqlRow> comparator, boolean descending) {
    PartitionedMapTable table = (PartitionedMapTable) table0;
    MapIndexScanMetadata indexScanMetadata = new MapIndexScanMetadata(table.getMapName(), tableIndex.getName(), table.getKeyDescriptor(), table.getValueDescriptor(), Arrays.asList(table.paths()), Arrays.asList(table.types()), indexFilter, projection, remainingFilter, comparator, descending);
    Vertex scanner = dag.newUniqueVertex("Index(" + toString(table) + ")", readMapIndexSupplier(indexScanMetadata));
    // LP must be 1 - one local index contains all local partitions, if there are 2 local processors,
    // the index will be scanned twice and each time half of the partitions will be thrown out.
    scanner.localParallelism(1);
    if (tableIndex.getType() == IndexType.SORTED) {
        Vertex sorter = dag.newUniqueVertex("SortCombine", ProcessorMetaSupplier.forceTotalParallelismOne(ProcessorSupplier.of(mapP(FunctionEx.identity())), localMemberAddress));
        assert comparator != null;
        dag.edge(between(scanner, sorter).ordered(comparator).distributeTo(localMemberAddress).allToOne(""));
        return sorter;
    }
    return scanner;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) PartitionedMapTable(com.hazelcast.sql.impl.schema.map.PartitionedMapTable) Nonnull(javax.annotation.Nonnull)

Example 2 with MapIndexScanMetadata

use of com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata 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);
}
Also used : ArrayList(java.util.ArrayList) JobConfig(com.hazelcast.jet.config.JobConfig) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexConfig(com.hazelcast.config.IndexConfig) FunctionalPredicateExpression(com.hazelcast.sql.impl.expression.FunctionalPredicateExpression) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with MapIndexScanMetadata

use of com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata in project hazelcast by hazelcast.

the class MapIndexScanPTest method test_whenFilterAndSpecificProjectionExists_sorted.

@Test
public void test_whenFilterAndSpecificProjectionExists_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) {
            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);
    IndexFilter filter = new IndexRangeFilter(intValue(0), true, intValue(count / 2), true);
    MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, 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);
}
Also used : IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with MapIndexScanMetadata

use of com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata in project hazelcast by hazelcast.

the class MapIndexScanPTest method test_fullScanAsc_sorted.

@Test
public void test_fullScanAsc_sorted() {
    List<JetSqlRow> expected = new ArrayList<>();
    for (int i = count; i > 0; i--) {
        map.put(i, new Person("value-" + i, i));
        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);
    IndexFilter filter = new IndexRangeFilter(null, true, null, true);
    MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, 2, 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);
}
Also used : IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with MapIndexScanMetadata

use of com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata in project hazelcast by hazelcast.

the class MapIndexScanPTest method test_fullScanDesc_sorted.

@Test
public void test_fullScanDesc_sorted() {
    List<JetSqlRow> expected = new ArrayList<>();
    for (int i = 0; i <= count; i++) {
        map.put(i, new Person("value-" + i, i));
        expected.add(jetRow((count - i), "value-" + (count - i), (count - i)));
    }
    IndexConfig indexConfig = new IndexConfig(IndexType.SORTED, "age").setName(randomName());
    map.addIndex(indexConfig);
    IndexFilter filter = new IndexRangeFilter(null, true, null, true);
    MapIndexScanMetadata metadata = metadata(indexConfig.getName(), filter, 2, true);
    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);
}
Also used : IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) IndexFilter(com.hazelcast.sql.impl.exec.scan.index.IndexFilter) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MapIndexScanMetadata (com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata)8 IndexConfig (com.hazelcast.config.IndexConfig)6 JobConfig (com.hazelcast.jet.config.JobConfig)6 IndexFilter (com.hazelcast.sql.impl.exec.scan.index.IndexFilter)6 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 IndexRangeFilter (com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter)5 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 ConstructorFunction (com.hazelcast.internal.util.ConstructorFunction)1 Vertex (com.hazelcast.jet.core.Vertex)1 KvRowProjector (com.hazelcast.jet.sql.impl.connector.keyvalue.KvRowProjector)1 RowProjectorProcessorSupplier (com.hazelcast.jet.sql.impl.connector.map.RowProjectorProcessorSupplier)1 JsonArrayFunction (com.hazelcast.jet.sql.impl.expression.json.JsonArrayFunction)1 JsonObjectFunction (com.hazelcast.jet.sql.impl.expression.json.JsonObjectFunction)1 JsonParseFunction (com.hazelcast.jet.sql.impl.expression.json.JsonParseFunction)1 JsonQueryFunction (com.hazelcast.jet.sql.impl.expression.json.JsonQueryFunction)1 FieldCollation (com.hazelcast.jet.sql.impl.opt.FieldCollation)1