flume结合morphline使用

本文介绍了如何使用Morphline进行数据清洗,并结合Flume将处理后的数据发送到Kafka和HDFS。通过配置morphline.conf文件,实现了数据预处理,最终将清洗后的数据导入到Hive外部表中进行查询。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先来介绍下morphline

Morphlines provides a set of frequently-used high-level transformation and I/O commands that can be combined in application specific ways, as described in the Introduction. The following tables provide a short description of each available command and a link to the complete documentation.
更加具体的可以看官网介绍

这次需求跟上次一样只是中间加一层morphline清洗出更多的数据。
测试使用数据请看上一篇的最后部分

  • morphline.conf
morphlines: [
  {
    id: morphline

    importCommands : ["org.kitesdk.**"]

    commands: [
      {
        readLine {
          charset: UTF-8
        }
      }

      # 解析出字段
      {
        split {
          inputField: message
          outputFields: [date, time, soft, version]
          separator: " "
          isRegex: false
          addEmptyStrings: false
          trim: true
        }
      }
      {
        split {
          inputField: soft
          outputFields: [mes,plat]
          separator: ":"
          isRegex: false
          addEmptyStrings: false
          trim: true
        }
      }
      {
        split {
          inputField: mes
          outputFields: ["",status,name]
          separator: ","
          isRegex: false
          addEmptyStrings: false
          trim: true
        }
      }
      # 将时间戳添加到header中,不加会报找不到timestap
      {
        addValues {
         timestamp: "@{date} @{time}"
        }
      }

    # 格式化上面的时间戳
      {
    convertTimestamp {
      field : timestamp
      inputFormats : ["yyyy-MM-dd HH:mm:ss"]
      outputFormat : unixTimeInMillis
    }

      }

    # 测试使用
      {
    logInfo {
       format : "timestamp: {}, record: {}"
       args : ["@{timestamp}", "@{}"]
    }
      }

    # 将数据转成avro格式,自定义schema
      {
    toAvro {
      schemaFile: /home/training/Desktop/flume-kafka/morphline1/softschema.avsc
    }
      }

    # 指定containlessBinary可以去掉schema头,指定编码解码器
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值