yunfengzhou-hub commented on issue #1080:
URL: https://github.com/apache/flink-agents/issues/1080#issuecomment-5842183155
It is a good idea to add a `TypeInformation` parameter to the DataStream and
Table conversion API. But compared with adding a new `AgentOutput`, it might be
better to directly add `TypeInformation` parameter to `toDataStream` and
`toTable` methods. It means the user experience will be as follows
Java:
```java
AgentBuilder builder = agentsEnv.fromDataStream(input,
keySelector).apply(agent);
// Unrestricted Agent output, unchanged.
DataStream<Object> raw = builder.toDataStream();
// Typed terminal: the parameter is the single output-type declaration.
DataStream<ReviewOutput> typed =
builder.toDataStream(TypeInformation.of(ReviewOutput.class));
// For Table, either declaration suffices; the other side is derived.
Table fromType = builder.toTable(TypeInformation.of(ReviewOutput.class));
Table fromSchema = builder.toTable(schema); // row type derived from
physical columns
```
Python:
```python
builder = agents_env.from_datastream(input, key_selector).apply(agent)
raw = builder.to_datastream() # unrestricted
typed = builder.to_datastream(ReviewOutput) # Pydantic model /
dataclass /
# TypedDict / named tuple
-> inferred
table = builder.to_table(schema=review_schema) # or
builder.to_table(ReviewOutput)
```
`to_table` keeps today's argument order (`schema`, `output_type`); both
become optional with exactly one required, and passing both cross-checks them.
The parameter also accepts an explicit `TypeInformation` when inference is
unavailable.
Of the two implementation options the issue lists, the downstream conversion
operator is the better fit: it is the one that preserves the two properties the
issue asks for — the raw Agent operator keeps using Object/serialized bytes,
and heterogeneous output stays available through the raw view. Feeding the type
into the operator before construction would instead make the raw view typed, so
it could reject heterogeneous records whenever a typed terminal was requested.
Happy to take the implementation if this direction works.
--
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]