Skip to content

Commit 4b922a1

Browse files
committed
es 8.7.1 support
1 parent 4b7e5b7 commit 4b922a1

17 files changed

+1080
-62
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jdk:
55

66
before_install:
77
- sudo rm -rf /var/lib/elasticsearch
8-
- curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.7.0-amd64.deb -o elasticsearch.deb && sudo dpkg -i --force-confnew elasticsearch.deb
8+
- curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.7.1-amd64.deb -o elasticsearch.deb && sudo dpkg -i --force-confnew elasticsearch.deb
99
- sudo cp ./src/test/resources/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml
1010
- sudo cat /etc/elasticsearch/elasticsearch.yml
1111
- sudo java -version

lib/aggregations.jar

-191 KB
Binary file not shown.

lib/parent-join.jar

-91.2 KB
Binary file not shown.

lib/reindex.jar

-121 KB
Binary file not shown.

pom.xml

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.nlpcn</groupId>
55
<artifactId>elasticsearch-sql</artifactId>
6-
<version>8.7.0.1</version>
6+
<version>8.7.1.0</version>
77
<packaging>jar</packaging>
88
<description>Query elasticsearch using SQL</description>
99
<name>elasticsearch-sql</name>
@@ -44,7 +44,7 @@
4444
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4545
<runSuite>**/MainTestSuite.class</runSuite>
4646
<elasticsearch.plugin.name>sql</elasticsearch.plugin.name>
47-
<elasticsearch.version>8.7.0</elasticsearch.version>
47+
<elasticsearch.version>8.7.1</elasticsearch.version>
4848
<elasticsearch.plugin.classname>org.elasticsearch.plugin.nlpcn.SqlPlug</elasticsearch.plugin.classname>
4949
<druid.version>1.2.15</druid.version>
5050
<guava.version>31.1-jre</guava.version>
@@ -82,30 +82,6 @@
8282
<version>${guava.version}</version>
8383
</dependency>
8484

85-
<dependency>
86-
<groupId>org.elasticsearch.plugin</groupId>
87-
<artifactId>reindex-client</artifactId>
88-
<version>${elasticsearch.version}</version>
89-
<systemPath>${project.basedir}/lib/reindex.jar</systemPath>
90-
<scope>system</scope>
91-
</dependency>
92-
93-
<dependency>
94-
<groupId>org.elasticsearch.plugin</groupId>
95-
<artifactId>parent-join-client</artifactId>
96-
<version>${elasticsearch.version}</version>
97-
<systemPath>${project.basedir}/lib/parent-join.jar</systemPath>
98-
<scope>system</scope>
99-
</dependency>
100-
101-
<dependency>
102-
<groupId>org.elasticsearch.plugin</groupId>
103-
<artifactId>aggregations</artifactId>
104-
<version>${elasticsearch.version}</version>
105-
<systemPath>${project.basedir}/lib/aggregations.jar</systemPath>
106-
<scope>system</scope>
107-
</dependency>
108-
10985
<dependency>
11086
<groupId>org.locationtech.jts</groupId>
11187
<artifactId>jts-core</artifactId>

src/assembly/zip.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,5 @@
2323
<include>plugin-descriptor.properties</include>
2424
</includes>
2525
</fileSet>
26-
<fileSet>
27-
<directory>${project.basedir}/lib</directory>
28-
<outputDirectory>/</outputDirectory>
29-
<includes>
30-
<include>*.jar</include>
31-
</includes>
32-
</fileSet>
3326
</fileSets>
3427
</assembly>
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.aggregations.pipeline;
10+
11+
import org.elasticsearch.TransportVersion;
12+
import org.elasticsearch.common.ParsingException;
13+
import org.elasticsearch.common.io.stream.StreamInput;
14+
import org.elasticsearch.common.io.stream.StreamOutput;
15+
import org.elasticsearch.script.Script;
16+
import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder;
17+
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
18+
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
19+
import org.elasticsearch.xcontent.XContentBuilder;
20+
import org.elasticsearch.xcontent.XContentParser;
21+
22+
import java.io.IOException;
23+
import java.util.ArrayList;
24+
import java.util.HashMap;
25+
import java.util.List;
26+
import java.util.Map;
27+
import java.util.Objects;
28+
import java.util.TreeMap;
29+
30+
import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.BUCKETS_PATH;
31+
import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.GAP_POLICY;
32+
33+
public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAggregationBuilder<BucketSelectorPipelineAggregationBuilder> {
34+
public static final String NAME = "bucket_selector";
35+
36+
private final Map<String, String> bucketsPathsMap;
37+
private final Script script;
38+
private GapPolicy gapPolicy = GapPolicy.SKIP;
39+
40+
public BucketSelectorPipelineAggregationBuilder(String name, Map<String, String> bucketsPathsMap, Script script) {
41+
super(name, NAME, new TreeMap<>(bucketsPathsMap).values().toArray(new String[bucketsPathsMap.size()]));
42+
this.bucketsPathsMap = bucketsPathsMap;
43+
this.script = script;
44+
}
45+
46+
/**
47+
* Read from a stream.
48+
*/
49+
public BucketSelectorPipelineAggregationBuilder(StreamInput in) throws IOException {
50+
super(in, NAME);
51+
bucketsPathsMap = in.readMap(StreamInput::readString, StreamInput::readString);
52+
script = new Script(in);
53+
gapPolicy = GapPolicy.readFrom(in);
54+
}
55+
56+
@Override
57+
protected void doWriteTo(StreamOutput out) throws IOException {
58+
out.writeMap(bucketsPathsMap, StreamOutput::writeString, StreamOutput::writeString);
59+
script.writeTo(out);
60+
gapPolicy.writeTo(out);
61+
}
62+
63+
/**
64+
* Sets the gap policy to use for this aggregation.
65+
*/
66+
public BucketSelectorPipelineAggregationBuilder gapPolicy(GapPolicy gapPolicy) {
67+
if (gapPolicy == null) {
68+
throw new IllegalArgumentException("[gapPolicy] must not be null: [" + name + "]");
69+
}
70+
this.gapPolicy = gapPolicy;
71+
return this;
72+
}
73+
74+
/**
75+
* Gets the gap policy to use for this aggregation.
76+
*/
77+
public GapPolicy gapPolicy() {
78+
return gapPolicy;
79+
}
80+
81+
@Override
82+
protected PipelineAggregator createInternal(Map<String, Object> metadata) {
83+
throw new UnsupportedOperationException();
84+
}
85+
86+
@Override
87+
protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
88+
builder.field(BUCKETS_PATH.getPreferredName(), bucketsPathsMap);
89+
builder.field(Script.SCRIPT_PARSE_FIELD.getPreferredName(), script);
90+
builder.field(GAP_POLICY.getPreferredName(), gapPolicy.getName());
91+
return builder;
92+
}
93+
94+
public static BucketSelectorPipelineAggregationBuilder parse(String reducerName, XContentParser parser) throws IOException {
95+
XContentParser.Token token;
96+
Script script = null;
97+
String currentFieldName = null;
98+
Map<String, String> bucketsPathsMap = null;
99+
GapPolicy gapPolicy = null;
100+
101+
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
102+
if (token == XContentParser.Token.FIELD_NAME) {
103+
currentFieldName = parser.currentName();
104+
} else if (token == XContentParser.Token.VALUE_STRING) {
105+
if (BUCKETS_PATH.match(currentFieldName, parser.getDeprecationHandler())) {
106+
bucketsPathsMap = new HashMap<>();
107+
bucketsPathsMap.put("_value", parser.text());
108+
} else if (GAP_POLICY.match(currentFieldName, parser.getDeprecationHandler())) {
109+
gapPolicy = GapPolicy.parse(parser.text(), parser.getTokenLocation());
110+
} else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
111+
script = Script.parse(parser);
112+
} else {
113+
throw new ParsingException(
114+
parser.getTokenLocation(),
115+
"Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."
116+
);
117+
}
118+
} else if (token == XContentParser.Token.START_ARRAY) {
119+
if (BUCKETS_PATH.match(currentFieldName, parser.getDeprecationHandler())) {
120+
List<String> paths = new ArrayList<>();
121+
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
122+
String path = parser.text();
123+
paths.add(path);
124+
}
125+
bucketsPathsMap = new HashMap<>();
126+
for (int i = 0; i < paths.size(); i++) {
127+
bucketsPathsMap.put("_value" + i, paths.get(i));
128+
}
129+
} else {
130+
throw new ParsingException(
131+
parser.getTokenLocation(),
132+
"Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."
133+
);
134+
}
135+
} else if (token == XContentParser.Token.START_OBJECT) {
136+
if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
137+
script = Script.parse(parser);
138+
} else if (BUCKETS_PATH.match(currentFieldName, parser.getDeprecationHandler())) {
139+
Map<String, Object> map = parser.map();
140+
bucketsPathsMap = new HashMap<>();
141+
for (Map.Entry<String, Object> entry : map.entrySet()) {
142+
bucketsPathsMap.put(entry.getKey(), String.valueOf(entry.getValue()));
143+
}
144+
} else {
145+
throw new ParsingException(
146+
parser.getTokenLocation(),
147+
"Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."
148+
);
149+
}
150+
} else {
151+
throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + reducerName + "].");
152+
}
153+
}
154+
155+
if (bucketsPathsMap == null) {
156+
throw new ParsingException(
157+
parser.getTokenLocation(),
158+
"Missing required field [" + BUCKETS_PATH.getPreferredName() + "] for bucket_selector aggregation [" + reducerName + "]"
159+
);
160+
}
161+
162+
if (script == null) {
163+
throw new ParsingException(
164+
parser.getTokenLocation(),
165+
"Missing required field ["
166+
+ Script.SCRIPT_PARSE_FIELD.getPreferredName()
167+
+ "] for bucket_selector aggregation ["
168+
+ reducerName
169+
+ "]"
170+
);
171+
}
172+
173+
BucketSelectorPipelineAggregationBuilder factory = new BucketSelectorPipelineAggregationBuilder(
174+
reducerName,
175+
bucketsPathsMap,
176+
script
177+
);
178+
if (gapPolicy != null) {
179+
factory.gapPolicy(gapPolicy);
180+
}
181+
return factory;
182+
}
183+
184+
@Override
185+
protected void validate(ValidationContext context) {
186+
context.validateHasParent(NAME, name);
187+
}
188+
189+
@Override
190+
protected boolean overrideBucketsPath() {
191+
return true;
192+
}
193+
194+
@Override
195+
public int hashCode() {
196+
return Objects.hash(super.hashCode(), bucketsPathsMap, script, gapPolicy);
197+
}
198+
199+
@Override
200+
public boolean equals(Object obj) {
201+
if (this == obj) return true;
202+
if (obj == null || getClass() != obj.getClass()) return false;
203+
if (super.equals(obj) == false) return false;
204+
205+
BucketSelectorPipelineAggregationBuilder other = (BucketSelectorPipelineAggregationBuilder) obj;
206+
return Objects.equals(bucketsPathsMap, other.bucketsPathsMap)
207+
&& Objects.equals(script, other.script)
208+
&& Objects.equals(gapPolicy, other.gapPolicy);
209+
}
210+
211+
@Override
212+
public String getWriteableName() {
213+
return NAME;
214+
}
215+
216+
@Override
217+
public TransportVersion getMinimalSupportedVersion() {
218+
return TransportVersion.ZERO;
219+
}
220+
}

0 commit comments

Comments
 (0)