Skip to content

Commit 7333fcf

Browse files
committed
Add sorting
1 parent f1eb1b2 commit 7333fcf

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ private PhysicalOperation planMvExpand(MvExpandExec mvExpandExec, LocalExecution
703703
}
704704

705705
private PhysicalOperation planChangePoint(ChangePointExec changePoint, LocalExecutionPlannerContext context) {
706+
// TODO: should this be planned locally?
706707
PhysicalOperation source = plan(changePoint.child(), context);
707708
Layout layout = source.layout.builder()
708709
.append(changePoint.targetType())

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/mapper/LocalMapper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
import org.elasticsearch.index.IndexMode;
1212
import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException;
1313
import org.elasticsearch.xpack.esql.core.expression.Attribute;
14+
import org.elasticsearch.xpack.esql.core.expression.Literal;
15+
import org.elasticsearch.xpack.esql.core.tree.Source;
16+
import org.elasticsearch.xpack.esql.core.type.DataType;
17+
import org.elasticsearch.xpack.esql.expression.Order;
1418
import org.elasticsearch.xpack.esql.plan.logical.Aggregate;
1519
import org.elasticsearch.xpack.esql.plan.logical.BinaryPlan;
1620
import org.elasticsearch.xpack.esql.plan.logical.ChangePoint;
@@ -92,6 +96,11 @@ private PhysicalPlan mapUnary(UnaryPlan unary) {
9296
}
9397

9498
if (unary instanceof ChangePoint changePoint) {
99+
// TODO: ChangePoint shouldn't run on the local node
100+
// TODO: fix hardcoded 1000
101+
mappedChild = new TopNExec(changePoint.source(), mappedChild,
102+
List.of(new Order(changePoint.source(), changePoint.key(), Order.OrderDirection.ASC, Order.NullsPosition.ANY)),
103+
new Literal(Source.EMPTY, 1000, DataType.INTEGER), null);
95104
return new ChangePointExec(
96105
changePoint.source(),
97106
mappedChild,

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/mapper/Mapper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
import org.elasticsearch.index.IndexMode;
1212
import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException;
1313
import org.elasticsearch.xpack.esql.core.expression.Attribute;
14+
import org.elasticsearch.xpack.esql.core.expression.Literal;
15+
import org.elasticsearch.xpack.esql.core.tree.Source;
16+
import org.elasticsearch.xpack.esql.core.type.DataType;
1417
import org.elasticsearch.xpack.esql.core.util.Holder;
18+
import org.elasticsearch.xpack.esql.expression.Order;
1519
import org.elasticsearch.xpack.esql.plan.logical.Aggregate;
1620
import org.elasticsearch.xpack.esql.plan.logical.BinaryPlan;
1721
import org.elasticsearch.xpack.esql.plan.logical.ChangePoint;
@@ -175,6 +179,9 @@ private PhysicalPlan mapUnary(UnaryPlan unary) {
175179

176180
if (unary instanceof ChangePoint changePoint) {
177181
mappedChild = addExchangeForFragment(changePoint, mappedChild);
182+
mappedChild = new TopNExec(changePoint.source(), mappedChild,
183+
List.of(new Order(changePoint.source(), changePoint.key(), Order.OrderDirection.ASC, Order.NullsPosition.ANY)),
184+
new Literal(Source.EMPTY, 1000, DataType.INTEGER), null);
178185
return new ChangePointExec(
179186
changePoint.source(),
180187
mappedChild,

0 commit comments

Comments
 (0)