[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-18。"],[[["\u003cp\u003eApache Beam is an open-source, unified model for defining both batch and streaming pipelines, simplifying large-scale data processing by allowing users to focus on the logic rather than managing parallel processing.\u003c/p\u003e\n"],["\u003cp\u003eApache Beam pipelines consist of \u003ccode\u003ePCollections\u003c/code\u003e (datasets) and \u003ccode\u003ePTransforms\u003c/code\u003e (operations), where \u003ccode\u003ePCollections\u003c/code\u003e can be bounded (fixed size) or unbounded (continuously updating), processed by batch or streaming pipelines, respectively.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eParDo\u003c/code\u003e is a core parallel processing operation, applying a user-defined function to each element in a \u003ccode\u003ePCollection\u003c/code\u003e, and Apache Beam provides I/O connectors to read data from various sources and write to different sinks, including Google Cloud services.\u003c/p\u003e\n"],["\u003cp\u003eWindowing enables grouping operations over unbounded collections by dividing them into finite windows based on timestamps, and watermarks track when all data in a window is expected, managing out-of-order or delayed data.\u003c/p\u003e\n"],["\u003cp\u003eDataflow can run Apache Beam pipelines, by managing the orchestration, deploying code to the necessary resources, and performing optimizations to make pipeline processing efficient.\u003c/p\u003e\n"]]],[],null,["# Programming model for Apache Beam\n\n\u003cbr /\u003e\n\nDataflow is based on the open-source Apache Beam project. This\ndocument describes the Apache Beam programming model.\n\nOverview\n--------\n\nApache Beam is an open source, unified model for defining both batch and\nstreaming pipelines. The Apache Beam programming model simplifies the\nmechanics of large-scale data processing. Using one of the Apache Beam SDKs,\nyou build a program that defines the pipeline. Then, you execute the pipeline\non a specific platform such as Dataflow. This model lets you\nconcentrate on the logical composition of your data processing job, rather than\nmanaging the orchestration of parallel processing.\n\nApache Beam insulates you from the low-level details of distributed\nprocessing, such as coordinating individual workers, sharding datasets, and\nother such tasks. Dataflow fully manages these low-level details.\n\nA *pipeline* is a graph of transformations that are applied to collections of\ndata. In Apache Beam, a collection is called a `PCollection`, and a\ntransform is called a `PTransform`. A `PCollection` can be bounded or unbounded.\nA *bounded* `PCollection` has a known, fixed size, and can be processed using a\nbatch pipeline. Unbounded `PCollections` must use a streaming pipeline, because\nthe data is processed as it arrives.\n\nApache Beam provides connectors to read from and write to different systems,\nincluding Google Cloud services and third-party technologies such as\nApache Kafka.\n\nThe following diagram shows an Apache Beam pipeline.\n\nYou can write `PTransforms` that perform arbitrary logic. The Apache Beam\nSDKs also provide a library of useful `PTransforms` out of the box, including\nthe following:\n\n- Filter out all elements that don't satisfy a predicate.\n- Apply a 1-to-1 mapping function over each element.\n- Group elements by key.\n- Count the elements in a collection\n- Count the elements associated with each key in a key-value collection.\n\nTo run an Apache Beam pipeline using Dataflow, perform the\nfollowing steps:\n\n1. Use the Apache Beam SDK to define and build the pipeline. Alternatively, you can deploy a prebuilt pipeline by using a Dataflow template.\n2. Use Dataflow to run the pipeline. Dataflow allocates a pool of VMs to run the job, deploys the code to the VMs, and orchestrates running the job.\n3. Dataflow performs optimizations on the backend to make your pipeline run efficiently and take advantage of parallelization.\n4. While a job is running and after it completes, use Dataflow management capabilities to monitor progress and troubleshoot.\n\nApache Beam concepts\n--------------------\n\nThis section contains summaries of fundamental concepts.\n\n### Basic concepts\n\nPipelines\n: A pipeline encapsulates the entire series of computations that are involved in\n reading input data, transforming that data, and writing output data. The input\n source and output sink can be the same type or of different types, letting you\n convert data from one format to another. Apache Beam programs start by\n constructing a `Pipeline` object, and then using that object as the basis for\n creating the pipeline's datasets. Each pipeline represents a single, repeatable\n job.\n\nPCollection\n: A `PCollection` represents a potentially distributed, multi-element dataset that\n acts as the pipeline's data. Apache Beam transforms use\n `PCollection` objects as inputs and outputs for each step in your pipeline. A\n `PCollection` can hold a dataset of a fixed size or an unbounded dataset from a\n continuously updating data source.\n\nTransforms\n: A transform represents a processing operation that transforms data. A\n transform takes one or more `PCollection`s as input, performs an operation that\n you specify on each element in that collection, and produces one or more\n `PCollection`s as output. A transform can perform nearly any kind of processing\n operation, including performing mathematical computations on data, converting\n data from one format to another, grouping data together, reading and writing\n data, filtering data to output only the elements you want, or combining data\n elements into single values.\n\nParDo\n: `ParDo` is the core parallel processing operation in the Apache Beam SDKs,\n invoking a user-specified function on each of the elements of the input\n `PCollection`. `ParDo` collects the zero or more output elements into an output\n `PCollection`. The `ParDo` transform processes elements independently and possibly\n in parallel. The user-defined function for a `ParDo` is called a `DoFn`.\n\nPipeline I/O\n: Apache Beam I/O connectors let you read data into your pipeline and\n write output data from your pipeline. An I/O connector consists of a source and\n a sink. All Apache Beam sources and sinks are transforms that let your\n pipeline work with data from several different data storage formats. You can\n also write a custom I/O connector.\n\nAggregation\n: Aggregation is the process of computing some value from multiple input\n elements. The primary computational pattern for aggregation in Apache Beam\n is to group all elements with a common key and window. Then, it combines each\n group of elements using an associative and commutative operation.\n\nUser-defined functions (UDFs)\n: Some operations within Apache Beam allow executing user-defined code as a\n way of configuring the transform. For `ParDo`, user-defined code specifies the\n operation to apply to every element, and for `Combine`, it specifies how values\n should be combined. A pipeline might contain UDFs written in a different\n language than the language of your runner. A pipeline might also contain UDFs\n written in multiple languages.\n\nRunner\n: Runners are the software that accepts a pipeline and executes it. Most runners are\n translators or adapters to massively parallel big-data processing systems.\n Other runners exist for local testing and debugging.\n\nSource\n: A transform that reads from an external storage system. A pipeline typically reads input data from a source. The source has a type, which may be different from the sink type, so you can change the format of data as it moves through the pipeline.\n\nSink\n: A transform that writes to an external data storage system, like a file or a database.\n\nTextIO\n: A PTransform for reading and writing text files. The TextIO source and sink\n support files compressed with `gzip` and `bzip2`. The TextIO input source\n supports JSON. However, for the Dataflow service to be able to\n parallelize input and\n output, your source data must be delimited with a line feed.\n You can use a regular\n expression to target specific files with the TextIO source.\n Dataflow supports general wildcard patterns. Your glob expression\n can appear anywhere in the path. However, Dataflow does not\n support recursive wildcards (`**`).\n\n### Advanced concepts\n\nEvent time\n: The time a data event occurs, determined by the timestamp on the data\n element itself. This contrasts with the time the actual data element\n gets processed at any stage in the pipeline.\n\nWindowing\n: Windowing enables grouping operations over unbounded collections by dividing\n the collection into windows of finite collections according to the timestamps of\n the individual elements. A windowing function tells the runner how to assign\n elements to an initial window, and how to merge windows of grouped elements.\n Apache Beam lets you define different kinds of windows or use the\n predefined windowing functions.\n\nWatermarks\n: Apache Beam tracks a watermark, which is the system's notion of when all\n data in a certain window can be expected to have arrived in the pipeline.\n Apache Beam tracks a watermark because data is not guaranteed to arrive\n in a pipeline in time order or at predictable intervals. In addition, it's not\n guaranteed that data events will appear in the pipeline in the same order\n that they were generated.\n\nTrigger\n: Triggers determine when to emit aggregated results as data arrives. For\n bounded data, results are emitted after all of the input has been processed. For\n unbounded data, results are emitted when the watermark passes the end of the\n window, indicating that the system believes all input data for that window has\n been processed. Apache Beam provides several predefined triggers and lets\n you combine them.\n\nWhat's next\n-----------\n\n- To learn more about the basic concepts of building pipelines using the Apache Beam SDKs, see the [Apache Beam Programming Guide](https://beam.apache.org/documentation/programming-guide/) in the Apache Beam documentation.\n- For more details about the Apache Beam capabilities supported by Dataflow, see the [Apache Beam capability matrix](https://beam.apache.org/documentation/runners/capability-matrix/).\n\n*Apache Beam® is a registered\ntrademark of The Apache Software Foundation or its affiliates in the United\nStates and/or other countries.*"]]