File tree Expand file tree Collapse file tree 3 files changed +16
-6
lines changed
main/java/org/elasticsearch/xpack/esql/parser
test/java/org/elasticsearch/xpack/esql/parser Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 1+ pr : 138363
2+ summary : Fix StringIndexOutOfBoundsException in COMPLETION command when options are omitted.
3+ area : ES|QL
4+ type : bug
5+ issues :
6+ - 138361
Original file line number Diff line number Diff line change @@ -1029,16 +1029,20 @@ public PlanFactory visitCompletionCommand(EsqlBaseParser.CompletionCommandContex
10291029 }
10301030
10311031 private Completion applyCompletionOptions (Completion completion , EsqlBaseParser .CommandNamedParametersContext ctx ) {
1032- MapExpression optionsExpresion = visitCommandNamedParameters (ctx );
1032+ MapExpression optionsExpression = ctx == null ? null : visitCommandNamedParameters (ctx );
10331033
1034- if (optionsExpresion == null || optionsExpresion .containsKey (Completion .INFERENCE_ID_OPTION_NAME ) == false ) {
1034+ if (optionsExpression == null || optionsExpression .containsKey (Completion .INFERENCE_ID_OPTION_NAME ) == false ) {
10351035 // Having a mandatory named parameter for inference_id is an antipattern, but it will be optional in the future when we have a
10361036 // default LLM. It is better to keep inference_id as a named parameter and relax the syntax when it will become optional than
10371037 // completely change the syntax in the future.
1038- throw new ParsingException (source (ctx ), "Missing mandatory option [{}] in COMPLETION" , Completion .INFERENCE_ID_OPTION_NAME );
1038+ throw new ParsingException (
1039+ completion .source (),
1040+ "Missing mandatory option [{}] in COMPLETION" ,
1041+ Completion .INFERENCE_ID_OPTION_NAME
1042+ );
10391043 }
10401044
1041- Map <String , Expression > optionsMap = visitCommandNamedParameters ( ctx ) .keyFoldedMap ();
1045+ Map <String , Expression > optionsMap = optionsExpression .keyFoldedMap ();
10421046
10431047 Expression inferenceId = optionsMap .remove (Completion .INFERENCE_ID_OPTION_NAME );
10441048 if (inferenceId != null ) {
Original file line number Diff line number Diff line change @@ -4111,13 +4111,13 @@ public void testInvalidRerank() {
41114111 }
41124112
41134113 public void testCompletionMissingOptions () {
4114- expectError ("FROM foo* | COMPLETION targetField = prompt" , "line 1:44 : Missing mandatory option [inference_id] in COMPLETION" );
4114+ expectError ("FROM foo* | COMPLETION targetField = prompt" , "line 1:13 : Missing mandatory option [inference_id] in COMPLETION" );
41154115 }
41164116
41174117 public void testCompletionEmptyOptions () {
41184118 expectError (
41194119 "FROM foo* | COMPLETION targetField = prompt WITH { }" ,
4120- "line 1:45 : Missing mandatory option [inference_id] in COMPLETION"
4120+ "line 1:13 : Missing mandatory option [inference_id] in COMPLETION"
41214121 );
41224122 }
41234123
You can’t perform that action at this time.
0 commit comments