Search in sources :

Example 16 with Traverser

use of com.hazelcast.jet.Traverser in project hazelcast-jet by hazelcast.

the class TransformPipe method buildDAG.

@Override
public Vertex buildDAG(DAG dag) {
    Vertex previous = upstream.buildDAG(dag);
    // the lambda below must not capture `this`, therefore the instance variable
    // must first be loaded into a local variable
    DistributedFunction<Traverser<E_IN>, Traverser<E_OUT>> transformer = this.transformer;
    Vertex transform = dag.newVertex(uniqueVertexName("transform"), () -> new TransformP<>(transformer));
    if (upstream.isOrdered()) {
        transform.localParallelism(1);
    }
    dag.edge(between(previous, transform));
    return transform;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Traverser(com.hazelcast.jet.Traverser)

Example 17 with Traverser

use of com.hazelcast.jet.Traverser in project hazelcast-jet by hazelcast.

the class AppendableTraverserTest method test_flatMapperUsage.

@Test
public void test_flatMapperUsage() {
    // an instance of AppendableTraverser is repeatedly returned
    // from a flatMap function
    Traverser tt = Traverser.over(10, 20).flatMap(item -> {
        assertTrue(t.isEmpty());
        t.append(item);
        t.append(item + 1);
        return t;
    });
    assertEquals(10, tt.next());
    assertEquals(11, tt.next());
    assertEquals(20, tt.next());
    assertEquals(21, tt.next());
    assertNull(tt.next());
}
Also used : Traverser(com.hazelcast.jet.Traverser) Test(org.junit.Test)

Example 18 with Traverser

use of com.hazelcast.jet.Traverser in project hazelcast-jet by hazelcast.

the class StreamKafkaP method saveToSnapshot.

@Override
public boolean saveToSnapshot() {
    if (!emitFromTraverser(traverser)) {
        return false;
    }
    if (snapshotTraverser == null) {
        Stream<Entry<BroadcastKey<TopicPartition>, long[]>> snapshotStream = offsets.entrySet().stream().flatMap(entry -> IntStream.range(0, entry.getValue().length).filter(partition -> entry.getValue()[partition] >= 0).mapToObj(partition -> {
            TopicPartition key = new TopicPartition(entry.getKey(), partition);
            long offset = entry.getValue()[partition];
            long watermark = watermarkSourceUtil.getWatermark(currentAssignment.get(key));
            return entry(broadcastKey(key), new long[] { offset, watermark });
        }));
        snapshotTraverser = traverseStream(snapshotStream).onFirstNull(() -> snapshotTraverser = null);
    }
    return emitFromTraverserToSnapshot(snapshotTraverser);
}
Also used : IntStream(java.util.stream.IntStream) AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) Traverser(com.hazelcast.jet.Traverser) Arrays(java.util.Arrays) WatermarkSourceUtil(com.hazelcast.jet.core.WatermarkSourceUtil) Processor(com.hazelcast.jet.core.Processor) Traversers.traverseStream(com.hazelcast.jet.Traversers.traverseStream) LoggingUtil.logFinest(com.hazelcast.jet.impl.util.LoggingUtil.logFinest) HashMap(java.util.HashMap) KafkaProcessors(com.hazelcast.jet.kafka.KafkaProcessors) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords) Traversers.traverseIterable(com.hazelcast.jet.Traversers.traverseIterable) InterruptException(org.apache.kafka.common.errors.InterruptException) Util.entry(com.hazelcast.jet.Util.entry) Map(java.util.Map) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) LinkedHashSet(java.util.LinkedHashSet) DistributedSupplier(com.hazelcast.jet.function.DistributedSupplier) TopicPartition(org.apache.kafka.common.TopicPartition) Properties(java.util.Properties) Set(java.util.Set) Traversers(com.hazelcast.jet.Traversers) BroadcastKey(com.hazelcast.jet.core.BroadcastKey) List(java.util.List) BroadcastKey.broadcastKey(com.hazelcast.jet.core.BroadcastKey.broadcastKey) WatermarkGenerationParams(com.hazelcast.jet.core.WatermarkGenerationParams) Stream(java.util.stream.Stream) Preconditions(com.hazelcast.util.Preconditions) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Entry(java.util.Map.Entry) System.arraycopy(java.lang.System.arraycopy) SECONDS(java.util.concurrent.TimeUnit.SECONDS) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) Entry(java.util.Map.Entry) TopicPartition(org.apache.kafka.common.TopicPartition)

Aggregations

Traverser (com.hazelcast.jet.Traverser)18 List (java.util.List)12 FunctionEx (com.hazelcast.function.FunctionEx)10 Nonnull (javax.annotation.Nonnull)10 Traversers (com.hazelcast.jet.Traversers)9 BiFunctionEx (com.hazelcast.function.BiFunctionEx)7 JetException (com.hazelcast.jet.JetException)7 Function (java.util.function.Function)7 Nullable (javax.annotation.Nullable)7 Traversers.traverseIterable (com.hazelcast.jet.Traversers.traverseIterable)6 EventTimePolicy.eventTimePolicy (com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy)6 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 SupplierEx (com.hazelcast.function.SupplierEx)5 AbstractProcessor (com.hazelcast.jet.core.AbstractProcessor)5 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)5 ComparatorEx (com.hazelcast.function.ComparatorEx)4 ToLongFunctionEx (com.hazelcast.function.ToLongFunctionEx)4 Traversers.traverseStream (com.hazelcast.jet.Traversers.traverseStream)4 DAG (com.hazelcast.jet.core.DAG)4