nzw921rx commented on issue #10942:
URL: https://github.com/apache/seatunnel/issues/10942#issuecomment-4534380362

   > Here is a reference
   > 
   > ```
   > public class SeaTunnelTransformCollector implements Collector<Record<?>> {
   > 
   >     private final List<OneInputFlowLifeCycle<Record<?>>> outputs;
   >     // Cached at construction; outputs list is fixed for the lifetime of 
this collector.
   >     private final boolean fanOut;
   > 
   >     public 
SeaTunnelTransformCollector(List<OneInputFlowLifeCycle<Record<?>>> outputs) {
   >         this.outputs = outputs;
   >         this.fanOut = outputs.size() > 1;
   >     }
   > 
   >     @Override
   >     public void collect(Record<?> record) {
   >         if (!fanOut) {
   >             // Fast path: single downstream, no copy, no loop overhead.
   >             if (!outputs.isEmpty()) {
   >                 try {
   >                     outputs.get(0).received(record);
   >                 } catch (IOException e) {
   >                     throw new TaskRuntimeException(e);
   >                 }
   >             }
   >             return;
   >         }
   >         // Fan-out path: each branch gets its own row copy to prevent 
cross-branch mutation.
   >         for (OneInputFlowLifeCycle<Record<?>> output : outputs) {
   >             try {
   >                 output.received(copyRecord(record));
   >             } catch (IOException e) {
   >                 throw new TaskRuntimeException(e);
   >             }
   >         }
   >     }
   > 
   >     private static Record<?> copyRecord(Record<?> record) {
   >         Object data = record.getData();
   >         if (data instanceof SeaTunnelRow) {
   >             return new Record<>(((SeaTunnelRow) data).copy());
   >         }
   >         // Barrier and SchemaChangeEvent are immutable coordination 
objects; no copy needed.
   >         return record;
   >     }
   > 
   >     @Override
   >     public void close() {}
   > }
   > ```
   
   @davidzollo This is a good idea. At present, the redundant copy operations 
in the `transform` layer should be removed together, and it does not involve 
compatibility issues with user-defined plugins
   
   


-- 
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]

Reply via email to