Skip to content

Commit 35120e6

Browse files
committed
Support default parameters when not specified
1 parent ccda43d commit 35120e6

File tree

1 file changed

+22
-3
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string

1 file changed

+22
-3
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ExtractSnippets.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper;
3434
import org.elasticsearch.xpack.esql.expression.function.Example;
3535
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
36-
import org.elasticsearch.xpack.esql.expression.function.OptionalArgument;
3736
import org.elasticsearch.xpack.esql.expression.function.Param;
37+
import org.elasticsearch.xpack.esql.expression.function.TwoOptionalArguments;
3838
import org.elasticsearch.xpack.esql.expression.function.scalar.EsqlScalarFunction;
3939
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
4040
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
@@ -44,6 +44,7 @@
4444
import org.elasticsearch.xpack.esql.querydsl.query.TranslationAwareExpressionQuery;
4545

4646
import java.io.IOException;
47+
import java.util.ArrayList;
4748
import java.util.List;
4849
import java.util.Map;
4950
import java.util.Objects;
@@ -60,7 +61,12 @@
6061
/**
6162
* Extract snippets function, that extracts the most relevant snippets from a given input string
6263
*/
63-
public class ExtractSnippets extends EsqlScalarFunction implements OptionalArgument, RewriteableAware, TranslationAware, EvaluatorMapper {
64+
public class ExtractSnippets extends EsqlScalarFunction
65+
implements
66+
TwoOptionalArguments,
67+
RewriteableAware,
68+
TranslationAware,
69+
EvaluatorMapper {
6470
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
6571
Expression.class,
6672
"ExtractSnippets",
@@ -108,7 +114,7 @@ public ExtractSnippets(
108114
Expression snippetLength,
109115
QueryBuilder queryBuilder
110116
) {
111-
super(source, List.of(field, str, numSnippets, snippetLength));
117+
super(source, fields(field, str, numSnippets, snippetLength));
112118
this.field = field;
113119
this.str = str;
114120
this.numSnippets = numSnippets;
@@ -331,4 +337,17 @@ public boolean equals(Object o) {
331337
public int hashCode() {
332338
return Objects.hash(field(), str(), numSnippets(), snippetLength(), queryBuilder());
333339
}
340+
341+
private static List<Expression> fields(Expression field, Expression str, Expression numSnippets, Expression snippetLength) {
342+
List<Expression> list = new ArrayList<>(4);
343+
list.add(field);
344+
list.add(str);
345+
if (numSnippets != null) {
346+
list.add(numSnippets);
347+
if (snippetLength != null) {
348+
list.add(snippetLength);
349+
}
350+
}
351+
return list;
352+
}
334353
}

0 commit comments

Comments
 (0)