• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FixedWindows类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.beam.sdk.transforms.windowing.FixedWindows的典型用法代码示例。如果您正苦于以下问题:Java FixedWindows类的具体用法?Java FixedWindows怎么用?Java FixedWindows使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FixedWindows类属于org.apache.beam.sdk.transforms.windowing包,在下文中一共展示了FixedWindows类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

    Options options = PipelineOptionsFactory.fromArgs(args).withValidation()
        .as(Options.class);
    options.setRunner(FlinkRunner.class);

    Pipeline p = Pipeline.create(options);

    KafkaIO.Read<byte[], String> kafkaIOReader = KafkaIO.read()
        .withBootstrapServers("192.168.99.100:32771")
        .withTopics(Arrays.asList("beam".split(",")))
        .updateConsumerProperties(ImmutableMap.of("auto.offset.reset", (Object)"earliest"))
        .withValueCoder(StringUtf8Coder.of());

    p.apply(kafkaIOReader.withoutMetadata())
        .apply(Values.<String>create())
        .apply(Window.<String>into(
          FixedWindows.of(Duration.standardMinutes(options.getWindowSize()))))
        .apply(new CountWords())
        .apply(MapElements.via(new FormatAsTextFn()))
        .apply("WriteCounts", TextIO.Write.to(options.getOutput()));

    p.run();
  }
 
开发者ID:0x0ece,项目名称:beam-starter,代码行数:25,代码来源:StreamWordCount.java


示例2: main

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
/** Run a batch pipeline to calculate hourly team scores. */
public static void main(String[] args) throws Exception {

  Options options =
      PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
  Pipeline pipeline = Pipeline.create(options);

  pipeline
  .apply("ReadLogs", TextIO.read().from(options.getInput()))
  .apply("SetTimestamps", WithTimestamps.of(new SetTimestampFn()))

  .apply("FixedWindows", Window.<String>into(FixedWindows.of(ONE_HOUR)))

  .apply("TeamScores", new CalculateTeamScores(options.getOutputPrefix()));

  pipeline.run();
}
 
开发者ID:davorbonaci,项目名称:beam-portability-demo,代码行数:18,代码来源:HourlyTeamScore.java


示例3: main

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

    Options options =
        PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
    Pipeline pipeline = Pipeline.create(options);

    pipeline
    .apply(KafkaIO.<String, String>read()
        .withBootstrapServers(options.getKafkaBootstrapServer())
        .withTopic(options.getTopic())
        .withKeyDeserializer(StringDeserializer.class)
        .withValueDeserializer(StringDeserializer.class)
        .withTimestampFn(new SetTimestampFn()))
    .apply("Values", ParDo.of(new ValuesFn()))

    .apply("FixedWindows", Window.<String>into(FixedWindows.of(FIVE_MINUTES))
        .triggering(AfterWatermark.pastEndOfWindow()
            .withEarlyFirings(AfterProcessingTime.pastFirstElementInPane()
                .plusDelayOf(TWO_MINUTES))
            .withLateFirings(AfterPane.elementCountAtLeast(1)))
        .withAllowedLateness(TEN_MINUTES)
        .accumulatingFiredPanes())

    .apply("TeamScore", new CalculateTeamScores(options.getOutputPrefix()));

    pipeline.run();
  }
 
开发者ID:davorbonaci,项目名称:beam-portability-demo,代码行数:28,代码来源:LeaderBoard.java


示例4: expand

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Override
public PCollection<KV<String, Integer>> expand(PCollection<GameActionInfo> infos) {
  return infos.apply("LeaderboardTeamFixedWindows",
      Window.<GameActionInfo>into(FixedWindows.of(teamWindowDuration))
          // We will get early (speculative) results as well as cumulative
          // processing of late data.
          .triggering(AfterWatermark.pastEndOfWindow()
              .withEarlyFirings(AfterProcessingTime.pastFirstElementInPane()
                  .plusDelayOf(FIVE_MINUTES))
              .withLateFirings(AfterProcessingTime.pastFirstElementInPane()
                  .plusDelayOf(TEN_MINUTES)))
          .withAllowedLateness(allowedLateness)
          .accumulatingFiredPanes())
      // Extract and sum teamname/score pairs from the event data.
      .apply("ExtractTeamScore", new ExtractAndSumScore("team"));
}
 
开发者ID:apache,项目名称:beam,代码行数:17,代码来源:LeaderBoard.java


示例5: testTotalFlow

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
@Category(ValidatesRunner.class)
public void testTotalFlow () {
  PCollection<KV<String, Integer>> flow = pipeline
      .apply(Create.timestamped(TIME_STAMPED_INPUT))
      .apply(ParDo.of(new ExtractFlowInfo()));

  PCollection<TableRow> totalFlow = flow
      .apply(Window.<KV<String, Integer>>into(FixedWindows.of(Duration.standardMinutes(1))))
      .apply(new TotalFlow("default"));

  PCollection<String> results =  totalFlow.apply(ParDo.of(new FormatResults()));

  PAssert.that(results)
      .containsInAnyOrder(canonicalFormat(OUT_ROW_1), canonicalFormat(OUT_ROW_2));
  pipeline.run().waitUntilFinish();

}
 
开发者ID:apache,项目名称:beam,代码行数:19,代码来源:TriggerExampleTest.java


示例6: testOnlyT1ShouldFireFixedWindows

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
public void testOnlyT1ShouldFireFixedWindows() throws Exception {
  tester =
      TriggerStateMachineTester.forTrigger(
          AfterFirstStateMachine.of(mockTrigger1, mockTrigger2),
          FixedWindows.of(Duration.millis(10)));
  tester.injectElements(1);
  IntervalWindow window = new IntervalWindow(new Instant(1), new Instant(11));

  when(mockTrigger1.shouldFire(anyTriggerContext())).thenReturn(true);
  when(mockTrigger2.shouldFire(anyTriggerContext())).thenReturn(false);

  assertTrue(tester.shouldFire(window)); // should fire

  tester.fireIfShouldFire(window);
  assertTrue(tester.isMarkedFinished(window));
}
 
开发者ID:apache,项目名称:beam,代码行数:18,代码来源:AfterFirstStateMachineTest.java


示例7: testReshuffleAfterFixedWindowsAndGroupByKey

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
@Category(ValidatesRunner.class)
public void testReshuffleAfterFixedWindowsAndGroupByKey() {

  PCollection<KV<String, Iterable<Integer>>> input = pipeline
      .apply(Create.of(GBK_TESTABLE_KVS)
          .withCoder(KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of())))
      .apply(Window.<KV<String, Integer>>into(
          FixedWindows.of(Duration.standardMinutes(10L))))
      .apply(GroupByKey.<String, Integer>create());

  PCollection<KV<String, Iterable<Integer>>> output = input
      .apply(Reshuffle.<String, Iterable<Integer>>of());

  PAssert.that(output).satisfies(new AssertThatHasExpectedContents());

  assertEquals(
      input.getWindowingStrategy(),
      output.getWindowingStrategy());

  pipeline.run();
}
 
开发者ID:apache,项目名称:beam,代码行数:23,代码来源:ReshuffleTest.java


示例8: testReshuffleAfterFixedWindows

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
@Category(ValidatesRunner.class)
public void testReshuffleAfterFixedWindows() {

  PCollection<KV<String, Integer>> input = pipeline
      .apply(Create.of(ARBITRARY_KVS)
          .withCoder(KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of())))
      .apply(Window.<KV<String, Integer>>into(
          FixedWindows.of(Duration.standardMinutes(10L))));

  PCollection<KV<String, Integer>> output = input
      .apply(Reshuffle.<String, Integer>of());

  PAssert.that(output).containsInAnyOrder(ARBITRARY_KVS);

  assertEquals(
      input.getWindowingStrategy(),
      output.getWindowingStrategy());

  pipeline.run();
}
 
开发者ID:apache,项目名称:beam,代码行数:22,代码来源:ReshuffleTest.java


示例9: testReshuffleAfterSlidingWindows

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
@Category(ValidatesRunner.class)
public void testReshuffleAfterSlidingWindows() {

  PCollection<KV<String, Integer>> input = pipeline
      .apply(Create.of(ARBITRARY_KVS)
          .withCoder(KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of())))
      .apply(Window.<KV<String, Integer>>into(
          FixedWindows.of(Duration.standardMinutes(10L))));

  PCollection<KV<String, Integer>> output = input
      .apply(Reshuffle.<String, Integer>of());

  PAssert.that(output).containsInAnyOrder(ARBITRARY_KVS);

  assertEquals(
      input.getWindowingStrategy(),
      output.getWindowingStrategy());

  pipeline.run();
}
 
开发者ID:apache,项目名称:beam,代码行数:22,代码来源:ReshuffleTest.java


示例10: testSampleAnyZero

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
@Category(ValidatesRunner.class)
public void testSampleAnyZero() {
  PCollection<Integer> input =
      pipeline.apply(
          Create.timestamped(ImmutableList.of(tv(0), tv(1), tv(2), tv(3), tv(4), tv(5)))
              .withCoder(BigEndianIntegerCoder.of()));
  PCollection<Integer> output = input
      .apply(Window.<Integer>into(FixedWindows.of(Duration.standardSeconds(3))))
      .apply(Sample.<Integer>any(0));

  PAssert.that(output)
      .inWindow(new IntervalWindow(new Instant(0), Duration.standardSeconds(3)))
      .satisfies(new VerifyCorrectSample<>(0, EMPTY));
  PAssert.that(output)
      .inWindow(new IntervalWindow(new Instant(3000), Duration.standardSeconds(3)))
      .satisfies(new VerifyCorrectSample<>(0, EMPTY));
  pipeline.run();
}
 
开发者ID:apache,项目名称:beam,代码行数:20,代码来源:SampleTest.java


示例11: testActualFiresAndFinishes

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
/**
 * Tests that for {@code OrFinally(actual, ...)} when {@code actual}
 * fires and finishes, the {@code OrFinally} also fires and finishes.
 */
@Test
public void testActualFiresAndFinishes() throws Exception {
  tester = TriggerStateMachineTester.forTrigger(
      new OrFinallyStateMachine(
          AfterPaneStateMachine.elementCountAtLeast(2),
          AfterPaneStateMachine.elementCountAtLeast(100)),
      FixedWindows.of(Duration.millis(100)));

  IntervalWindow window = new IntervalWindow(new Instant(0), new Instant(100));

  // Not yet firing
  tester.injectElements(1);
  assertFalse(tester.shouldFire(window));
  assertFalse(tester.isMarkedFinished(window));

  // The actual fires and finishes
  tester.injectElements(2);
  assertTrue(tester.shouldFire(window));
  tester.fireIfShouldFire(window);
  assertTrue(tester.isMarkedFinished(window));
}
 
开发者ID:apache,项目名称:beam,代码行数:26,代码来源:OrFinallyStateMachineTest.java


示例12: testT1FiresFirst

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
public void testT1FiresFirst() throws Exception {
  tester = TriggerStateMachineTester.forTrigger(
      AfterAllStateMachine.of(
          AfterPaneStateMachine.elementCountAtLeast(1),
          AfterPaneStateMachine.elementCountAtLeast(2)),
      FixedWindows.of(Duration.millis(100)));

  IntervalWindow window = new IntervalWindow(new Instant(0), new Instant(100));

  tester.injectElements(1);
  assertFalse(tester.shouldFire(window));

  tester.injectElements(2);
  assertTrue(tester.shouldFire(window));
  tester.fireIfShouldFire(window);
  assertTrue(tester.isMarkedFinished(window));
}
 
开发者ID:apache,项目名称:beam,代码行数:19,代码来源:AfterAllStateMachineTest.java


示例13: testEqualWindowFnPropagation

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
@Category(NeedsRunner.class)
public void testEqualWindowFnPropagation() {
  PCollection<String> input1 =
      p.apply("CreateInput1", Create.of("Input1"))
      .apply("Window1", Window.<String>into(FixedWindows.of(Duration.standardMinutes(1))));
  PCollection<String> input2 =
      p.apply("CreateInput2", Create.of("Input2"))
      .apply("Window2", Window.<String>into(FixedWindows.of(Duration.standardMinutes(1))));

  PCollection<String> output =
      PCollectionList.of(input1).and(input2)
      .apply(Flatten.<String>pCollections());

  p.run();

  Assert.assertTrue(output.getWindowingStrategy().getWindowFn().isCompatible(
      FixedWindows.of(Duration.standardMinutes(1))));
}
 
开发者ID:apache,项目名称:beam,代码行数:20,代码来源:FlattenTest.java


示例14: testIncompatibleWindowFnPropagationFailure

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
public void testIncompatibleWindowFnPropagationFailure() {
  p.enableAbandonedNodeEnforcement(false);

  PCollection<String> input1 =
      p.apply("CreateInput1", Create.of("Input1"))
      .apply("Window1", Window.<String>into(FixedWindows.of(Duration.standardMinutes(1))));
  PCollection<String> input2 =
      p.apply("CreateInput2", Create.of("Input2"))
      .apply("Window2", Window.<String>into(FixedWindows.of(Duration.standardMinutes(2))));

  try {
    PCollectionList.of(input1).and(input2)
        .apply(Flatten.<String>pCollections());
    Assert.fail("Exception should have been thrown");
  } catch (IllegalStateException e) {
    Assert.assertTrue(e.getMessage().startsWith(
        "Inputs to Flatten had incompatible window windowFns"));
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:21,代码来源:FlattenTest.java


示例15: testIdentityWindowFnPropagation

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
@Category(NeedsRunner.class)
public void testIdentityWindowFnPropagation() {

  List<KV<String, Integer>> ungroupedPairs = Arrays.asList();

  PCollection<KV<String, Integer>> input =
      p.apply(Create.of(ungroupedPairs)
          .withCoder(KvCoder.of(StringUtf8Coder.of(), BigEndianIntegerCoder.of())))
      .apply(Window.<KV<String, Integer>>into(FixedWindows.of(Duration.standardMinutes(1))));

  PCollection<KV<String, Iterable<Integer>>> output =
      input.apply(GroupByKey.<String, Integer>create());

  p.run();

  Assert.assertTrue(output.getWindowingStrategy().getWindowFn().isCompatible(
      FixedWindows.of(Duration.standardMinutes(1))));
}
 
开发者ID:apache,项目名称:beam,代码行数:20,代码来源:GroupByKeyTest.java


示例16: testTimestampCombinerEarliest

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
/**
 * Tests that when two elements are combined via a GroupByKey their output timestamp agrees
 * with the windowing function customized to actually be the same as the default, the earlier of
 * the two values.
 */
@Test
@Category(ValidatesRunner.class)
public void testTimestampCombinerEarliest() {

  p.apply(
      Create.timestamped(
          TimestampedValue.of(KV.of(0, "hello"), new Instant(0)),
          TimestampedValue.of(KV.of(0, "goodbye"), new Instant(10))))
      .apply(Window.<KV<Integer, String>>into(FixedWindows.of(Duration.standardMinutes(10)))
          .withTimestampCombiner(TimestampCombiner.EARLIEST))
      .apply(GroupByKey.<Integer, String>create())
      .apply(ParDo.of(new AssertTimestamp(new Instant(0))));

  p.run();
}
 
开发者ID:apache,项目名称:beam,代码行数:21,代码来源:GroupByKeyTest.java


示例17: testElementsAtAlmostPositiveInfinity

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
@Category({NeedsRunner.class, UsesTestStream.class})
public void testElementsAtAlmostPositiveInfinity() {
  Instant endOfGlobalWindow = GlobalWindow.INSTANCE.maxTimestamp();
  TestStream<String> stream =
      TestStream.create(StringUtf8Coder.of())
          .addElements(
              TimestampedValue.of("foo", endOfGlobalWindow),
              TimestampedValue.of("bar", endOfGlobalWindow))
          .advanceWatermarkToInfinity();

  FixedWindows windows = FixedWindows.of(Duration.standardHours(6));
  PCollection<String> windowedValues =
      p.apply(stream)
          .apply(Window.<String>into(windows))
          .apply(WithKeys.<Integer, String>of(1))
          .apply(GroupByKey.<Integer, String>create())
          .apply(Values.<Iterable<String>>create())
          .apply(Flatten.<String>iterables());

  PAssert.that(windowedValues)
      .inWindow(windows.assignWindow(endOfGlobalWindow))
      .containsInAnyOrder("foo", "bar");
  p.run();
}
 
开发者ID:apache,项目名称:beam,代码行数:26,代码来源:TestStreamTest.java


示例18: testWindowedIsEqualTo

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
/**
 * Basic test for {@code isEqualTo}.
 */
@Test
@Category(ValidatesRunner.class)
public void testWindowedIsEqualTo() throws Exception {
  PCollection<Integer> pcollection =
      pipeline.apply(Create.timestamped(TimestampedValue.of(43, new Instant(250L)),
          TimestampedValue.of(22, new Instant(-250L))))
          .apply(Window.<Integer>into(FixedWindows.of(Duration.millis(500L))));
  PAssert.thatSingleton(pcollection)
      .inOnlyPane(new IntervalWindow(new Instant(0L), new Instant(500L)))
      .isEqualTo(43);
  PAssert.thatSingleton(pcollection)
      .inOnlyPane(new IntervalWindow(new Instant(-500L), new Instant(0L)))
      .isEqualTo(22);
  pipeline.run();
}
 
开发者ID:apache,项目名称:beam,代码行数:19,代码来源:PAssertTest.java


示例19: testWriteSpilling

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
@Category(NeedsRunner.class)
public void testWriteSpilling() throws IOException {
  List<String> inputs = Lists.newArrayList();
  for (int i = 0; i < 100; ++i) {
    inputs.add("mambo_number_" + i);
  }
  runWrite(
      inputs,
      Window.<String>into(FixedWindows.of(Duration.millis(2))),
      getBaseOutputFilename(),
      WriteFiles.to(makeSimpleSink())
          .withMaxNumWritersPerBundle(2)
          .withWindowedWrites()
          .withNumShards(1));
}
 
开发者ID:apache,项目名称:beam,代码行数:17,代码来源:WriteFilesTest.java


示例20: testWindowingStrategy

import org.apache.beam.sdk.transforms.windowing.FixedWindows; //导入依赖的package包/类
@Test
public void testWindowingStrategy() throws Exception {
  SdkComponents sdkComponents = SdkComponents.create();
  WindowingStrategy windowingStrategy =
      WindowingStrategy.of(FixedWindows.of(Duration.millis(1)))
          .withAllowedLateness(Duration.standardSeconds(4));
  String id = sdkComponents.registerWindowingStrategy(windowingStrategy);
  RehydratedComponents rehydratedComponents =
      RehydratedComponents.forComponents(sdkComponents.toComponents());

  WindowingStrategy<?, ?> rehydratedStrategy = rehydratedComponents.getWindowingStrategy(id);
  assertThat(rehydratedStrategy, equalTo((WindowingStrategy) windowingStrategy.fixDefaults()));
  assertThat(
      rehydratedComponents.getWindowingStrategy(id),
      theInstance((WindowingStrategy) rehydratedStrategy));
}
 
开发者ID:apache,项目名称:beam,代码行数:17,代码来源:RehydratedComponentsTest.java



注:本文中的org.apache.beam.sdk.transforms.windowing.FixedWindows类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ParsingContext类代码示例发布时间:2022-05-22
下一篇:
Java SimpleByteSource类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap