forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESQL: Port TopN to NamedWriteable (elastic#111466)
This ports `TopN` to `NamedWriteable` to line up with the rest of ESQL. It also moves most references of `esql.core.expression.Order` to `esql.expression.Order` to make serialization line up a little better. We will compress those two classes into one soon.
- Loading branch information
Showing
15 changed files
with
102 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../esql/src/test/java/org/elasticsearch/xpack/esql/plan/logical/TopNSerializationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.esql.plan.logical; | ||
|
||
import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
import org.elasticsearch.xpack.esql.core.tree.Source; | ||
import org.elasticsearch.xpack.esql.expression.AbstractExpressionSerializationTests; | ||
import org.elasticsearch.xpack.esql.expression.Order; | ||
import org.elasticsearch.xpack.esql.expression.OrderSerializationTests; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class TopNSerializationTests extends AbstractLogicalPlanSerializationTests<TopN> { | ||
public static TopN randomTopN(int depth) { | ||
Source source = randomSource(); | ||
LogicalPlan child = randomChild(depth); | ||
List<Order> order = randomOrders(); | ||
Expression limit = AbstractExpressionSerializationTests.randomChild(); | ||
return new TopN(source, child, order, limit); | ||
} | ||
|
||
private static List<Order> randomOrders() { | ||
return randomList(1, 10, OrderSerializationTests::randomOrder); | ||
} | ||
|
||
@Override | ||
protected TopN createTestInstance() { | ||
return randomTopN(0); | ||
} | ||
|
||
@Override | ||
protected TopN mutateInstance(TopN instance) throws IOException { | ||
Source source = instance.source(); | ||
LogicalPlan child = instance.child(); | ||
List<Order> order = instance.order(); | ||
Expression limit = instance.limit(); | ||
switch (between(0, 2)) { | ||
case 0 -> child = randomValueOtherThan(child, () -> randomChild(0)); | ||
case 1 -> order = randomValueOtherThan(order, TopNSerializationTests::randomOrders); | ||
case 2 -> limit = randomValueOtherThan(limit, AbstractExpressionSerializationTests::randomChild); | ||
} | ||
return new TopN(source, child, order, limit); | ||
} | ||
|
||
@Override | ||
protected boolean alwaysEmptySource() { | ||
return true; | ||
} | ||
} |