Skip to content

Commit d368a4e

Browse files
Merge branch 'main' into fix123425
2 parents 6cf4752 + 5447909 commit d368a4e

File tree

58 files changed

+638
-94
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+638
-94
lines changed

docs/changelog/125479.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 125479
2+
summary: ES|QL - Allow full text functions to be used in STATS
3+
area: ES|QL
4+
type: enhancement
5+
issues:
6+
- 125481

docs/changelog/127949.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 127949
2+
summary: Ensure ordinal builder emit ordinal blocks
3+
area: ES|QL
4+
type: bug
5+
issues: []

muted-tests.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,6 @@ tests:
423423
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
424424
method: test {p0=search/350_point_in_time/point-in-time with index filter}
425425
issue: https://github.com/elastic/elasticsearch/issues/127741
426-
- class: org.elasticsearch.compute.aggregation.FilteredGroupingAggregatorFunctionTests
427-
method: testSimpleCircuitBreaking
428-
issue: https://github.com/elastic/elasticsearch/issues/127833
429426
- class: org.elasticsearch.packaging.test.DockerTests
430427
method: test025SyncPluginsUsingProxy
431428
issue: https://github.com/elastic/elasticsearch/issues/127138
@@ -453,9 +450,6 @@ tests:
453450
- class: org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDeciderIT
454451
method: testRestoreSnapshotAllocationDoesNotExceedWatermarkWithMultipleRestores
455452
issue: https://github.com/elastic/elasticsearch/issues/127787
456-
- class: org.elasticsearch.xpack.esql.action.CrossClusterQueryWithFiltersIT
457-
method: testTimestampFilterFromQuery
458-
issue: https://github.com/elastic/elasticsearch/issues/127332
459453
- class: org.elasticsearch.indices.stats.IndexStatsIT
460454
method: testThrottleStats
461455
issue: https://github.com/elastic/elasticsearch/issues/126359
@@ -465,6 +459,9 @@ tests:
465459
- class: org.elasticsearch.search.vectors.IVFKnnFloatVectorQueryTests
466460
method: testSearchBoost
467461
issue: https://github.com/elastic/elasticsearch/issues/127969
462+
- class: org.elasticsearch.packaging.test.DockerTests
463+
method: test040JavaUsesTheOsProvidedKeystore
464+
issue: https://github.com/elastic/elasticsearch/issues/127437
468465

469466
# Examples:
470467
#

x-pack/plugin/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ tasks.named("yamlRestCompatTestTransform").configure({ task ->
9595
task.skipTest("esql/61_enrich_ip/Invalid IP strings", "We switched from exceptions to null+warnings for ENRICH runtime errors")
9696
task.skipTest("esql/180_match_operator/match with non text field", "Match operator can now be used on non-text fields")
9797
task.skipTest("esql/180_match_operator/match with functions", "Error message changed")
98+
task.skipTest("esql/180_match_operator/match within eval", "Error message changed")
9899
task.skipTest("esql/40_unsupported_types/semantic_text declared in mapping", "The semantic text field format changed")
99100
task.skipTest("esql/190_lookup_join/Alias as lookup index", "LOOKUP JOIN does not support index aliases for now")
100101
task.skipTest("esql/190_lookup_join/alias-repeated-alias", "LOOKUP JOIN does not support index aliases for now")

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/SingletonOrdinalsBuilder.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
public class SingletonOrdinalsBuilder implements BlockLoader.SingletonOrdinalsBuilder, Releasable, Block.Builder {
2323
private final BlockFactory blockFactory;
2424
private final SortedDocValues docValues;
25+
private int minOrd = Integer.MAX_VALUE;
26+
private int maxOrd = Integer.MIN_VALUE;
2527
private final int[] ords;
2628
private int count;
2729

@@ -39,8 +41,10 @@ public SingletonOrdinalsBuilder appendNull() {
3941
}
4042

4143
@Override
42-
public SingletonOrdinalsBuilder appendOrd(int value) {
43-
ords[count++] = value;
44+
public SingletonOrdinalsBuilder appendOrd(int ord) {
45+
ords[count++] = ord;
46+
minOrd = Math.min(minOrd, ord);
47+
maxOrd = Math.max(maxOrd, ord);
4448
return this;
4549
}
4650

@@ -55,7 +59,7 @@ public SingletonOrdinalsBuilder endPositionEntry() {
5559
}
5660

5761
BytesRefBlock buildOrdinal() {
58-
int valueCount = docValues.getValueCount();
62+
int valueCount = maxOrd - minOrd + 1;
5963
long breakerSize = ordsSize(valueCount);
6064
blockFactory.adjustBreaker(breakerSize);
6165
BytesRefVector bytesVector = null;
@@ -65,7 +69,7 @@ BytesRefBlock buildOrdinal() {
6569
Arrays.fill(newOrds, -1);
6670
for (int ord : ords) {
6771
if (ord != -1) {
68-
newOrds[ord] = 0;
72+
newOrds[ord - minOrd] = 0;
6973
}
7074
}
7175
// resolve the ordinals and remaps the ordinals
@@ -74,7 +78,7 @@ BytesRefBlock buildOrdinal() {
7478
for (int i = 0; i < newOrds.length; i++) {
7579
if (newOrds[i] != -1) {
7680
newOrds[i] = ++nextOrd;
77-
bytesBuilder.appendBytesRef(docValues.lookupOrd(i));
81+
bytesBuilder.appendBytesRef(docValues.lookupOrd(i + minOrd));
7882
}
7983
}
8084
bytesVector = bytesBuilder.build();
@@ -86,7 +90,7 @@ BytesRefBlock buildOrdinal() {
8690
if (ord == -1) {
8791
ordinalsBuilder.appendNull();
8892
} else {
89-
ordinalsBuilder.appendInt(newOrds[ord]);
93+
ordinalsBuilder.appendInt(newOrds[ord - minOrd]);
9094
}
9195
}
9296
ordinalBlock = ordinalsBuilder.build();
@@ -107,7 +111,6 @@ BytesRefBlock buildRegularBlock() {
107111
blockFactory.adjustBreaker(breakerSize);
108112
try {
109113
int[] sortedOrds = ords.clone();
110-
Arrays.sort(sortedOrds);
111114
int uniqueCount = compactToUnique(sortedOrds);
112115

113116
try (BreakingBytesRefBuilder copies = new BreakingBytesRefBuilder(blockFactory.breaker(), "ords")) {
@@ -167,7 +170,12 @@ public BytesRefBlock build() {
167170
}
168171

169172
boolean shouldBuildOrdinalsBlock() {
170-
return ords.length >= 2 * docValues.getValueCount() && ords.length >= 32;
173+
if (minOrd <= maxOrd) {
174+
int numOrds = maxOrd - minOrd + 1;
175+
return OrdinalBytesRefBlock.isDense(ords.length, numOrds);
176+
} else {
177+
return false;
178+
}
171179
}
172180

173181
@Override

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/AggregatorFunctionTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected final int aggregatorIntermediateBlockCount() {
6161
protected abstract void assertSimpleOutput(List<Block> input, Block result);
6262

6363
@Override
64-
protected Operator.OperatorFactory simpleWithMode(AggregatorMode mode) {
64+
protected Operator.OperatorFactory simpleWithMode(SimpleOptions options, AggregatorMode mode) {
6565
return simpleWithMode(mode, Function.identity());
6666
}
6767

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/GroupingAggregatorFunctionTestCase.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@ protected DataType acceptedDataType() {
9090
};
9191

9292
@Override
93-
protected final Operator.OperatorFactory simpleWithMode(AggregatorMode mode) {
94-
return simpleWithMode(mode, Function.identity());
93+
protected final Operator.OperatorFactory simpleWithMode(SimpleOptions options, AggregatorMode mode) {
94+
return simpleWithMode(options, mode, Function.identity());
9595
}
9696

9797
protected List<Integer> channels(AggregatorMode mode) {
9898
return mode.isInputPartial() ? range(1, 1 + aggregatorIntermediateBlockCount()).boxed().toList() : List.of(1);
9999
}
100100

101101
private Operator.OperatorFactory simpleWithMode(
102+
SimpleOptions options,
102103
AggregatorMode mode,
103104
Function<AggregatorFunctionSupplier, AggregatorFunctionSupplier> wrap
104105
) {
@@ -108,13 +109,24 @@ private Operator.OperatorFactory simpleWithMode(
108109
if (randomBoolean()) {
109110
supplier = chunkGroups(emitChunkSize, supplier);
110111
}
111-
return new RandomizingHashAggregationOperatorFactory(
112-
List.of(new BlockHash.GroupSpec(0, ElementType.LONG)),
113-
mode,
114-
List.of(supplier.groupingAggregatorFactory(mode, channels(mode))),
115-
randomPageSize(),
116-
null
117-
);
112+
113+
if (options.requiresDeterministicFactory()) {
114+
return new HashAggregationOperator.HashAggregationOperatorFactory(
115+
List.of(new BlockHash.GroupSpec(0, ElementType.LONG)),
116+
mode,
117+
List.of(supplier.groupingAggregatorFactory(mode, channels(mode))),
118+
randomPageSize(),
119+
null
120+
);
121+
} else {
122+
return new RandomizingHashAggregationOperatorFactory(
123+
List.of(new BlockHash.GroupSpec(0, ElementType.LONG)),
124+
mode,
125+
List.of(supplier.groupingAggregatorFactory(mode, channels(mode))),
126+
randomPageSize(),
127+
null
128+
);
129+
}
118130
}
119131

120132
@Override
@@ -389,6 +401,7 @@ public final void testEmptyInput() {
389401

390402
public final void testAllFiltered() {
391403
Operator.OperatorFactory factory = simpleWithMode(
404+
SimpleOptions.DEFAULT,
392405
AggregatorMode.SINGLE,
393406
agg -> new FilteredAggregatorFunctionSupplier(agg, ConstantBooleanExpressionEvaluator.factory(false))
394407
);
@@ -401,6 +414,7 @@ public final void testAllFiltered() {
401414

402415
public final void testNoneFiltered() {
403416
Operator.OperatorFactory factory = simpleWithMode(
417+
SimpleOptions.DEFAULT,
404418
AggregatorMode.SINGLE,
405419
agg -> new FilteredAggregatorFunctionSupplier(agg, ConstantBooleanExpressionEvaluator.factory(true))
406420
);
@@ -414,6 +428,7 @@ public final void testNoneFiltered() {
414428

415429
public void testSomeFiltered() {
416430
Operator.OperatorFactory factory = simpleWithMode(
431+
SimpleOptions.DEFAULT,
417432
AggregatorMode.SINGLE,
418433
agg -> new FilteredAggregatorFunctionSupplier(agg, AddGarbageRowsSourceOperator.filterFactory())
419434
);

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
package org.elasticsearch.compute.data;
99

1010
import org.apache.lucene.document.SortedDocValuesField;
11+
import org.apache.lucene.index.DirectoryReader;
1112
import org.apache.lucene.index.IndexReader;
13+
import org.apache.lucene.index.IndexWriter;
14+
import org.apache.lucene.index.IndexWriterConfig;
1215
import org.apache.lucene.index.LeafReaderContext;
1316
import org.apache.lucene.index.SortedDocValues;
1417
import org.apache.lucene.store.Directory;
@@ -37,6 +40,7 @@
3740
import static org.elasticsearch.test.MapMatcher.assertMap;
3841
import static org.elasticsearch.test.MapMatcher.matchesMap;
3942
import static org.hamcrest.Matchers.equalTo;
43+
import static org.hamcrest.Matchers.hasSize;
4044

4145
public class SingletonOrdinalsBuilderTests extends ESTestCase {
4246
public void testReader() throws IOException {
@@ -154,6 +158,39 @@ public void testAllNull() throws IOException {
154158
}
155159
}
156160

161+
public void testEmitOrdinalForHighCardinality() throws IOException {
162+
BlockFactory factory = breakingDriverContext().blockFactory();
163+
int numOrds = between(50, 100);
164+
try (Directory directory = newDirectory(); IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig())) {
165+
for (int o = 0; o < numOrds; o++) {
166+
int docPerOrds = between(10, 15);
167+
for (int d = 0; d < docPerOrds; d++) {
168+
indexWriter.addDocument(List.of(new SortedDocValuesField("f", new BytesRef("value-" + o))));
169+
}
170+
}
171+
try (IndexReader reader = DirectoryReader.open(indexWriter)) {
172+
assertThat(reader.leaves(), hasSize(1));
173+
for (LeafReaderContext ctx : reader.leaves()) {
174+
int batchSize = between(40, 100);
175+
int ord = random().nextInt(numOrds);
176+
try (
177+
var b1 = new SingletonOrdinalsBuilder(factory, ctx.reader().getSortedDocValues("f"), batchSize);
178+
var b2 = new SingletonOrdinalsBuilder(factory, ctx.reader().getSortedDocValues("f"), batchSize)
179+
) {
180+
for (int i = 0; i < batchSize; i++) {
181+
b1.appendOrd(ord);
182+
b2.appendOrd(ord);
183+
}
184+
try (BytesRefBlock block1 = b1.build(); BytesRefBlock block2 = b2.buildRegularBlock()) {
185+
assertThat(block1, equalTo(block2));
186+
assertNotNull(block1.asOrdinals());
187+
}
188+
}
189+
}
190+
}
191+
}
192+
}
193+
157194
static BytesRefBlock buildOrdinalsBuilder(SingletonOrdinalsBuilder builder) {
158195
if (randomBoolean()) {
159196
return builder.buildRegularBlock();

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/lucene/LuceneCountOperatorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void closeIndex() throws IOException {
5151
}
5252

5353
@Override
54-
protected LuceneCountOperator.Factory simple() {
54+
protected LuceneCountOperator.Factory simple(SimpleOptions options) {
5555
return simple(randomFrom(DataPartitioning.values()), between(1, 10_000), 100);
5656
}
5757

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/lucene/LuceneMaxOperatorTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void closeIndex() throws IOException {
7373
}
7474

7575
@Override
76-
protected LuceneMaxFactory simple() {
76+
protected LuceneMaxFactory simple(SimpleOptions options) {
7777
return simple(getNumberTypeTest(), randomFrom(DataPartitioning.values()), between(1, 10_000), 100);
7878
}
7979

0 commit comments

Comments
 (0)