Skip to content

Commit 26102a0

Browse files
committed
es 8.13.0 support
1 parent d1d84a7 commit 26102a0

File tree

96 files changed

+5771
-192
lines changed

Some content is hidden

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

96 files changed

+5771
-192
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.12.2-amd64.deb -o elasticsearch.deb && sudo dpkg -i --force-confnew elasticsearch.deb
8+
- curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.13.0-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

pom.xml

Lines changed: 4 additions & 4 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.12.2.0</version>
6+
<version>8.13.0.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.12.2</elasticsearch.version>
47+
<elasticsearch.version>8.13.0</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>32.0.0-jre</guava.version>
@@ -162,8 +162,8 @@
162162
<artifactId>maven-compiler-plugin</artifactId>
163163
<version>2.3.2</version>
164164
<configuration>
165-
<source>1.8</source>
166-
<target>1.8</target>
165+
<source>16</source>
166+
<target>16</target>
167167
<encoding>UTF-8</encoding>
168168
</configuration>
169169
</plugin>

src/main/java/com/alibaba/druid/pool/ElasticSearchDruidDataSourceFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.alibaba.druid.pool;
22

3-
import org.elasticsearch.client.internal.Client;
43
import org.elasticsearch.plugin.nlpcn.client.ElasticsearchRestClient;
54

65
import javax.sql.DataSource;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.action.admin.indices.refresh;
10+
11+
import org.elasticsearch.action.support.broadcast.BaseBroadcastResponse;
12+
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
13+
import org.elasticsearch.xcontent.ConstructingObjectParser;
14+
import org.elasticsearch.xcontent.XContentParser;
15+
16+
import java.util.Arrays;
17+
18+
import static org.elasticsearch.action.support.broadcast.BaseBroadcastResponse.declareBroadcastFields;
19+
20+
/**
21+
* The response of a refresh action.
22+
*/
23+
public class ParsedRefreshResponse {
24+
25+
private static final ConstructingObjectParser<BroadcastResponse, Void> PARSER = new ConstructingObjectParser<>("refresh", true, arg -> {
26+
BaseBroadcastResponse response = (BaseBroadcastResponse) arg[0];
27+
return new BroadcastResponse(
28+
response.getTotalShards(),
29+
response.getSuccessfulShards(),
30+
response.getFailedShards(),
31+
Arrays.asList(response.getShardFailures())
32+
);
33+
});
34+
35+
static {
36+
declareBroadcastFields(PARSER);
37+
}
38+
39+
public static BroadcastResponse fromXContent(XContentParser parser) {
40+
return PARSER.apply(parser, null);
41+
}
42+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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.action.bulk;
10+
11+
import org.elasticsearch.ElasticsearchException;
12+
import org.elasticsearch.action.DocWriteRequest.OpType;
13+
import org.elasticsearch.action.DocWriteResponse;
14+
import org.elasticsearch.action.delete.DeleteResponse;
15+
import org.elasticsearch.action.index.IndexResponse;
16+
import org.elasticsearch.action.update.UpdateResponse;
17+
import org.elasticsearch.core.CheckedConsumer;
18+
import org.elasticsearch.rest.RestStatus;
19+
import org.elasticsearch.xcontent.XContentParser;
20+
21+
import java.io.IOException;
22+
23+
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
24+
import static org.elasticsearch.common.xcontent.XContentParserUtils.throwUnknownField;
25+
26+
/**
27+
* Represents a single item response for an action executed as part of the bulk API. Holds the index/type/id
28+
* of the relevant action, and if it has failed or not (with the failure message in case it failed).
29+
*/
30+
public class ParsedBulkItemResponse {
31+
32+
/**
33+
* Reads a {@link BulkItemResponse} from a {@link XContentParser}.
34+
*
35+
* @param parser the {@link XContentParser}
36+
* @param id the id to assign to the parsed {@link BulkItemResponse}. It is usually the index of
37+
* the item in the {@link BulkResponse#getItems} array.
38+
*/
39+
public static BulkItemResponse fromXContent(XContentParser parser, int id) throws IOException {
40+
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser);
41+
42+
XContentParser.Token token = parser.nextToken();
43+
ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser);
44+
45+
String currentFieldName = parser.currentName();
46+
token = parser.nextToken();
47+
48+
final OpType opType = OpType.fromString(currentFieldName);
49+
ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser);
50+
51+
DocWriteResponse.Builder builder = null;
52+
CheckedConsumer<XContentParser, IOException> itemParser = null;
53+
54+
if (opType == OpType.INDEX || opType == OpType.CREATE) {
55+
final IndexResponse.Builder indexResponseBuilder = new IndexResponse.Builder();
56+
builder = indexResponseBuilder;
57+
itemParser = (indexParser) -> IndexResponse.parseXContentFields(indexParser, indexResponseBuilder);
58+
59+
} else if (opType == OpType.UPDATE) {
60+
final UpdateResponse.Builder updateResponseBuilder = new UpdateResponse.Builder();
61+
builder = updateResponseBuilder;
62+
itemParser = (updateParser) -> UpdateResponse.parseXContentFields(updateParser, updateResponseBuilder);
63+
64+
} else if (opType == OpType.DELETE) {
65+
final DeleteResponse.Builder deleteResponseBuilder = new DeleteResponse.Builder();
66+
builder = deleteResponseBuilder;
67+
itemParser = (deleteParser) -> DeleteResponse.parseXContentFields(deleteParser, deleteResponseBuilder);
68+
} else {
69+
throwUnknownField(currentFieldName, parser);
70+
}
71+
72+
RestStatus status = null;
73+
ElasticsearchException exception = null;
74+
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
75+
if (token == XContentParser.Token.FIELD_NAME) {
76+
currentFieldName = parser.currentName();
77+
}
78+
79+
if (BulkItemResponse.ERROR.equals(currentFieldName)) {
80+
if (token == XContentParser.Token.START_OBJECT) {
81+
exception = ElasticsearchException.fromXContent(parser);
82+
}
83+
} else if (BulkItemResponse.STATUS.equals(currentFieldName)) {
84+
if (token == XContentParser.Token.VALUE_NUMBER) {
85+
status = RestStatus.fromCode(parser.intValue());
86+
}
87+
} else {
88+
itemParser.accept(parser);
89+
}
90+
}
91+
92+
ensureExpectedToken(XContentParser.Token.END_OBJECT, token, parser);
93+
token = parser.nextToken();
94+
ensureExpectedToken(XContentParser.Token.END_OBJECT, token, parser);
95+
96+
BulkItemResponse bulkItemResponse;
97+
if (exception != null) {
98+
BulkItemResponse.Failure failure = new BulkItemResponse.Failure(builder.getShardId().getIndexName(), builder.getId(), exception, status);
99+
bulkItemResponse = BulkItemResponse.failure(id, opType, failure);
100+
} else {
101+
bulkItemResponse = BulkItemResponse.success(id, opType, builder.build());
102+
}
103+
return bulkItemResponse;
104+
}
105+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.action.bulk;
10+
11+
import org.elasticsearch.xcontent.XContentParser;
12+
13+
import java.io.IOException;
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
17+
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
18+
import static org.elasticsearch.common.xcontent.XContentParserUtils.throwUnknownField;
19+
import static org.elasticsearch.common.xcontent.XContentParserUtils.throwUnknownToken;
20+
21+
/**
22+
* A response of a bulk execution. Holding a response for each item responding (in order) of the
23+
* bulk requests. Each item holds the index/type/id is operated on, and if it failed or not (with the
24+
* failure message).
25+
*/
26+
public class ParsedBulkResponse {
27+
28+
public static BulkResponse fromXContent(XContentParser parser) throws IOException {
29+
XContentParser.Token token = parser.nextToken();
30+
ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser);
31+
32+
long took = -1L;
33+
long ingestTook = BulkResponse.NO_INGEST_TOOK;
34+
List<BulkItemResponse> items = new ArrayList<>();
35+
36+
String currentFieldName = parser.currentName();
37+
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
38+
if (token == XContentParser.Token.FIELD_NAME) {
39+
currentFieldName = parser.currentName();
40+
} else if (token.isValue()) {
41+
if (BulkResponse.TOOK.equals(currentFieldName)) {
42+
took = parser.longValue();
43+
} else if (BulkResponse.INGEST_TOOK.equals(currentFieldName)) {
44+
ingestTook = parser.longValue();
45+
} else if (BulkResponse.ERRORS.equals(currentFieldName) == false) {
46+
throwUnknownField(currentFieldName, parser);
47+
}
48+
} else if (token == XContentParser.Token.START_ARRAY) {
49+
if (BulkResponse.ITEMS.equals(currentFieldName)) {
50+
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
51+
items.add(ParsedBulkItemResponse.fromXContent(parser, items.size()));
52+
}
53+
} else {
54+
throwUnknownField(currentFieldName, parser);
55+
}
56+
} else {
57+
throwUnknownToken(token, parser);
58+
}
59+
}
60+
return new BulkResponse(items.toArray(new BulkItemResponse[items.size()]), took, ingestTook);
61+
}
62+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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.action.search;
10+
11+
import org.elasticsearch.ElasticsearchException;
12+
import org.elasticsearch.core.RefCounted;
13+
import org.elasticsearch.xcontent.ConstructingObjectParser;
14+
import org.elasticsearch.xcontent.ParseField;
15+
import org.elasticsearch.xcontent.XContentParser;
16+
import org.elasticsearch.xcontent.XContentParser.Token;
17+
18+
import java.io.IOException;
19+
import java.lang.reflect.Field;
20+
import java.util.Arrays;
21+
import java.util.List;
22+
23+
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
24+
25+
/**
26+
* A multi search response.
27+
*/
28+
public class ParsedMultiSearchResponse {
29+
30+
private static final ParseField RESPONSES = new ParseField(MultiSearchResponse.Fields.RESPONSES);
31+
private static final ParseField TOOK_IN_MILLIS = new ParseField("took");
32+
private static final Field REF_COUNTED_FIELD;
33+
34+
static {
35+
try {
36+
REF_COUNTED_FIELD = MultiSearchResponse.class.getDeclaredField("refCounted");
37+
if (!REF_COUNTED_FIELD.isAccessible()) {
38+
REF_COUNTED_FIELD.setAccessible(true);
39+
}
40+
} catch (NoSuchFieldException e) {
41+
throw new IllegalStateException(e);
42+
}
43+
}
44+
45+
@SuppressWarnings("unchecked")
46+
private static final ConstructingObjectParser<MultiSearchResponse, Void> PARSER = new ConstructingObjectParser<>(
47+
"multi_search",
48+
true,
49+
a -> new MultiSearchResponse(((List<MultiSearchResponse.Item>) a[0]).toArray(new MultiSearchResponse.Item[0]), (long) a[1])
50+
);
51+
static {
52+
PARSER.declareObjectArray(constructorArg(), (p, c) -> itemFromXContent(p), RESPONSES);
53+
PARSER.declareLong(constructorArg(), TOOK_IN_MILLIS);
54+
}
55+
56+
public static MultiSearchResponse fromXContext(XContentParser parser) {
57+
return unpooled(PARSER.apply(parser, null));
58+
}
59+
60+
private static MultiSearchResponse.Item itemFromXContent(XContentParser parser) throws IOException {
61+
// This parsing logic is a bit tricky here, because the multi search response itself is tricky:
62+
// 1) The json objects inside the responses array are either a search response or a serialized exception
63+
// 2) Each response json object gets a status field injected that ElasticsearchException.failureFromXContent(...) does not parse,
64+
// but SearchResponse.innerFromXContent(...) parses and then ignores. The status field is not needed to parse
65+
// the response item. However in both cases this method does need to parse the 'status' field otherwise the parsing of
66+
// the response item in the next json array element will fail due to parsing errors.
67+
68+
MultiSearchResponse.Item item = null;
69+
String fieldName = null;
70+
71+
Token token = parser.nextToken();
72+
assert token == Token.FIELD_NAME;
73+
outer: for (; token != Token.END_OBJECT; token = parser.nextToken()) {
74+
switch (token) {
75+
case FIELD_NAME:
76+
fieldName = parser.currentName();
77+
if ("error".equals(fieldName)) {
78+
item = new MultiSearchResponse.Item(null, ElasticsearchException.failureFromXContent(parser));
79+
} else if ("status".equals(fieldName) == false) {
80+
item = new MultiSearchResponse.Item(ParsedSearchResponse.innerFromXContent(parser), null);
81+
break outer;
82+
}
83+
break;
84+
case VALUE_NUMBER:
85+
if ("status".equals(fieldName)) {
86+
// Ignore the status value
87+
}
88+
break;
89+
}
90+
}
91+
assert parser.currentToken() == Token.END_OBJECT;
92+
return item;
93+
}
94+
95+
private static MultiSearchResponse unpooled(MultiSearchResponse searchResponse) {
96+
MultiSearchResponse.Item[] items = searchResponse.getResponses();
97+
MultiSearchResponse.Item[] tempItems = Arrays.copyOf(items, items.length);
98+
searchResponse.decRef();
99+
System.arraycopy(tempItems, 0, items, 0, items.length);
100+
try {
101+
REF_COUNTED_FIELD.set(searchResponse, RefCounted.ALWAYS_REFERENCED);
102+
} catch (IllegalAccessException e) {
103+
throw new IllegalStateException(e);
104+
}
105+
return searchResponse;
106+
}
107+
}

0 commit comments

Comments
 (0)