【问题标题】:google cloud dataflow - can I get "event-time" from meta-data?谷歌云数据流 - 我可以从元数据中获取“事件时间”吗?
【发布时间】:2016-06-30 00:40:09
【问题描述】:

问候开发者,

我知道数据流(DF)可以从 I/O(如 Pubsub)获取事件时间,我也可以将“事件时间”分配给数据。但是,我可以从数据中获取这个属性值吗?

据我了解,我可以从数据中获取输入时间戳(处理时间),但不能获取事件时间。

Q1:我可以从数据中获取事件时间吗?

Q2:如果可以,如何获得?

感谢您的帮助:D

【问题讨论】:

    标签: google-cloud-dataflow


    【解决方案1】:

    要获取 DoFn 中元素的时间戳,您可以调用 ProcessContext.timestamp()。要根据自己的应用逻辑设置元素的时间戳,可以使用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));
    }
    

    【讨论】:

    • 我知道如何为数据分配时间戳,以及如何从数据中获取“输入时间”(处理时间)。但我想问的问题是如何从数据中获取“事件时间”?
    • 是的,您可以为此使用 ProcessContext.timestamp()。除非我误解了你的问题?
    • c.timestamp() 返回分配给当前元素的时间戳(在事件时间中)。在源(例如 PubSub),这是从消息中的时间戳属性分配的,或者基于该输入的到达时间(其他源可能具有其他语义)。在管道中,您可以使用 outputWithTimestamp 更改分配给元素的时间戳。如果您不使用outputWithTimestamp,源分配的时间戳会传播。如果这不能澄清,您能否通过示例或更多详细信息详细说明您的问题?
    • 最近,我发现 ProcessContext.timestamp() 代表事件时间,我认为是之前的处理时间。为了您的帮助,我知道 ProcessContext.timestamp() 可以得到我想要的结果。感谢您的帮助:D
    猜你喜欢
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多