-
Notifications
You must be signed in to change notification settings - Fork 686
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
SOLR-17274: allow JSON atomic updates to use multiple modifiers or a modifier like 'set' as a field name if child docs not enabled #2451
Conversation
- this modifies `isChildDoc` to always return false if child docs are not possible according to the schema, and restores part of the logic of `parseObjectFieldValue` so that it can handle multiple modifiers - re-enables the ability to use multiple modifiers in a single update, like `{"add": "foo", "remove": "bar"}` - re-enables the ability to have a field with a name like `set` or `remove` and be able to use updates like `{"set": {"set": "foo"}` - both of these are possible now but only if the schema doesn't support child/nested docs; if the schema does support them, then functionality is unchanged and either will continue throwing an exception
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.
Nice test
solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesJsonTest.java
Outdated
Show resolved
Hide resolved
solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesJsonTest.java
Outdated
Show resolved
Hide resolved
solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesJsonTest.java
Outdated
Show resolved
Hide resolved
doc.setField("id", "1"); | ||
doc.setField( | ||
"set", | ||
new HashMap<String, String>() { |
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.
Map.of
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.
Map.of
doesn't seem to allow null
values, so I can't do Map.of("set", null)
here. What do you suggest instead of HashMap
?
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 well; its okay. I hate the syntax hack with the HashMap subclass but I see its appeal in being able to use it inline like this.
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.
Oh, it looks like one of the checks is failing because of the instance initializer block, so I'll change it to use HashMap
but avoid that.
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.
Updated.
solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesJsonTest.java
Outdated
Show resolved
Hide resolved
solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesJsonTest.java
Outdated
Show resolved
Hide resolved
solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesJsonTest.java
Outdated
Show resolved
Hide resolved
solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesJsonTest.java
Outdated
Show resolved
Hide resolved
- Map.of doesn't allow null values, so there's still one remaining use of HashMap
Thinking of wording for CHANGES.txt:
|
Alternatively I rather like the title here:
|
solr/core/src/test/org/apache/solr/update/processor/AtomicUpdateJsonTest.java
Outdated
Show resolved
Hide resolved
I'll merge this tonight unless I hear to the contrary. |
…modifier like 'set' as a field name if child docs not enabled (#2451) * fix two problems with json atomic update [SOLR-17274] - this modifies `isChildDoc` to always return false if child docs are not possible according to the schema, and restores part of the logic of `parseObjectFieldValue` so that it can handle multiple modifiers - re-enables the ability to use multiple modifiers in a single update, like `{"add": "foo", "remove": "bar"}` - re-enables the ability to have a field with a name like `set` or `remove` and be able to use updates like `{"set": {"set": "foo"}` - both of these are possible now but only if the schema doesn't support child/nested docs; if the schema does support them, then functionality is unchanged and either will continue throwing an exception --------- Co-authored-by: Calvin Smith <[email protected]> Co-authored-by: David Smiley <[email protected]> (cherry picked from commit 3b30f25)
When this will be published for public use? |
Whenever 9.7 is released. Should be within a month. |
Fixes problems with the JsonLoader's parsing of atomic update values that use multiple modifiers in a single update or reference a field name that matches a modifier (like
set
oradd
).https://issues.apache.org/jira/browse/SOLR-17274
Description
Fixes two problems with JSON atomic updates where an atomic update value like
{"set": {"set": "foo"}}
(set a field namedset
to valuefoo
) or{"foo": {"add": "bar", "remove": "baz"}}
(addbar
value to and removebaz
values from fieldfoo
) would throw an exception due toisChildDoc
thinking a nested doc was being updated. The exact exception message was:Unable to index docs with children: the schema must include definitions for both a uniqueKey field and the '_root_' field, using the exact same fieldType
Solution
I modified the
isChildDoc
method ofJsonLoader
to check if the schema is usable for child docs, and to returnfalse
if not. I also had to revert a part of the logic inparseObjectFieldValue
so that it would return all the modifier values when there are multiple. TheisChildDoc
behavior is unchanged if the schema does support child docs, so the same error with continue to be thrown in that case.Tests
There weren't any atomic update tests that used the JSON loader previously, so I added a new schema file with the minimal fields needed to test this functionality and some tests for existing functionality via Json and for what is changed by this PR.
Checklist
Please review the following and check all that apply:
main
branch../gradlew check
.The only tests that failed were the S3 tests, which I believe is common and not necessarily a problem if my changes shouldn't have affected the s3 functionality.