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 @@ -1157,16 +1157,20 @@ public PlanFactory visitCompletionCommand(EsqlBaseParser.CompletionCommandContex
11571157 }
11581158
11591159 private Completion applyCompletionOptions (Completion completion , EsqlBaseParser .CommandNamedParametersContext ctx ) {
1160- MapExpression optionsExpresion = visitCommandNamedParameters (ctx );
1160+ MapExpression optionsExpression = ctx == null ? null : visitCommandNamedParameters (ctx );
11611161
1162- if (optionsExpresion == null || optionsExpresion .containsKey (Completion .INFERENCE_ID_OPTION_NAME ) == false ) {
1162+ if (optionsExpression == null || optionsExpression .containsKey (Completion .INFERENCE_ID_OPTION_NAME ) == false ) {
11631163 // Having a mandatory named parameter for inference_id is an antipattern, but it will be optional in the future when we have a
11641164 // default LLM. It is better to keep inference_id as a named parameter and relax the syntax when it will become optional than
11651165 // completely change the syntax in the future.
1166- throw new ParsingException (source (ctx ), "Missing mandatory option [{}] in COMPLETION" , Completion .INFERENCE_ID_OPTION_NAME );
1166+ throw new ParsingException (
1167+ completion .source (),
1168+ "Missing mandatory option [{}] in COMPLETION" ,
1169+ Completion .INFERENCE_ID_OPTION_NAME
1170+ );
11671171 }
11681172
1169- Map <String , Expression > optionsMap = visitCommandNamedParameters ( ctx ) .keyFoldedMap ();
1173+ Map <String , Expression > optionsMap = optionsExpression .keyFoldedMap ();
11701174
11711175 Expression inferenceId = optionsMap .remove (Completion .INFERENCE_ID_OPTION_NAME );
11721176 if (inferenceId != null ) {
Original file line number Diff line number Diff line change @@ -4233,13 +4233,13 @@ public void testInvalidRerank() {
42334233 }
42344234
42354235 public void testCompletionMissingOptions () {
4236- expectError ("FROM foo* | COMPLETION targetField = prompt" , "line 1:44 : Missing mandatory option [inference_id] in COMPLETION" );
4236+ expectError ("FROM foo* | COMPLETION targetField = prompt" , "line 1:13 : Missing mandatory option [inference_id] in COMPLETION" );
42374237 }
42384238
42394239 public void testCompletionEmptyOptions () {
42404240 expectError (
42414241 "FROM foo* | COMPLETION targetField = prompt WITH { }" ,
4242- "line 1:45 : Missing mandatory option [inference_id] in COMPLETION"
4242+ "line 1:13 : Missing mandatory option [inference_id] in COMPLETION"
42434243 );
42444244 }
42454245
You can’t perform that action at this time.
0 commit comments