Abacn commented on code in PR #37937: URL: https://github.com/apache/beam/pull/37937#discussion_r3168815620
########## .agent/skills/beam-dofn-modernizer/SKILL.md: ########## @@ -0,0 +1,207 @@ +--- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +--- +name: beam-dofn-modernizer +description: Rewrite Apache Beam DoFn methods (@ProcessElement, @OnTimer, @OnWindowExpiration) to remove legacy ProcessContext or OnTimerContext usage. Use this skill when you encounter DoFn methods that use context.element(), context.output(), etc., and need to modernize them using parameter injection (@Element, @Timestamp, @Pane, OutputReceiver, MultiOutputReceiver). +--- + +# Modernizing Apache Beam DoFns + +Apache Beam has moved towards parameter injection in `DoFn` methods to improve readability and allow for more efficient execution. This skill helps you migrate legacy `ProcessContext` and `OnTimerContext` usage to modern annotated parameters. + +## Core Mappings + +When rewriting a `@ProcessElement` or `@OnTimer` method, replace the context argument with the corresponding parameters based on the usage: + +| Legacy Context Usage (e.g. `ProcessContext c`) | Modern Parameter Replacement | +| :--- | :--- | +| `c.element()` | `@Element T element` | +| `c.timestamp()` | `@Timestamp Instant timestamp` | +| `c.pane()` | `PaneInfo pane` | +| `c.window()` | `BoundedWindow window` | +| `c.sideInput(PCollectionView<T> view)` | `@SideInput("viewName") T value` | +| `c.getPipelineOptions()` | `PipelineOptions options` | +| `c.output(value)` | `OutputReceiver<T> receiver` then `receiver.output(value)` | +| `c.output(tag, value)` | `MultiOutputReceiver receiver` then `receiver.get(tag).output(value)` | +| `c.outputWithTimestamp(value, ts)` | `OutputReceiver<T> receiver` then `receiver.outputWithTimestamp(value, ts)` | + +## Method Signature Changes + +### @ProcessElement + +**Legacy:** +```java +@ProcessElement +public void processElement(ProcessContext c) { + T element = c.element(); + c.output(transform(element)); +} +``` + +**Modern:** Review Comment: From diff "+1,062 -547" arguably the "modern" API is way more verbose than the "legacy" one -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
