-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Refactors MoreLikeThisQueryBuilder and Parser #13486
Closed
alexksikes
wants to merge
10
commits into
elastic:feature/query-refactoring
from
alexksikes:feature/query-refactoring-more-like-this
+950
−485
Closed
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d722c47
Refactors MoreLikeThisQueryBuilder and Parser
alexksikes 96f3b28
adds serialization and a couple of fixes
alexksikes f060dbe
adds most builder tests
alexksikes c00cac3
adds item validation
alexksikes 3d817f4
adds getters
alexksikes 9239c7c
adds serialization test for artificial doc and per field analyzer
alexksikes 5d76514
minor change Item#doc(XContentBuilder)
alexksikes c9ffe10
addressed comments
alexksikes bad2164
updated migration doc
alexksikes 102c16b
addressed comments
alexksikes 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 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 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 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 |
---|---|---|
|
@@ -18,12 +18,17 @@ | |
*/ | ||
package org.elasticsearch.index; | ||
|
||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.lucene.uid.Versions; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* | ||
*/ | ||
public enum VersionType { | ||
public enum VersionType implements Writeable<VersionType> { | ||
INTERNAL((byte) 0) { | ||
@Override | ||
public boolean isVersionConflictForWrites(long currentVersion, long expectedVersion) { | ||
|
@@ -219,6 +224,8 @@ public boolean validateVersionForReads(long version) { | |
|
||
private final byte value; | ||
|
||
private static final VersionType PROTOTYPE = INTERNAL; | ||
|
||
VersionType(byte value) { | ||
this.value = value; | ||
} | ||
|
@@ -304,4 +311,18 @@ public static VersionType fromValue(byte value) { | |
} | ||
throw new IllegalArgumentException("No version type match [" + value + "]"); | ||
} | ||
|
||
@Override | ||
public VersionType readFrom(StreamInput in) throws IOException { | ||
return VersionType.values()[in.readVInt()]; | ||
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. can we check the value we are reading here? an assertion would be ok |
||
} | ||
|
||
public static VersionType readVersionTypeFrom(StreamInput in) throws IOException { | ||
return PROTOTYPE.readFrom(in); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeVInt(this.ordinal()); | ||
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.
|
||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment seems wrong, as far as I can see the difference to
writeStringArrayNullable
is that it writes boolean instead of int in case of null argument.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this method needed if we have
writeStringArrayNullable
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That one doesn't seem to differentiate between null and zero-length array, which we need if we e.g. test for equality of queries after serialization. At least that's what I think, @Ale might have had other reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exactly the reason. I first tried
writeStringArrayNullable
, but then you read back an empty array, not a null array.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of having both of these methods. The difference between them is too subtle. I think we should instead replace
writeStringArrayNullable
withwriteOptionalStringArray
as the former is trappy and could easily lead to bugs. Serialisation code should always serialise and de-serialise to the same thing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 should this change be part of this PR? Looks like this is not used anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not used anywhere else (or even if its only used in a couple of places) then I would be +1 to doing it in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad this is actually used in a couple of places. I'll open an issue on this.