-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Store ignored malformed fields in binary doc values #142357
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| import java.io.IOException; | ||
|
|
||
| public final class BinaryDocValuesSyntheticFieldLoaderLayer implements CompositeSyntheticFieldLoader.DocValuesLayer { | ||
| public class BinaryDocValuesSyntheticFieldLoaderLayer implements CompositeSyntheticFieldLoader.DocValuesLayer { | ||
|
Contributor
Author
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. Needed to removed |
||
|
|
||
| private final String name; | ||
| private SortedBinaryDocValues bytesValues; | ||
|
|
@@ -42,6 +42,7 @@ public DocValuesLoader docValuesLoader(LeafReader leafReader, int[] docIdsInLeaf | |
| } | ||
|
|
||
| bytesValues = MultiValuedSortedBinaryDocValues.from(leafReader, name, docValues); | ||
|
|
||
| return docId -> { | ||
| hasValue = bytesValues.advanceExact(docId); | ||
| return hasValue; | ||
|
|
@@ -61,10 +62,17 @@ public void write(XContentBuilder b) throws IOException { | |
|
|
||
| for (int i = 0; i < bytesValues.docValueCount(); ++i) { | ||
| BytesRef value = bytesValues.nextValue(); | ||
| b.utf8Value(value.bytes, value.offset, value.length); | ||
| writeValue(b, value); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Write a single value to the builder. Subclasses can override to change the write format. | ||
| */ | ||
| protected void writeValue(XContentBuilder b, BytesRef value) throws IOException { | ||
| b.utf8Value(value.bytes, value.offset, value.length); | ||
| } | ||
|
|
||
| @Override | ||
| public String fieldName() { | ||
| return name; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ | |
|
|
||
| import org.apache.lucene.index.LeafReader; | ||
| import org.apache.lucene.util.BytesRef; | ||
| import org.elasticsearch.index.IndexVersion; | ||
| import org.elasticsearch.index.IndexVersions; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
|
|
@@ -173,11 +175,23 @@ default void reset() { | |
| } | ||
|
|
||
| /** | ||
| * Layer that loads malformed values stored in a dedicated field with a conventional name. | ||
| * Returns the appropriate malformed values layer for the given index version. | ||
| * Uses binary doc values for new indices and stored fields for old indices. | ||
| */ | ||
| public static Layer malformedValuesLayer(String fieldName, IndexVersion indexVersion) { | ||
| if (indexVersion.onOrAfter(IndexVersions.STORE_IGNORED_MALFORMED_IN_BINARY_DOC_VALUES)) { | ||
| return new MalformedValuesBinaryDocValuesLayer(fieldName); | ||
| } else { | ||
| return new MalformedValuesStoredFieldLayer(fieldName); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Layer that loads malformed values from stored fields for synthetic source. | ||
| * @see IgnoreMalformedStoredValues | ||
| */ | ||
| public static class MalformedValuesLayer extends StoredFieldLayer { | ||
| public MalformedValuesLayer(String fieldName) { | ||
| private static class MalformedValuesStoredFieldLayer extends StoredFieldLayer { | ||
| MalformedValuesStoredFieldLayer(String fieldName) { | ||
| super(IgnoreMalformedStoredValues.name(fieldName)); | ||
| } | ||
|
|
||
|
|
@@ -191,6 +205,20 @@ protected void writeValue(Object value, XContentBuilder b) throws IOException { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Layer that loads malformed values from binary doc values for synthetic source. | ||
| */ | ||
| private static class MalformedValuesBinaryDocValuesLayer extends BinaryDocValuesSyntheticFieldLoaderLayer { | ||
| MalformedValuesBinaryDocValuesLayer(String fieldName) { | ||
| super(IgnoreMalformedStoredValues.name(fieldName)); | ||
| } | ||
|
|
||
| @Override | ||
| protected void writeValue(XContentBuilder b, BytesRef value) throws IOException { | ||
|
Contributor
Author
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. here is that override of |
||
| XContentDataHelper.decodeAndWrite(b, value); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Layer that loads field values from a provided stored field. | ||
| */ | ||
|
|
||
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.
Can't use
replaceValueInMatchhere due to how the yaml is structured -fields with ignore_malformedis large and has manymatchassertions that specifically check_source.ip. UsingreplaceValueInMatchhere means all of those assertions will be changed, which is not what we want.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 wonder whether instead of skipping the test entirely can we maybe use
removeMatch?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 wouldn't work well - each yaml test uses a nested format for all of its match assertions (ex.
_source: { ip: [...] }).removeMatch()looks only at the name of the top-level key, (ex._source), so using it here effectively removes all match assertion and renders the tests useless. This applies to all the test I've skipped in this PR. We would need to unnest some of the match assertions and then backport that in order for the yamlRestCompatTests to pass