Skip to content

Commit 182300b

Browse files
committed
restore
1 parent 8e8a0a8 commit 182300b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/SingletonOrdinalsBuilderTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131

3232
import java.io.IOException;
3333
import java.util.ArrayList;
34+
import java.util.Arrays;
3435
import java.util.HashMap;
3536
import java.util.List;
3637
import java.util.Map;
3738

39+
import static org.elasticsearch.test.ListMatcher.matchesList;
3840
import static org.elasticsearch.test.MapMatcher.assertMap;
3941
import static org.elasticsearch.test.MapMatcher.matchesMap;
4042
import static org.hamcrest.Matchers.equalTo;
@@ -89,6 +91,27 @@ private void testRead(BlockFactory factory) throws IOException {
8991
}
9092
}
9193

94+
public void testCompactWithNulls() {
95+
assertCompactToUnique(new int[] { -1, -1, -1, -1, 0, 1, 2 }, List.of(0, 1, 2));
96+
}
97+
98+
public void testCompactNoNulls() {
99+
assertCompactToUnique(new int[] { 0, 1, 2 }, List.of(0, 1, 2));
100+
}
101+
102+
public void testCompactDups() {
103+
assertCompactToUnique(new int[] { 0, 0, 0, 1, 2 }, List.of(0, 1, 2));
104+
}
105+
106+
public void testCompactSkips() {
107+
assertCompactToUnique(new int[] { 2, 7, 1000 }, List.of(2, 7, 1000));
108+
}
109+
110+
private void assertCompactToUnique(int[] sortedOrds, List<Integer> expected) {
111+
int uniqueLength = SingletonOrdinalsBuilder.compactToUnique(sortedOrds);
112+
assertMap(Arrays.stream(sortedOrds).mapToObj(Integer::valueOf).limit(uniqueLength).toList(), matchesList(expected));
113+
}
114+
92115
private final List<CircuitBreaker> breakers = new ArrayList<>();
93116
private final List<BlockFactory> blockFactories = new ArrayList<>();
94117

0 commit comments

Comments
 (0)