Skip to content

Commit

Permalink
es 8.15.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
shi-yuan committed Aug 24, 2024
1 parent a95dacb commit ae443c6
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jdk:

before_install:
- sudo rm -rf /var/lib/elasticsearch
- curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.14.3-amd64.deb -o elasticsearch.deb && sudo dpkg -i --force-confnew elasticsearch.deb
- curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.15.0-amd64.deb -o elasticsearch.deb && sudo dpkg -i --force-confnew elasticsearch.deb
- sudo cp ./src/test/resources/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml
- sudo cat /etc/elasticsearch/elasticsearch.yml
- sudo java -version
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.nlpcn</groupId>
<artifactId>elasticsearch-sql</artifactId>
<version>8.14.3.0</version>
<version>8.15.0.0</version>
<packaging>jar</packaging>
<description>Query elasticsearch using SQL</description>
<name>elasticsearch-sql</name>
Expand Down Expand Up @@ -44,7 +44,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<runSuite>**/MainTestSuite.class</runSuite>
<elasticsearch.plugin.name>sql</elasticsearch.plugin.name>
<elasticsearch.version>8.14.3</elasticsearch.version>
<elasticsearch.version>8.15.0</elasticsearch.version>
<elasticsearch.plugin.classname>org.elasticsearch.plugin.nlpcn.SqlPlug</elasticsearch.plugin.classname>
<druid.version>1.2.15</druid.version>
<guava.version>32.0.0-jre</guava.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.action.search;

import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.core.RefCounted;
import org.elasticsearch.core.TimeValue;
Expand All @@ -28,6 +29,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;

Expand Down Expand Up @@ -151,7 +153,7 @@ public static SearchResponse innerFromXContent(XContentParser parser) throws IOE
tookInMillis,
failures.toArray(ShardSearchFailure.EMPTY_ARRAY),
clusters,
searchContextId
Objects.nonNull(searchContextId) ? new BytesArray(searchContextId) : null
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.elasticsearch.common.unit.RelativeByteSizeValue;
import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.elasticsearch.health.metadata.HealthMetadata;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.shard.IndexLongFieldRange;
import org.elasticsearch.xcontent.XContentParser;

Expand Down Expand Up @@ -83,6 +84,7 @@ public class ClusterStateActionHandler extends ActionHandler<ClusterStateRequest
private static final String KEY_STATE = "state";
private static final String KEY_MAPPINGS = "mappings";
private static final String KEY_MAPPINGS_HASH = "mappings_hash";
private static final String KEY_MAPPINGS_UPDATED_VERSION = "mappings_updated_version";
private static final String KEY_ALIASES = "aliases";
private static final String KEY_ROLLOVER_INFOS = "rollover_info";
private static final String KEY_WARMERS = "warmers";
Expand Down Expand Up @@ -381,6 +383,9 @@ private IndexMetadata loadIndexMetadataFromXContent(XContentParser parser) throw
case KEY_SYSTEM:
builder.system(parser.booleanValue());
break;
case KEY_MAPPINGS_UPDATED_VERSION:
builder.mappingsUpdatedVersion(IndexVersion.fromId(parser.intValue()));
break;
case KEY_MAPPINGS_HASH:
logger.warn("Skipping mappings hash");
parser.skipChildren();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected PutClusterSettingsRequest convertRequest(ClusterUpdateSettingsRequest
builder.withJson(parser, jsonpMapper);
}
Optional.ofNullable(clusterUpdateSettingsRequest.masterNodeTimeout()).ifPresent(e -> builder.masterTimeout(Time.of(t -> t.time(e.toString()))));
Optional.ofNullable(clusterUpdateSettingsRequest.timeout()).ifPresent(e -> builder.timeout(Time.of(t -> t.time(e.toString()))));
Optional.ofNullable(clusterUpdateSettingsRequest.ackTimeout()).ifPresent(e -> builder.timeout(Time.of(t -> t.time(e.toString()))));
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected CreateIndexRequest convertRequest(org.elasticsearch.action.admin.indic
builder.index(createIndexRequest.index());
builder.mappings(fromJson(createIndexRequest.mappings(), TypeMapping._DESERIALIZER));
builder.settings(fromJson(createIndexRequest.settings().toString(), IndexSettings._DESERIALIZER));
Optional.ofNullable(createIndexRequest.timeout()).ifPresent(e -> builder.timeout(Time.of(t -> t.time(e.toString()))));
Optional.ofNullable(createIndexRequest.ackTimeout()).ifPresent(e -> builder.timeout(Time.of(t -> t.time(e.toString()))));
Optional.ofNullable(createIndexRequest.masterNodeTimeout()).ifPresent(e -> builder.masterTimeout(Time.of(t -> t.time(e.toString()))));
ActiveShardCount activeShardCount = createIndexRequest.waitForActiveShards();
if (Objects.nonNull(activeShardCount) && activeShardCount.value() > -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected DeleteIndexRequest convertRequest(org.elasticsearch.action.admin.indic
DeleteIndexRequest.Builder builder = new DeleteIndexRequest.Builder();
builder.index(Arrays.asList(deleteIndexRequest.indices()));
Optional.ofNullable(deleteIndexRequest.masterNodeTimeout()).ifPresent(e -> builder.masterTimeout(Time.of(t -> t.time(e.toString()))));
Optional.ofNullable(deleteIndexRequest.timeout()).ifPresent(e -> builder.timeout(Time.of(t -> t.time(e.toString()))));
Optional.ofNullable(deleteIndexRequest.ackTimeout()).ifPresent(e -> builder.timeout(Time.of(t -> t.time(e.toString()))));
Optional.ofNullable(deleteIndexRequest.indicesOptions()).ifPresent(options -> {
builder.allowNoIndices(options.allowNoIndices());
builder.ignoreUnavailable(options.ignoreUnavailable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected PutMappingRequest convertRequest(org.elasticsearch.action.admin.indice
builder.ignoreUnavailable(options.ignoreUnavailable());
builder.expandWildcards(getExpandWildcard(options.wildcardOptions()));
});
Optional.ofNullable(putMappingRequest.timeout()).ifPresent(e -> builder.timeout(Time.of(t -> t.time(e.toString()))));
Optional.ofNullable(putMappingRequest.ackTimeout()).ifPresent(e -> builder.timeout(Time.of(t -> t.time(e.toString()))));
Optional.ofNullable(putMappingRequest.masterNodeTimeout()).ifPresent(e -> builder.masterTimeout(Time.of(t -> t.time(e.toString()))));
return builder.build();
}
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/org/nlpcn/es4sql/domain/SearchResult.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package org.nlpcn.es4sql.domain;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.Aggregation;
Expand All @@ -23,6 +17,13 @@
import org.elasticsearch.search.aggregations.metrics.InternalValueCount;
import org.nlpcn.es4sql.exception.SqlParseException;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class SearchResult {
/**
* 查询结果
Expand Down Expand Up @@ -60,7 +61,7 @@ public SearchResult(SearchResponse resp, Select select) throws SqlParseException
this.total = buckets.size();
results = new ArrayList<>(buckets.size());
for (Bucket bucket : buckets) {
Map<String, Object> aggsMap = toAggsMap(bucket.getAggregations().getAsMap());
Map<String, Object> aggsMap = toAggsMap(bucket.getAggregations().asList());
aggsMap.put("docCount", bucket.getDocCount());
results.add(aggsMap);
}
Expand Down Expand Up @@ -97,15 +98,15 @@ private Map<String, Object> toFieldsMap(Map<String, DocumentField> fields) {

/**
* 讲es的field域转换为你Object
*
* @param fields
*
* @param aggregations
* @return
* @throws SqlParseException
*/
private Map<String, Object> toAggsMap(Map<String, InternalAggregation> fields) throws SqlParseException {
Map<String, Object> result = new HashMap<>();
for (Entry<String, InternalAggregation> entry : fields.entrySet()) {
result.put(entry.getKey(), covenValue(entry.getValue()));
private Map<String, Object> toAggsMap(List<InternalAggregation> aggregations) throws SqlParseException {
Map<String, Object> result = Maps.newMapWithExpectedSize(aggregations.size());
for (InternalAggregation aggregation : aggregations) {
result.put(aggregation.getName(), covenValue(aggregation));
}
return result;
}
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/org/nlpcn/es4sql/AggregationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.google.common.collect.DiscreteDomain;
import com.google.common.collect.Range;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.bucket.filter.Filters;
import org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter;
Expand Down Expand Up @@ -201,8 +203,13 @@ public void percentileTestSpecific() throws IOException, SqlParseException, SQLF
@Test
public void aliasTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
InternalAggregations result = query(String.format("SELECT COUNT(*) AS mycount FROM %s", TEST_INDEX_ACCOUNT));
assertThat(result.asMap(), hasKey("mycount"));
}
List<InternalAggregation> aggregations = result.asList();
Map<String, InternalAggregation> aggregationsAsMap = Maps.newMapWithExpectedSize(aggregations.size());
for (InternalAggregation aggregation : aggregations) {
aggregationsAsMap.put(aggregation.getName(), aggregation);
}
assertThat(aggregationsAsMap, hasKey("mycount"));
}

@Test
public void groupByTest() throws Exception {
Expand Down

0 comments on commit ae443c6

Please sign in to comment.