Skip to content

Commit bc78b03

Browse files
author
Hendrik Muhs
authored
[7.9][Transform]disable optimizations when using scripts in group_by (#62524)
the outcome and we have no query counterpart. Other optimizations for other group_by's are not affected. relates #57332 backport #60724
1 parent c056b7e commit bc78b03

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/pivot/TermsGroupSourceTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public static TermsGroupSource randomTermsGroupSource() {
2121
return new TermsGroupSource(field, scriptConfig);
2222
}
2323

24+
public static TermsGroupSource randomTermsGroupSourceNoScript() {
25+
String field = randomAlphaOfLengthBetween(1, 20);
26+
return new TermsGroupSource(field, null);
27+
}
28+
2429
@Override
2530
protected TermsGroupSource doParseInstance(XContentParser parser) throws IOException {
2631
return TermsGroupSource.fromXContent(parser, false);

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/CompositeBucketsChangeCollector.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ static Map<String, FieldCollector> createFieldCollectors(Map<String, SingleGroup
381381
Map<String, FieldCollector> fieldCollectors = new HashMap<>();
382382

383383
for (Entry<String, SingleGroupSource> entry : groups.entrySet()) {
384+
// skip any fields that use scripts
385+
if (entry.getValue().getScriptConfig() != null) {
386+
continue;
387+
}
388+
384389
switch (entry.getValue().getType()) {
385390
case TERMS:
386391
fieldCollectors.put(

x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/pivot/CompositeBucketsChangeCollectorTests.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.xpack.core.transform.transforms.pivot.GroupConfig;
2626
import org.elasticsearch.xpack.core.transform.transforms.pivot.GroupConfigTests;
2727
import org.elasticsearch.xpack.core.transform.transforms.pivot.HistogramGroupSourceTests;
28+
import org.elasticsearch.xpack.core.transform.transforms.pivot.ScriptConfigTests;
2829
import org.elasticsearch.xpack.core.transform.transforms.pivot.SingleGroupSource;
2930
import org.elasticsearch.xpack.core.transform.transforms.pivot.TermsGroupSource;
3031
import org.elasticsearch.xpack.core.transform.transforms.pivot.TermsGroupSourceTests;
@@ -76,7 +77,7 @@ public void testPageSize() throws IOException {
7677
assertEquals(10, getCompositeAggregationBuilder(collector.buildChangesQuery(new SearchSourceBuilder(), null, 10)).size());
7778

7879
// a terms group_by is limited by terms query
79-
SingleGroupSource termsGroupBy = TermsGroupSourceTests.randomTermsGroupSource();
80+
SingleGroupSource termsGroupBy = TermsGroupSourceTests.randomTermsGroupSourceNoScript();
8081
groups.put("terms", termsGroupBy);
8182

8283
collector = CompositeBucketsChangeCollector.buildChangeCollector(getCompositeAggregation(groups), groups, null);
@@ -138,6 +139,24 @@ public void testTermsFieldCollector() throws IOException {
138139
assertThat(((TermsQueryBuilder) queryBuilder).values(), containsInAnyOrder("id1", "id2", "id3"));
139140
}
140141

142+
public void testNoTermsFieldCollectorForScripts() throws IOException {
143+
Map<String, SingleGroupSource> groups = new LinkedHashMap<>();
144+
145+
// terms with value script
146+
SingleGroupSource termsGroupBy = new TermsGroupSource("id", ScriptConfigTests.randomScriptConfig());
147+
groups.put("id", termsGroupBy);
148+
149+
Map<String, FieldCollector> fieldCollectors = CompositeBucketsChangeCollector.createFieldCollectors(groups, null);
150+
assertTrue(fieldCollectors.isEmpty());
151+
152+
// terms with only a script
153+
termsGroupBy = new TermsGroupSource(null, ScriptConfigTests.randomScriptConfig());
154+
groups.put("id", termsGroupBy);
155+
156+
fieldCollectors = CompositeBucketsChangeCollector.createFieldCollectors(groups, null);
157+
assertTrue(fieldCollectors.isEmpty());
158+
}
159+
141160
private static CompositeAggregationBuilder getCompositeAggregation(Map<String, SingleGroupSource> groups) throws IOException {
142161
CompositeAggregationBuilder compositeAggregation;
143162
try (XContentBuilder builder = jsonBuilder()) {

0 commit comments

Comments
 (0)