google 云数据流 - 我可以从元数据中获取 "event-time" 吗?
google cloud dataflow - can I get "event-time" from meta-data?
问候开发者,
我知道数据流 (DF) 可以从 I/O(如 Pubsub)获取事件时间,我也可以将 "event-time" 分配给数据。但是,我可以从数据中获取这个属性值吗?
据我了解,我可以从数据中获取输入时间戳(处理时间),但不能从事件时间中获取。
Q1:我可以从数据中获取事件时间吗?
Q2:如果可以,如何获取?
感谢您的帮助 :D
要获取 DoFn 中元素的时间戳,您可以调用 ProcessContext.timestamp(). To set the timestamp of an element according to your own application logic, you can use Context.outputWithTimestamp().
像这样:
@Override
public void processElement(ProcessContext c) {
// Generate a timestamp that falls somewhere in two hours after the event time.
long randMillis = (long) (Math.random() * Duration.standardHours(2).getMillis());
Instant randomTimestamp = c.timestamp().plus(randMillis);
c.outputWithTimestamp(c.element(), new Instant(randomTimestamp));
}
问候开发者,
我知道数据流 (DF) 可以从 I/O(如 Pubsub)获取事件时间,我也可以将 "event-time" 分配给数据。但是,我可以从数据中获取这个属性值吗?
据我了解,我可以从数据中获取输入时间戳(处理时间),但不能从事件时间中获取。
Q1:我可以从数据中获取事件时间吗?
Q2:如果可以,如何获取?
感谢您的帮助 :D
要获取 DoFn 中元素的时间戳,您可以调用 ProcessContext.timestamp(). To set the timestamp of an element according to your own application logic, you can use Context.outputWithTimestamp().
像这样:
@Override
public void processElement(ProcessContext c) {
// Generate a timestamp that falls somewhere in two hours after the event time.
long randMillis = (long) (Math.random() * Duration.standardHours(2).getMillis());
Instant randomTimestamp = c.timestamp().plus(randMillis);
c.outputWithTimestamp(c.element(), new Instant(randomTimestamp));
}