Skip to content

Commit a03cb39

Browse files
committed
Fix few bug with the current implemntation
1 parent 35e4a43 commit a03cb39

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PushDownAndCombineLimits.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.xpack.esql.plan.logical.Project;
1919
import org.elasticsearch.xpack.esql.plan.logical.RegexExtract;
2020
import org.elasticsearch.xpack.esql.plan.logical.UnaryPlan;
21+
import org.elasticsearch.xpack.esql.plan.logical.inference.Rerank;
2122
import org.elasticsearch.xpack.esql.plan.logical.join.Join;
2223
import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes;
2324

@@ -52,11 +53,14 @@ public LogicalPlan rule(Limit limit, LogicalOptimizerContext ctx) {
5253
mvx = new MvExpand(mvx.source(), mvx.child(), mvx.target(), mvx.expanded(), limitVal);
5354
}
5455
return mvx.replaceChild(limit.replaceChild(mvx.child()));
55-
}
56-
// check if there's a 'visible' descendant limit lower than the current one
57-
// and if so, align the current limit since it adds no value
58-
// this applies for cases such as | limit 1 | sort field | limit 10
59-
else {
56+
} else if (unary instanceof Rerank) {
57+
Limit descendantLimit = descendantLimit(unary);
58+
if (descendantLimit == null) {
59+
var rerankerDefaultLimit = ctx.configuration().resultTruncationDefaultSize();
60+
var rerankerLimit = new Limit(limit.source(), Literal.of(limit.limit(), rerankerDefaultLimit), unary.child());
61+
return limit.replaceChild(unary.replaceChild(rerankerLimit));
62+
}
63+
} else {
6064
Limit descendantLimit = descendantLimit(unary);
6165
if (descendantLimit != null) {
6266
var l1 = (int) limit.limit().fold(ctx.foldCtx());

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/inference/Rerank.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ public String getWriteableName() {
6868
return ENTRY.name;
6969
}
7070

71-
@Override
72-
public String commandName() {
73-
return "RERANK";
74-
}
75-
7671
@Override
7772
public UnaryPlan replaceChild(LogicalPlan newChild) {
7873
return new Rerank(source(), newChild, inferenceId(), queryText, input);

0 commit comments

Comments
 (0)