-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Fix StoredFieldsSpec#merge(...) issue #138306
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
base: main
Are you sure you want to change the base?
Changes from all commits
ba798b0
fbd0086
840a0d1
d912b09
6fc551c
ed3dbc3
37552f2
471a415
94b779f
a6fe534
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 |
|---|---|---|
|
|
@@ -120,7 +120,7 @@ public void testMergeSourcePaths() { | |
|
|
||
| spec = spec.merge( | ||
| new StoredFieldsSpec( | ||
| true, | ||
| false, | ||
|
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. So this may be silly question, but it seems like we very much changed the meaning of this test, right? The way I read this, we changed
Member
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. The test just walks through a few scenarios and I just appended the scenario that triggered the bug. I can add a dedicated unit test for the bug here. |
||
| false, | ||
| Set.of("other_field"), | ||
| IgnoredSourceFieldMapper.IgnoredSourceFormat.NO_IGNORED_SOURCE, | ||
|
|
@@ -133,6 +133,16 @@ public void testMergeSourcePaths() { | |
| assertThat(spec.requiredStoredFields(), containsInAnyOrder("other_field")); | ||
| assertThat(spec.sourcePaths(), containsInAnyOrder("cat", "dog", "hamster")); | ||
| assertThat(spec.sourcePaths(), sameInstance(pref)); | ||
|
|
||
| // Clears source paths, because the spec requires complete source (since no source paths are defined) | ||
| spec = spec.merge( | ||
| new StoredFieldsSpec(true, false, Set.of(), IgnoredSourceFieldMapper.IgnoredSourceFormat.NO_IGNORED_SOURCE, Set.of()) | ||
| ); | ||
| assertThat(spec.ignoredSourceFormat(), equalTo(IgnoredSourceFieldMapper.IgnoredSourceFormat.NO_IGNORED_SOURCE)); | ||
| assertThat(spec.requiresSource(), equalTo(true)); | ||
| assertThat(spec.requiresMetadata(), equalTo(false)); | ||
| assertThat(spec.requiredStoredFields(), containsInAnyOrder("other_field")); | ||
| assertThat(spec.sourcePaths(), empty()); | ||
| } | ||
|
|
||
| private static SearchContext searchContext(SearchSourceBuilder sourceBuilder) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,3 +210,35 @@ setup: | |
| "keyword" : "ok", | ||
| "case" : "ok" | ||
| }} | ||
|
|
||
| --- | ||
| "source meta field and dynamic false": | ||
| - do: | ||
| indices.create: | ||
| index: my-index2 | ||
| body: | ||
| mappings: | ||
| dynamic: false | ||
|
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. Is this important? The
Member
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. For the query being tested here, yes. Otherwise the test wouldn't fail. |
||
| properties: | ||
| foo: | ||
| type: text | ||
|
|
||
| - do: | ||
| bulk: | ||
| index: my-index2 | ||
| refresh: true | ||
| body: | ||
| - { "index": { } } | ||
| - { "baz": "dasd" } | ||
| - do: | ||
| esql.query: | ||
| body: | ||
| query: 'FROM my-index2 METADATA _source | LIMIT 10' | ||
|
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. Not to be annoying, but are we testing here with what we actually want to be testing? Here we seem to have an index with a single text field, so even if we had not fixed the bug, I think this still would've worked, right - we would've stripped the source of everything but the field, which doesn't actually change the _source. Feels like we need the mapping with at least one another field, and the query that reads the entire source and the text field. We should be testing that the filtered out field is still returned in source This thing - #138188 - has the correctly shaped example I think.
Member
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.
Without the fix to I can add a |
||
|
|
||
| - match: {columns.0.name: "foo"} | ||
| - match: {columns.0.type: "text"} | ||
| - match: {columns.1.name: "_source"} | ||
| - match: {columns.1.type: "_source"} | ||
|
|
||
| - match: {values.0.0: null} | ||
| - match: {values.0.1: { "baz": "dasd" }} | ||
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.
Ah! So our intuition was right - every time we apply the filter, we are stripping down the rest of the source. The fix is to always keep the source if it's been asked for
Uh oh!
There was an error while loading. Please reload this page.
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.
As a side note, there seems to be quite a bit of boiler plate in this method, with some repeated outcomes. Do we want to shove them into separate tiny inlinable functions?
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.
Let me see if that actually makes to code cleaner.