@@ -4331,6 +4331,28 @@ public void testFoldableCompletionWithCustomTargetFieldTransformedToEval() {
43314331 assertThat (completionFunction .inferenceId (), equalTo (string ("completion-inference-id" )));
43324332 }
43334333
4334+ public void testFoldableCompletionWithFoldableExpressionTransformedToEval () {
4335+ // Test that a foldable Completion plan with a foldable expression (not just a literal) is transformed correctly
4336+ // Using CONCAT with all literal arguments to ensure it's foldable during analysis
4337+ LogicalPlan plan = analyze ("""
4338+ FROM books METADATA _score
4339+ | COMPLETION CONCAT("Translate", " ", "this text") WITH { "inference_id" : "completion-inference-id" }
4340+ """ , "mapping-books.json" );
4341+
4342+ Eval eval = as (as (plan , Limit .class ).child (), Eval .class );
4343+ assertThat (eval .fields ().size (), equalTo (1 ));
4344+
4345+ Alias alias = eval .fields ().get (0 );
4346+ assertThat (alias .name (), equalTo ("completion" ));
4347+ assertThat (alias .child (), instanceOf (CompletionFunction .class ));
4348+
4349+ CompletionFunction completionFunction = as (alias .child (), CompletionFunction .class );
4350+ // The prompt should be a Concat expression that is foldable (all arguments are literals)
4351+ assertThat (completionFunction .prompt (), instanceOf (Concat .class ));
4352+ assertThat (completionFunction .prompt ().foldable (), equalTo (true ));
4353+ assertThat (completionFunction .inferenceId (), equalTo (string ("completion-inference-id" )));
4354+ }
4355+
43344356 public void testResolveGroupingsBeforeResolvingImplicitReferencesToGroupings () {
43354357 var plan = analyze ("""
43364358 FROM test
0 commit comments