Giter Club home page Giter Club logo

pipeline's Introduction

pipeline

pipeline 处理数据

本次的处理中: PCollection 类表示输入数据集合。 ParDo 算子来模拟生成一个随机温度的输入数据集合。 Window 类来将数据分为 1 分钟、5 分钟和 15 分钟的时间窗口。 Combine 算子来求出每个时间窗口内的 max、min 和 avg 温度值。 Filter 算子来找到超过随机温度范围的异常点。 Write 算子来将统计结果写入到指定的输出位置,例如文件或数据库。 ##代码说明 PCollection input = pipeline.apply(TextIO.read().from("input.txt"));//读取输入文件; 需要重新写一个输入的类 在上面的代码中通过缓存写入input。

运行过程

使用了 Apache Beam 的 TextIO 类来读取输入文件, 并使用 ParDo 算子来解析输入数据,使用 WithTimestamps 算子来为数据分配时间戳, 使用 Window 类来将数据分为 1 分钟、5 分钟和 15 分钟的时间窗口,使用 Combine 算子来计算统计信息,使用 Filter 算子来找到异常点,并使用 TextIO 类来将统计结果写入到输出文件中。 StatisticsFn 的 CombineFn 类,这个类用于计算 1 分钟、5 分钟和 15 分钟时间窗口内的统计信息。 Statistics 的类来存储统计信息,包括最小值、最大值、和值和数据个数。 pipeline.run() 方法来运行整个管道。

运行结果

输入文件 1582345678901,23.5 1582345688901,24.5 1582345698901,25.5 1582345708901,26.5 1582345718901,27.5 输出文件 1 minute, 1582345678901, 23.5, 23.5, 23.5 1 minute, 1582345688901, 24.5, 24.5, 24.5 1 minute, 1582345698901, 25.5, 25.5, 25.5 1 minute, 1582345708901, 26.5, 26.5, 26.5 1 minute, 1582345718901, 27.5, 27.5, 27.5 5 minutes, 1582345688901, 27.5, 23.5, 25.5 15 minutes, 1582345688901, 27.5, 23.5, 25.5 异常店文件 1582345758901,120.5 1582345768901,110.5 1582345778901,130.5

配置

可以将代码打包 java -jar temperature-statistics.jar --inputFile=input.txt --outputDirectory=output --runner=DirectRunner 可以使用 Apache Beam 提供的其他运行器,例如 DataflowRunner 或 SparkRunner,以在云环境中运行程序。

pipeline's People

Contributors

ssh022-s avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.