[FLINK-40572][runtime] Support dynamic AI model selection - #4525
Merged
Conversation
haruki-830
marked this pull request as ready for review
September 8, 2026 02:16
yuxiqian
reviewed
Sep 9, 2026
yuxiqian
left a comment
Member
There was a problem hiding this comment.
Thanks Haruki for the cleaning-up work, just left some minor comments.
yuxiqian
approved these changes
Sep 9, 2026
yuxiqian
left a comment
Member
There was a problem hiding this comment.
LGTM, just left a follow up note.
| argumentNames.add(paramName); | ||
| argumentClasses.add(AiModelClient.class); | ||
| } | ||
| argumentNames.add(JaninoCompiler.DEFAULT_AI_MODEL_CLIENTS); |
Member
There was a problem hiding this comment.
Not relevant to this PR, but the previous argument declaration & binding implementation is rather weird:
- Projection column/time parameters are declared and bound in
ProjectionColumnProcessor. - Filter column/time parameters are declared and bound in
TransformFilterProcessor. - UDF and AI model parameters are declared in
TransformExpressionCompiler. - Their values are bound separately in
ProjectionColumnProcessorandTransformFilterProcessor.
The order is consistent, but the logic is scattered. Shall we build the complete parameter layout in one shared place and let TransformExpressionCompiler only consume it? This could be done later in a following ticket.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of this pull request?
This PR fixes FLINK-40572 and follows up on the remaining work discussed in #4520.
Previously, the model argument of an AI function had to be a string literal. The parser extracted the model name before execution, and
JaninoCompilerrewrote it to a pre-bound model client variable. As a result, expressions such as columns,IF, andCASEcould not be used to select an AI model dynamically.This PR evaluates the model argument for each record and resolves the selected model at runtime. It allows a pipeline to choose among the models declared in
pipeline.modelbased on record contents.Brief change log
STRINGexpression for every record.IF, andCASEexpressions.JaninoCompiler.Verifying this change
This change added and updated tests and can be verified as follows:
AiFunctionsTestto cover runtime model resolution, missing models, null model names, incompatible capabilities, and null-input short-circuiting.AiFunctionParserTestto cover dynamic model expressions and user-defined function precedence.FlinkPipelineAiFunctionITCaseto verify dynamic model selection in a running pipeline.flink2profile.mvn spotless:check.Documentation
Was generative AI tooling used to co-author this PR?
Generated-by: OpenAI Codex (GPT-5)