热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.apache.beam.sdk.values.TimestampedValue.of()方法的使用及代码示例

本文整理了Java中org.apache.beam.sdk.values.TimestampedValue.of()方法的一些代码示例,展示了Timesta

本文整理了Java中org.apache.beam.sdk.values.TimestampedValue.of()方法的一些代码示例,展示了TimestampedValue.of()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimestampedValue.of()方法的具体详情如下:
包路径:org.apache.beam.sdk.values.TimestampedValue
类名称:TimestampedValue
方法名:of

TimestampedValue.of介绍

[英]Returns a new TimestampedValue with the given value and timestamp.
[中]返回具有给定值和时间戳的新TimestampedValue。

代码示例

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

/**
* Runs the {@link WindowFn} over the provided input, returning a map of windows to the timestamps
* in those windows.
*/
public static Map> runWindowFn(
WindowFn windowFn, List timestamps) throws Exception {
List> timestampedValues = new ArrayList<>();
for (Long timestamp : timestamps) {
timestampedValues.add(TimestampedValue.of((T) null, new Instant(timestamp)));
}
return runWindowFnWithValue(windowFn, timestampedValues);
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
@Category(NeedsRunner.class)
public void timestampsSucceeds() {
PCollection timestamped =
pipeline.apply(
Create.timestamped(
TimestampedValue.of("foo", new Instant(0L)),
TimestampedValue.of("bar", new Instant(1L))));
PCollection> reified = timestamped.apply(Reify.timestamps());
PAssert.that(reified)
.containsInAnyOrder(
TimestampedValue.of("foo", new Instant(0)), TimestampedValue.of("bar", new Instant(1)));
pipeline.run();
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void testAddInputSameTimestamp() {
TimestampedValue accum = TimestampedValue.of(100L, INSTANT);
TimestampedValue input = TimestampedValue.of(200L, INSTANT);
assertThat(
"Latest for values with the same timestamp is chosen arbitrarily",
fn.addInput(accum, input),
isOneOf(accum, input));
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(
TimestampedValue.of("foo", new Instant(1000)),
TimestampedValue.of("foo", new Instant(1000)))
.addEqualityGroup(TimestampedValue.of("foo", new Instant(2000)))
.addEqualityGroup(TimestampedValue.of("bar", new Instant(1000)))
.addEqualityGroup(
TimestampedValue.of("foo", BoundedWindow.TIMESTAMP_MIN_VALUE),
TimestampedValue.atMinimumTimestamp("foo"))
.testEquals();
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void testCreateTimestampedDefaultOutputCoderUsingCoder() throws Exception {
Coder coder = new RecordCoder();
Create.TimestampedValues values =
Create.timestamped(
TimestampedValue.of(new Record(), new Instant(0)),
TimestampedValue.of(new Record2(), new Instant(0)))
.withCoder(coder);
assertThat(p.apply(values).getCoder(), equalTo(coder));
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
@Category(NeedsRunner.class)
public void testCreateParameterizedType() throws Exception {
PCollection> output =
p.apply(
Create.of(
TimestampedValue.of("a", new Instant(0)),
TimestampedValue.of("b", new Instant(0))));
PAssert.that(output)
.containsInAnyOrder(
TimestampedValue.of("a", new Instant(0)), TimestampedValue.of("b", new Instant(0)));
p.run();
}
/** An unserializable class to demonstrate encoding of elements. */

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void testNullTimestamp() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("timestamp");
TimestampedValue.of("foobar", null);
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void processTimestampedElement() throws Exception {
try (DoFnTester> tester = DoFnTester.of(new ReifyTimestamps())) {
TimestampedValue input = TimestampedValue.of(1L, new Instant(100));
tester.processTimestampedElement(input);
assertThat(tester.takeOutputElements(), contains(input));
}
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void testCreateTimestampedPolymorphicType() throws Exception {
thrown.expect(RuntimeException.class);
thrown.expectMessage(Matchers.containsString("Unable to infer a coder"));
// Create won't infer a default coder in this case.
PCollection c =
p.apply(
Create.timestamped(
TimestampedValue.of(new Record(), new Instant(0)),
TimestampedValue.of(new Record2(), new Instant(0))));
p.run();
throw new RuntimeException("Coder: " + c.getCoder());
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

/** runs {@link WindowFn#assignWindows(WindowFn.AssignContext)}. */
public static Collection assignedWindows(
WindowFn windowFn, long timestamp) throws Exception {
return assignedWindowsWithValue(
windowFn, TimestampedValue.of((T) null, new Instant(timestamp)));
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
@Category(NeedsRunner.class)
public void testGloballyEventTimestamp() {
PCollection output =
p.apply(
Create.timestamped(
TimestampedValue.of("foo", new Instant(100)),
TimestampedValue.of("bar", new Instant(300)),
TimestampedValue.of("baz", new Instant(200))))
.apply(Latest.globally());
PAssert.that(output).containsInAnyOrder("bar");
p.run();
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void testCoderEncodeDecodeEquals() throws Exception {
CoderProperties.coderDecodeEncodeEqual(
CODER, TimestampedValue.of(GlobalWindow.INSTANCE, Instant.now()));
}

代码示例来源:origin: org.apache.beam/beam-runners-core-java

@Test
public void falseAfterEndOfWindow() throws Exception {
triggerTester.injectElements(TimestampedValue.of(1, new Instant(1)));
IntervalWindow window =
new IntervalWindow(new Instant(0), new Instant(0).plus(Duration.standardMinutes(5)));
assertThat(triggerTester.shouldFire(window), is(false));
triggerTester.advanceInputWatermark(BoundedWindow.TIMESTAMP_MAX_VALUE);
assertThat(triggerTester.shouldFire(window), is(false));
}
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void testCreateTimestampedDefaultOutputCoderUsingTypeDescriptor() throws Exception {
Coder coder = new RecordCoder();
p.getCoderRegistry().registerCoderForClass(Record.class, coder);
Create.TimestampedValues values =
Create.timestamped(
TimestampedValue.of(new Record(), new Instant(0)),
TimestampedValue.of(new Record2(), new Instant(0)))
.withType(new TypeDescriptor() {});
assertThat(p.apply(values).getCoder(), equalTo(coder));
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

/**
* Assigns the given {@code timestamp} to windows using the specified {@code windowFn}, and
* verifies that result of {@code windowFn.getOutputTimestamp} for each window is within the
* proper bound.
*/
public static void validateNonInterferingOutputTimes(
WindowFn windowFn, long timestamp) throws Exception {
validateNonInterferingOutputTimesWithValue(
windowFn, TimestampedValue.of((T) null, new Instant(timestamp)));
}
/**

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
@Category(NeedsRunner.class)
public void testCreateTimestamped() {
List> data =
Arrays.asList(
TimestampedValue.of("a", new Instant(1L)),
TimestampedValue.of("b", new Instant(2L)),
TimestampedValue.of("c", new Instant(3L)));
PCollection output =
p.apply(Create.timestamped(data)).apply(ParDo.of(new PrintTimestamps()));
PAssert.that(output).containsInAnyOrder("a:1", "b:2", "c:3");
p.run();
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void testExtractOutputNullValue() {
TimestampedValue accum = TimestampedValue.of(null, baseTimestamp);
assertEquals(null, fn.extractOutput(accum));
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
public void peekValuesInWindow() throws Exception {
try (DoFnTester tester = DoFnTester.of(new CounterDoFn())) {
tester.startBundle();
tester.processElement(1L);
tester.processElement(2L);
tester.finishBundle();
assertThat(
tester.peekOutputElementsInWindow(GlobalWindow.INSTANCE),
containsInAnyOrder(
TimestampedValue.of("1", new Instant(1000L)),
TimestampedValue.of("2", new Instant(2000L))));
assertThat(
tester.peekOutputElementsInWindow(new IntervalWindow(new Instant(0L), new Instant(10L))),
Matchers.emptyIterable());
}
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

/**
* Assigns the given {@code timestamp} to windows using the specified {@code windowFn}, and
* verifies that result of {@link WindowFn#getOutputTime windowFn.getOutputTime} for later windows
* (as defined by {@code maxTimestamp} won't prevent the watermark from passing the end of earlier
* windows.
*
*

This verifies that overlapping windows don't interfere at all. Depending on the {@code
* windowFn} this may be stricter than desired.
*/
public static void validateGetOutputTimestamp(
WindowFn windowFn, long timestamp) throws Exception {
validateGetOutputTimestampWithValue(
windowFn, TimestampedValue.of((T) null, new Instant(timestamp)));
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Test
@Category(ValidatesRunner.class)
public void testMergingWindowing() {
PCollection input =
p.apply(
Create.timestamped(
TimestampedValue.of("a", new Instant(1)),
TimestampedValue.of("a", new Instant(5)),
TimestampedValue.of("a", new Instant(20))));
PCollection output =
input.apply(new WindowedCount(Sessions.withGapDuration(new Duration(10))));
PAssert.that(output).containsInAnyOrder(output("a", 2, 1, 1, 15), output("a", 1, 20, 20, 30));
p.run();
}

推荐阅读
author-avatar
老爷们白百合开在秋天
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有