Search in sources :

Example 36 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet-reference-manual by hazelcast.

the class S8 method main.

// end::s1[]
static void main() {
    // tag::s2[]
    JetInstance jet = Jet.newJetInstance();
    int upperBound = 10;
    DAG dag = new DAG();
    Vertex generateNumbers = dag.newVertex("generate-numbers", () -> new GenerateNumbersP(upperBound));
    Vertex logInput = dag.newVertex("log-input", DiagnosticProcessors.writeLoggerP(i -> "Received number: " + i));
    dag.edge(Edge.between(generateNumbers, logInput));
    try {
        jet.newJob(dag).join();
    } finally {
        Jet.shutdownAll();
    }
// end::s2[]
}
Also used : IntStream(java.util.stream.IntStream) AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) Traverser(com.hazelcast.jet.Traverser) DiagnosticProcessors(com.hazelcast.jet.core.processor.DiagnosticProcessors) JetInstance(com.hazelcast.jet.JetInstance) IntStream.range(java.util.stream.IntStream.range) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Processor(com.hazelcast.jet.core.Processor) Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) Traversers(com.hazelcast.jet.Traversers) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Vertex(com.hazelcast.jet.core.Vertex) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Map(java.util.Map) Context(com.hazelcast.jet.core.Processor.Context) Jet(com.hazelcast.jet.Jet) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) Nonnull(javax.annotation.Nonnull) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Vertex(com.hazelcast.jet.core.Vertex) JetInstance(com.hazelcast.jet.JetInstance) DAG(com.hazelcast.jet.core.DAG)

Example 37 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet-reference-manual by hazelcast.

the class ExpertZoneDag method s2.

static void s2() {
    // tag::s2[]
    // <1>
    Vertex source = dag.newVertex("source", SourceProcessors.readFilesP(".", UTF_8, "*", (file, line) -> line));
    Vertex transform = dag.newVertex("transform", mapP((String line) -> entry(line, line.length())));
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeMapP("sinkMap"));
    // <2>
    source.localParallelism(1);
    // <3>
    dag.edge(between(source, transform));
    dag.edge(between(transform, sink));
// end::s2[]
}
Also used : EdgeConfig(com.hazelcast.jet.config.EdgeConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Partitioner(com.hazelcast.jet.core.Partitioner) SourceProcessors(com.hazelcast.jet.core.processor.SourceProcessors) Processors.mapP(com.hazelcast.jet.core.processor.Processors.mapP) DistributedFunctions.entryKey(com.hazelcast.jet.function.DistributedFunctions.entryKey) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) Vertex(com.hazelcast.jet.core.Vertex) Util.entry(com.hazelcast.jet.Util.entry) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) HASH_CODE(com.hazelcast.jet.core.Partitioner.HASH_CODE) Edge.from(com.hazelcast.jet.core.Edge.from) DAG(com.hazelcast.jet.core.DAG) Edge.between(com.hazelcast.jet.core.Edge.between) Vertex(com.hazelcast.jet.core.Vertex)

Example 38 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet-reference-manual by hazelcast.

the class ExpertZoneDag method s3.

static void s3() {
    // tag::s3[]
    Vertex source = dag.newVertex("source", SourceProcessors.readFilesP(".", UTF_8, "*", (file, line) -> line));
    Vertex toUpper = dag.newVertex("toUpper", mapP((String in) -> in.toUpperCase()));
    Vertex toLower = dag.newVertex("toLower", mapP((String in) -> in.toLowerCase()));
    dag.edge(between(source, toUpper));
    dag.edge(from(source, 1).to(toLower));
// end::s3[]
}
Also used : EdgeConfig(com.hazelcast.jet.config.EdgeConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Partitioner(com.hazelcast.jet.core.Partitioner) SourceProcessors(com.hazelcast.jet.core.processor.SourceProcessors) Processors.mapP(com.hazelcast.jet.core.processor.Processors.mapP) DistributedFunctions.entryKey(com.hazelcast.jet.function.DistributedFunctions.entryKey) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) Vertex(com.hazelcast.jet.core.Vertex) Util.entry(com.hazelcast.jet.Util.entry) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) HASH_CODE(com.hazelcast.jet.core.Partitioner.HASH_CODE) Edge.from(com.hazelcast.jet.core.Edge.from) DAG(com.hazelcast.jet.core.DAG) Edge.between(com.hazelcast.jet.core.Edge.between) Vertex(com.hazelcast.jet.core.Vertex)

Example 39 with Vertex

use of com.hazelcast.jet.core.Vertex 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 40 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.

the class KafkaSqlConnector method writeProcessor.

@Nonnull
private Vertex writeProcessor(DAG dag, Table table0) {
    KafkaTable table = (KafkaTable) table0;
    Vertex vStart = dag.newUniqueVertex("Project(" + table + ")", KvProcessors.entryProjector(table.paths(), table.types(), table.keyUpsertDescriptor(), table.valueUpsertDescriptor(), false));
    // set the parallelism to match that of the kafka sink - see https://github.com/hazelcast/hazelcast/issues/20507
    // TODO eliminate the project vertex altogether and do the projecting in the sink directly
    vStart.localParallelism(1);
    Vertex vEnd = dag.newUniqueVertex(table.toString(), KafkaProcessors.<Entry<Object, Object>, Object, Object>writeKafkaP(table.kafkaProducerProperties(), table.topicName(), Entry::getKey, Entry::getValue, true));
    dag.edge(between(vStart, vEnd));
    return vStart;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Nonnull(javax.annotation.Nonnull)

Aggregations

Vertex (com.hazelcast.jet.core.Vertex)189 DAG (com.hazelcast.jet.core.DAG)130 Test (org.junit.Test)95 QuickTest (com.hazelcast.test.annotation.QuickTest)57 Job (com.hazelcast.jet.Job)53 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)48 Entry (java.util.Map.Entry)41 List (java.util.List)28 Edge.between (com.hazelcast.jet.core.Edge.between)26 Map (java.util.Map)26 Assert.assertEquals (org.junit.Assert.assertEquals)23 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)21 IntStream (java.util.stream.IntStream)21 Assert.assertTrue (org.junit.Assert.assertTrue)19 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)18 Category (org.junit.experimental.categories.Category)18 Collectors.toList (java.util.stream.Collectors.toList)17 Nonnull (javax.annotation.Nonnull)17 FunctionEx (com.hazelcast.function.FunctionEx)15 Edge (com.hazelcast.jet.core.Edge)15