【问题标题】:Escape Sequences not populating hdfs path and file prefix转义序列不填充 hdfs 路径和文件前缀
【发布时间】:2022-01-10 06:46:24
【问题描述】:

在我的水槽流中,我想要一个自定义的动态 hdfs 路径,但没有数据被填充到拦截器中。

示例数据: 188 17 2016-06-01 00:31:10 6200.041736 0

配置

agent2.sources.source2.interceptors = i2 i3 i4
agent2.sources.source2.interceptors.i2.type = regex_extractor
agent2.sources.source2.interceptors.i3.type = regex_extractor
agent2.sources.source2.interceptors.i4.type = regex_extractor
# regex to pick up the year
agent2.sources.source2.interceptors.i2.regex = (?<=\t)[0-9]{4}(?=-)
agent2.sources.source2.interceptors.i2.serializers = y
agent2.sources.source2.interceptors.i2.serializers.y.name = year
# regex to pick up the month
agent2.sources.source2.interceptors.i3.regex = (?<=-)[0-9]{2}(?=-)
agent2.sources.source2.interceptors.i3.serializers = m
agent2.sources.source2.interceptors.i3.serializers.m.name = month
# regex to pick up the day
agent2.sources.source2.interceptors.i4.regex = (?<=-)[0-9]{2}(?=\t)
agent2.sources.source2.interceptors.i4.serializers = d
agent2.sources.source2.interceptors.i4.serializers.d.name = day
# Define the HDFS sink 2 –year and month
agent2.sinks.sink-hdfs2.type = hdfs
agent2.sinks.sink-hdfs2.hdfs.path = /group-project/consumption/%{year}/%{month}
agent2.sinks.sink-hdfs2.hdfs.filePrefix = %{year}-%{month}
agent2.sinks.sink-hdfs2.hdfs.fileSuffix = .txt

【问题讨论】:

    标签: hadoop hdfs flume flume-ng


    【解决方案1】:

    年份和日期的前瞻和后瞻将仅匹配制表符。它们不会匹配多个空格。你最好使用\\s

    Flume 还需要两个反斜杠作为正则表达式符号,\\t 而不是 \t

    或者,您可以使用一个正则表达式来获取整个日期,并使用多个捕获组将它们分配给不同的序列化程序。例如(\\d{4})-(\\d{2})-(\\d{2})

    Flume User Guide 有一个很好的例子:

    如果 Flume 事件体包含 1:2:3.4foobar5 并且使用了以下配置

    a1.sources.r1.interceptors.i1.regex = (\\d):(\\d):(\\d)
    a1.sources.r1.interceptors.i1.serializers = s1 s2 s3
    a1.sources.r1.interceptors.i1.serializers.s1.name = one
    a1.sources.r1.interceptors.i1.serializers.s2.name = two
    a1.sources.r1.interceptors.i1.serializers.s3.name = three
    

    提取的事件将包含相同的正文,但将添加以下标头one=&gt;1, two=&gt;2, three=&gt;3

    【讨论】:

      猜你喜欢
      • 2014-05-27
      • 1970-01-01
      • 2015-05-13
      • 2019-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      相关资源
      最近更新 更多