-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Fix AnalyzeAction response serialization #44284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,10 @@ | |
|
||
package org.elasticsearch.action.admin.indices.analyze; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.single.shard.SingleShardRequest; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.Strings; | ||
|
@@ -292,22 +293,29 @@ public static class Response extends ActionResponse implements ToXContentObject | |
private final List<AnalyzeToken> tokens; | ||
|
||
public Response(List<AnalyzeToken> tokens, DetailAnalyzeResponse detail) { | ||
if (tokens == null && detail == null) { | ||
throw new IllegalArgumentException("Neither token nor detail set on AnalysisAction.Response"); | ||
} | ||
this.tokens = tokens; | ||
this.detail = detail; | ||
} | ||
|
||
public Response(StreamInput in) throws IOException { | ||
super.readFrom(in); | ||
int size = in.readVInt(); | ||
if (size > 0) { | ||
tokens = new ArrayList<>(size); | ||
for (int i = 0; i < size; i++) { | ||
tokens.add(new AnalyzeToken(in)); | ||
if (in.getVersion().onOrAfter(Version.V_8_0_0)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to backport this to 7_3_0 at least if possible. Not sure of its feasible to 7_2_1, might complicate the whole backport story a bit. |
||
AnalyzeToken[] tokenArray = in.readOptionalArray(AnalyzeToken::new, AnalyzeToken[]::new); | ||
tokens = tokenArray != null ? Arrays.asList(tokenArray) : null; | ||
} else { | ||
int size = in.readVInt(); | ||
if (size > 0) { | ||
tokens = new ArrayList<>(size); | ||
for (int i = 0; i < size; i++) { | ||
tokens.add(new AnalyzeToken(in)); | ||
} | ||
} else { | ||
tokens = null; | ||
} | ||
} | ||
else { | ||
tokens = null; | ||
} | ||
detail = in.readOptionalWriteable(DetailAnalyzeResponse::new); | ||
} | ||
|
||
|
@@ -346,21 +354,33 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
if (tokens != null) { | ||
out.writeVInt(tokens.size()); | ||
for (AnalyzeToken token : tokens) { | ||
token.writeTo(out); | ||
if (out.getVersion().onOrAfter(Version.V_8_0_0)) { | ||
AnalyzeToken[] tokenArray = null; | ||
if (tokens != null) { | ||
tokenArray = tokens.toArray(new AnalyzeToken[0]); | ||
} | ||
out.writeOptionalArray(tokenArray); | ||
} else { | ||
out.writeVInt(0); | ||
if (tokens != null) { | ||
out.writeVInt(tokens.size()); | ||
for (AnalyzeToken token : tokens) { | ||
token.writeTo(out); | ||
} | ||
} else { | ||
out.writeVInt(0); | ||
} | ||
} | ||
out.writeOptionalWriteable(detail); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Response that = (Response) o; | ||
return Objects.equals(detail, that.detail) && | ||
Objects.equals(tokens, that.tokens); | ||
|
@@ -401,8 +421,12 @@ public static class AnalyzeToken implements Writeable, ToXContentObject { | |
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
AnalyzeToken that = (AnalyzeToken) o; | ||
return startOffset == that.startOffset && | ||
endOffset == that.endOffset && | ||
|
@@ -582,8 +606,12 @@ public AnalyzeTokenList[] tokenfilters() { | |
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
DetailAnalyzeResponse that = (DetailAnalyzeResponse) o; | ||
return customAnalyzer == that.customAnalyzer && | ||
Objects.equals(analyzer, that.analyzer) && | ||
|
@@ -669,8 +697,12 @@ public static class AnalyzeTokenList implements Writeable, ToXContentObject { | |
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
AnalyzeTokenList that = (AnalyzeTokenList) o; | ||
return Objects.equals(name, that.name) && | ||
Arrays.equals(tokens, that.tokens); | ||
|
@@ -690,16 +722,19 @@ public AnalyzeTokenList(String name, AnalyzeToken[] tokens) { | |
|
||
AnalyzeTokenList(StreamInput in) throws IOException { | ||
name = in.readString(); | ||
int size = in.readVInt(); | ||
if (size > 0) { | ||
tokens = new AnalyzeToken[size]; | ||
for (int i = 0; i < size; i++) { | ||
tokens[i] = new AnalyzeToken(in); | ||
if (in.getVersion().onOrAfter(Version.V_8_0_0)) { | ||
tokens = in.readOptionalArray(AnalyzeToken::new, AnalyzeToken[]::new); | ||
} else { | ||
int size = in.readVInt(); | ||
if (size > 0) { | ||
tokens = new AnalyzeToken[size]; | ||
for (int i = 0; i < size; i++) { | ||
tokens[i] = new AnalyzeToken(in); | ||
} | ||
} else { | ||
tokens = null; | ||
} | ||
} | ||
else { | ||
tokens = null; | ||
} | ||
} | ||
|
||
public String getName() { | ||
|
@@ -732,13 +767,17 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(name); | ||
if (tokens != null) { | ||
out.writeVInt(tokens.length); | ||
for (AnalyzeToken token : tokens) { | ||
token.writeTo(out); | ||
} | ||
if (out.getVersion().onOrAfter(Version.V_8_0_0)) { | ||
out.writeOptionalArray(tokens); | ||
} else { | ||
out.writeVInt(0); | ||
if (tokens != null) { | ||
out.writeVInt(tokens.length); | ||
for (AnalyzeToken token : tokens) { | ||
token.writeTo(out); | ||
} | ||
} else { | ||
out.writeVInt(0); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -789,8 +828,12 @@ public void writeTo(StreamOutput out) throws IOException { | |
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
CharFilteredText that = (CharFilteredText) o; | ||
return Objects.equals(name, that.name) && | ||
Arrays.equals(texts, that.texts); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.