Tabnine Logo
WindowDefinition
Code IndexAdd Tabnine to your IDE (free)

How to use
WindowDefinition
in
com.hazelcast.jet.pipeline

Best Java code snippets using com.hazelcast.jet.pipeline.WindowDefinition (Showing top 16 results out of 315)

origin: hazelcast/hazelcast-jet

@Override
public void addToDag(Planner p) {
  if (wDef.kind() == SESSION) {
    addSessionWindow(p, wDef.downcast());
  } else if (aggrOp.combineFn() == null) {
    // We don't use single-stage even when optimizing for memory because the
    // single-stage setup doesn't save memory with just one global key.
    addSlidingWindowSingleStage(p, wDef.downcast());
  } else {
    addSlidingWindowTwoStage(p, wDef.downcast());
  }
}
origin: hazelcast/hazelcast-jet

@Override
public long preferredWatermarkStride() {
  return wDef.preferredWatermarkStride();
}
origin: hazelcast/hazelcast-jet-demos

.window(sliding(MINUTES.toMillis(120), MINUTES.toMillis(15)))
.aggregate(linearTrend(CarCount::getTime, CarCount::getCount))
.map((TimestampedEntry<String, Double> e) ->
origin: hazelcast/hazelcast-jet

private static String createName(WindowDefinition wDef) {
  return wDef.kind().name().toLowerCase() + "-window";
}
origin: hazelcast/hazelcast-jet-demos

/**
 * Builds and returns the Pipeline which represents the actual computation.
 */
private static Pipeline buildPipeline(String modelPath) {
  Pipeline pipeline = Pipeline.create();
  pipeline.drawFrom(WebcamSource.webcam(500))
      .mapUsingContext(classifierContext(modelPath),
          (ctx, img) -> {
            Entry<String, Double> classification = classifyWithModel(ctx, img);
            return tuple3(img, classification.getKey(), classification.getValue());
          }
      )
      .window(tumbling(1000))
      .aggregate(maxBy(comparingDouble(Tuple3::f2)))
      .drainTo(buildGUISink());
  return pipeline;
}
origin: hazelcast/hazelcast-jet-code-samples

private static Pipeline buildPipeline() {
  // we'll calculate two aggregations over the same input data:
  // 1. number of viewed product listings
  // 2. set of purchased product IDs
  // Output of the aggregation will be List{Integer, Set<String>}
  AggregateOperation1<ProductEvent, ?, Tuple2<Long, Set<String>>> aggrOp = allOf(
      summingLong(e -> e.getProductEventType() == VIEW_LISTING ? 1 : 0),
      mapping(e -> e.getProductEventType() == PURCHASE ? e.getProductId() : null, toSet())
  );
  Pipeline p = Pipeline.create();
  p.drawFrom(Sources.<ProductEvent>streamFromProcessor("generator",
      ProcessorMetaSupplier.of(GenerateEventsP::new, 1)))
   .addTimestamps(ProductEvent::getTimestamp, 0)
   .groupingKey(ProductEvent::getUserId)
   .window(WindowDefinition.session(SESSION_TIMEOUT))
   .aggregate(aggrOp, SessionWindow::sessionToString)
   .drainTo(Sinks.logger());
  return p;
}
origin: hazelcast/hazelcast-jet-code-samples

private static Pipeline buildPipeline() {
  Pipeline p = Pipeline.create();
  p.drawFrom(Sources.<Trade, Integer, Trade>mapJournal(TRADES_MAP_NAME,
      DistributedPredicate.alwaysTrue(), EventJournalMapEvent::getNewValue, START_FROM_CURRENT))
   .addTimestamps(Trade::getTime, 3000)
   .groupingKey(Trade::getTicker)
   .window(WindowDefinition.sliding(SLIDING_WINDOW_LENGTH_MILLIS, SLIDE_STEP_MILLIS))
   .aggregate(counting(),
       (winStart, winEnd, key, result) -> String.format("%s %5s %4d", toLocalTime(winEnd), key, result))
   .drainTo(Sinks.logger());
  return p;
}
origin: hazelcast/hazelcast-jet

private static String createName(WindowDefinition wDef) {
  return wDef.kind().name().toLowerCase() + "-window";
}
origin: hazelcast/hazelcast-jet-code-samples

@SuppressWarnings("Convert2MethodRef") // https://bugs.openjdk.java.net/browse/JDK-8154236
private static Pipeline aggregate() {
  Pipeline p = Pipeline.create();
  p.drawFrom(Sources.<PageVisit, Integer, PageVisit>mapJournal(PAGE_VISIT,
      mapPutEvents(), mapEventNewValue(), START_FROM_OLDEST))
   .addTimestamps(pv -> pv.timestamp(), 100)
   .window(sliding(10, 1))
   .aggregate(counting())
   .drainTo(Sinks.logger());
  return p;
}
origin: hazelcast/hazelcast-jet

@Override
public void addToDag(Planner p) {
  if (wDef.kind() == SESSION) {
    addSessionWindow(p, wDef.downcast());
  } else if (aggrOp.combineFn() == null || getOptimization() == MEMORY) {
    addSlidingWindowSingleStage(p, wDef.downcast());
  } else {
    addSlidingWindowTwoStage(p, wDef.downcast());
  }
}
origin: hazelcast/hazelcast-jet

@Override
public long preferredWatermarkStride() {
  return wDef.preferredWatermarkStride();
}
origin: hazelcast/hazelcast-jet-code-samples

@SuppressWarnings("Convert2MethodRef") // https://bugs.openjdk.java.net/browse/JDK-8154236
private static Pipeline groupAndAggregate() {
  Pipeline p = Pipeline.create();
  p.drawFrom(Sources.<PageVisit, Integer, PageVisit>mapJournal(PAGE_VISIT,
      mapPutEvents(), mapEventNewValue(), START_FROM_OLDEST))
   .addTimestamps(pv -> pv.timestamp(), 100)
   .window(sliding(10, 1))
   .groupingKey(pv -> pv.userId())
   .aggregate(toList())
   .drainTo(Sinks.logger());
  return p;
}
origin: hazelcast/hazelcast-jet-code-samples

/**
 * This code is the main point of the sample: use the source builder to
 * create an HTTP source connector, then create a Jet pipeline that
 * performs windowed aggregation over its data.
 */
private static Pipeline buildPipeline() {
  StreamSource<TimestampedItem<Long>> usedMemorySource = SourceBuilder
      .timestampedStream("used-memory", x -> new PollHttp())
      .fillBufferFn(PollHttp::fillBuffer)
      .destroyFn(PollHttp::close)
      .build();
  Pipeline p = Pipeline.create();
  p.drawFrom(usedMemorySource)
   .window(sliding(100, 20))
   .aggregate(linearTrend(TimestampedItem::timestamp, TimestampedItem::item))
   .map(tsItem -> entry(tsItem.timestamp(), tsItem.item()))
   .drainTo(Sinks.map(MAP_NAME));
  return p;
}
origin: hazelcast/hazelcast-jet-code-samples

private static Pipeline buildPipeline() {
  Pipeline p = Pipeline.create();
  p.drawFrom(Sources.<PriceUpdateEvent, String, Tuple2<Integer, Long>>mapJournal(
      "prices",
      mapPutEvents(),
      e -> new PriceUpdateEvent(e.getKey(), e.getNewValue().f0(), e.getNewValue().f1()),
      START_FROM_CURRENT
  ))
   .addTimestamps(PriceUpdateEvent::timestamp, LAG_SECONDS * 1000)
   .setLocalParallelism(1)
   .groupingKey(PriceUpdateEvent::ticker)
   .window(WindowDefinition.sliding(WINDOW_SIZE_SECONDS * 1000, 1000))
   .aggregate(AggregateOperations.counting())
   .drainTo(Sinks.logger());
  return p;
}
origin: hazelcast/hazelcast-jet-code-samples

@SuppressWarnings("Convert2MethodRef") // https://bugs.openjdk.java.net/browse/JDK-8154236
private static Pipeline coGroup() {
  Pipeline p = Pipeline.create();
  StreamStageWithKey<PageVisit, Integer> pageVisits = p
      .drawFrom(Sources.<PageVisit, Integer, PageVisit>mapJournal(PAGE_VISIT,
          mapPutEvents(), mapEventNewValue(), START_FROM_OLDEST))
      .addTimestamps(pv -> pv.timestamp(), 100)
      .groupingKey(pv -> pv.userId());
  StreamStageWithKey<Payment, Integer> payments = p
      .drawFrom(Sources.<Payment, Integer, Payment>mapJournal(PAYMENT,
          mapPutEvents(), mapEventNewValue(), START_FROM_OLDEST))
      .addTimestamps(pm -> pm.timestamp(), 100)
      .groupingKey(pm -> pm.userId());
  StreamStageWithKey<AddToCart, Integer> addToCarts = p
      .drawFrom(Sources.<AddToCart, Integer, AddToCart>mapJournal(ADD_TO_CART,
          mapPutEvents(), mapEventNewValue(), START_FROM_OLDEST))
      .addTimestamps(atc -> atc.timestamp(), 100)
      .groupingKey(atc -> atc.userId());
  StageWithKeyAndWindow<PageVisit, Integer> windowStage = pageVisits.window(sliding(10, 1));
  StreamStage<TimestampedEntry<Integer, Tuple3<List<PageVisit>, List<AddToCart>, List<Payment>>>> coGrouped =
      windowStage.aggregate3(toList(), addToCarts, toList(), payments, toList());
  coGrouped.drainTo(Sinks.logger());
  return p;
}
origin: hazelcast/hazelcast-jet-code-samples

@SuppressWarnings("Convert2MethodRef") // https://bugs.openjdk.java.net/browse/JDK-8154236
private static Pipeline coGroupWithBuilder() {
  Pipeline p = Pipeline.create();
  StreamStageWithKey<PageVisit, Integer> pageVisits = p
      .drawFrom(Sources.<PageVisit, Integer, PageVisit>mapJournal(PAGE_VISIT,
          mapPutEvents(), mapEventNewValue(), START_FROM_OLDEST))
      .addTimestamps(pv -> pv.timestamp(), 100)
      .groupingKey(pv -> pv.userId());
  StreamStageWithKey<AddToCart, Integer> addToCarts = p
      .drawFrom(Sources.<AddToCart, Integer, AddToCart>mapJournal(ADD_TO_CART,
          mapPutEvents(), mapEventNewValue(), START_FROM_OLDEST))
      .addTimestamps(atc -> atc.timestamp(), 100)
      .groupingKey(atc -> atc.userId());
  StreamStageWithKey<Payment, Integer> payments = p
      .drawFrom(Sources.<Payment, Integer, Payment>mapJournal(PAYMENT,
          mapPutEvents(), mapEventNewValue(), START_FROM_OLDEST))
      .addTimestamps(pm -> pm.timestamp(), 100)
      .groupingKey(pm -> pm.userId());
  StageWithKeyAndWindow<PageVisit, Integer> windowStage = pageVisits.window(sliding(10, 1));
  WindowGroupAggregateBuilder<Integer, List<PageVisit>> builder = windowStage.aggregateBuilder(toList());
  Tag<List<PageVisit>> pageVisitTag = builder.tag0();
  Tag<List<AddToCart>> addToCartTag = builder.add(addToCarts, toList());
  Tag<List<Payment>> paymentTag = builder.add(payments, toList());
  StreamStage<TimestampedEntry<Integer, Tuple3<List<PageVisit>, List<AddToCart>, List<Payment>>>> coGrouped =
      builder.build((winStart, winEnd, key, r) -> new TimestampedEntry<>(
          winEnd, key, tuple3(r.get(pageVisitTag), r.get(addToCartTag), r.get(paymentTag))));
  coGrouped.drainTo(Sinks.logger());
  return p;
}
com.hazelcast.jet.pipelineWindowDefinition

Javadoc

The definition of the window for a windowed aggregation operation. The enum WindowKind enumerates the kinds of window that Jet supports. To obtain a window definition, use the factory methods provided in this interface.

Most used methods

  • sliding
    Returns a WindowKind#SLIDING window definition with the given parameters. Find more information in t
  • downcast
    Returns this window definition downcast to the type determined through type inference at the call si
  • kind
    Returns what kind of window this definition describes.
  • preferredWatermarkStride
    Returns the optimal watermark stride for this window definition. Watermarks that are more spaced out
  • session
    Returns a window definition that aggregates events into session windows. Events and windows under di
  • tumbling
    Returns a tumbling window definition with the given parameters. Tumbling window is a special case of

Popular in Java

  • Parsing JSON documents to java classes using gson
  • notifyDataSetChanged (ArrayAdapter)
  • getApplicationContext (Context)
  • getSharedPreferences (Context)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now