wenjin272 opened a new pull request, #1512:
URL: https://github.com/apache/flink-agents/pull/1512

   Linked issue: #1431
   
   Python output follow-up to #1505.
   
   ### Purpose of change
   
   Python agents with supported explicit Flink output types now emit that type 
directly from the Agent operator. This removes the framework-added 
pickle-decoding map for typed DataStreams and Tables. Untyped outputs, Python 
class declarations, and unsupported Flink types retain their existing 
conversion path.
   
   #### Runtime flow
   
   `RemoteAgentBuilder` checks the declared type in Python and passes supported 
types through `CompileUtils` to the Agent operator. For Tables, it uses the 
physical Row type derived from the schema or output declaration. `EventRouter` 
uses `PythonOutputConverter` to convert the already-decoded Event payload into 
Java values matching that type. Downstream Python operators receive those 
values through PyFlink's input conversion.
   
   #### Key decisions
   
   - Convert the decoded payload in Java to avoid reconstructing it in Python 
and crossing the bridge again.
   - Use one Python compilation entry point. A missing type selects pickle 
output; an explicit byte-array type represents business bytes.
   - Cache one Agent output stream per builder. Type selection is independent 
of `pipeline.generic-types`; this does not remove other runtime dependencies on 
generic serialization.
   
   ### Behavioral Semantics
   
   #### Interaction decisions
   
   | Declaration | DataStream output | Table output |
   | --- | --- | --- |
   | Supported Flink type | Declared type on the Agent operator | Derived 
physical Row type on the Agent operator |
   | Python structured class | Existing instance reconstruction | Derived 
physical Row type, using direct conversion when supported |
   | Unsupported Flink type | Existing pickle/decode map | Existing Row 
conversion map |
   | No type | Existing unrestricted output | Schema required; follows the 
schema-derived Row type |
   
   Supported direct types include basic numbers, booleans, strings, byte 
arrays, Rows, Tuples, and recursively supported collections. Map keys must be 
supported scalar types. Temporal/decimal types and composite map keys use the 
existing path.
   
   #### Behavioral contracts
   
   - Supported typed output reaches downstream operators without a 
framework-added decode map, including after serialization and before a Python 
UDF.
   - Explicit byte-array output contains the payload bytes, rather than pickled 
output.
   - Untyped, Python-class, and unsupported-type declarations retain their 
output behavior.
   - Calls selecting the same Agent output type reuse the operator. A 
conflicting type on the same builder raises `ValueError`; separate builders or 
downstream conversion provide different views.
   - Row fields are projected by name where available. Nested collections 
contain independent converted values; converting another record does not mutate 
earlier results.
   - Invalid scalar values, integer overflow, and incorrect positional 
Row/Tuple arity fail conversion instead of silently truncating values.
   
   #### Failure behavior
   
   Unsupported declarations select the existing conversion path during graph 
construction. Once direct conversion is selected, invalid payloads raise an 
output-extraction `IllegalStateException` with the conversion error as its 
cause; there is no automatic fallback or converter-level retry. Existing Table 
schema/type validation remains in place. No external service interaction is 
introduced.
   
   ### Tests
   
   `git diff --check` passed. **The current revision has not been compiled or 
tested; test execution was deferred at the maintainer's request.** The 
following tests are included, not reported as passing:
   
   | Contract | Tests |
   | --- | --- |
   | Direct typed output, serialized records, and downstream Python UDFs | 
`test_typed_agent_output_without_decode_map`; 
`pythonOutputDeclarationSetsOperatorTypeAndUid` |
   | Explicit bytes differ from pickle output | 
`test_explicit_bytes_output_passes_type_instead_of_pickle_default`; 
`explicitByteOutputUsesTypedConversionInsteadOfPickle`; 
`restoresUtf8BytesAndAcceptsNativeJavaBytes` |
   | Existing paths remain available | 
`test_to_datastream_raw_view_is_untyped`; 
`test_to_datastream_structured_model_yields_instances`; 
`test_to_datastream_unsupported_bridge_types_keep_decode_map` |
   | Builder type conflicts and reuse | 
`test_to_datastream_rejects_conflicting_output_types`; 
`test_multiple_typed_datastreams_of_different_types_coexist` |
   | Row projection and independent nested values | 
`restoresRowFieldsByNameAndConvertsNumbers`; `restoresPythonRowJsonEncoding`; 
`collectionsHaveIndependentRowsAndTuples`; 
`repeatedConversionsDoNotMutateEarlierResults` |
   | Invalid values fail conversion | 
`rejectsOutOfRangeIntegersWithoutTruncation`; `rejectsWrongValuesAndArity` |
   
   Coverage targets type selection, JSON payload conversion, and the actual 
cross-language output boundary. Compilation, execution of these tests, the 
supported Flink-version matrix, and checkpoint/savepoint restore with the 
changed graph remain unverified. No performance benchmark is included.
   
   ### API
   
   Public Python terminal signatures remain unchanged. Existing callers 
requesting different Agent output types from one builder can now receive 
`ValueError` and must use separate builders or downstream conversions. Untyped 
and Python-class DataStream outputs keep their existing behavior; the Java 
terminal behavior introduced by #1505 remains unchanged.
   
   The internal Python `CompileUtils.connectToAgent` entry point now takes a 
nullable output type. Direct typed output changes the stream graph and 
serializer selection; this PR provides no migration guarantee for existing job 
snapshots.
   
   ### Documentation
   
   - [ ] `doc-needed`
   - [ ] `doc-not-needed`
   - [x] `doc-included`
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   - [x] Yes
   - [ ] No
   
   Generated-by: Codex CLI 0.153.4 (GPT-6)
   


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