SOLR-9838: 'inc' atomic update doesn't respect default field value

This commit is contained in:
Ishan Chattopadhyaya 2017-03-13 18:46:08 +05:30
parent d5181ec8e5
commit a06c39f3e5
3 changed files with 9 additions and 7 deletions

View File

@ -227,6 +227,8 @@ Bug Fixes
* SOLR-10226: add back "totalTime" metric to all handlers. See also the back-compat note. (ab)
* SOLR-9838: "inc" atomic update doesn't respect default field value (hoss, Amrit Sarkar, Ishan Chattopadhyaya)
Optimizations
----------------------

View File

@ -316,12 +316,11 @@ public class AtomicUpdateDocumentMerger {
protected void doInc(SolrInputDocument toDoc, SolrInputField sif, Object fieldVal) {
SolrInputField numericField = toDoc.get(sif.getName());
if (numericField == null) {
toDoc.setField(sif.getName(), fieldVal);
} else {
SchemaField sf = schema.getField(sif.getName());
if (numericField != null || sf.getDefaultValue() != null) {
// TODO: fieldtype needs externalToObject?
String oldValS = numericField.getFirstValue().toString();
SchemaField sf = schema.getField(sif.getName());
String oldValS = (numericField != null) ?
numericField.getFirstValue().toString(): sf.getDefaultValue().toString();
BytesRefBuilder term = new BytesRefBuilder();
sf.getType().readableToIndexed(oldValS, term);
Object oldVal = sf.getType().toObject(sf, term.get());
@ -340,6 +339,8 @@ public class AtomicUpdateDocumentMerger {
}
toDoc.setField(sif.getName(), result);
} else {
toDoc.setField(sif.getName(), fieldVal);
}
}

View File

@ -1204,7 +1204,6 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
}
@AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/SOLR-9838")
public void testAtomicUpdateOfFieldsWithDefaultValue() {
// both fields have the same default value (42)
for (String fieldToUpdate : Arrays.asList("intDefault", "intDvoDefault")) {
@ -1254,7 +1253,7 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
, "count(//doc/*)=6"
);
// do atomic update
assertU(adoc(sdoc("id", "7", fieldToUpdate, ImmutableMap.of("inc", -555))));
assertU(adoc(sdoc("id", "8", fieldToUpdate, ImmutableMap.of("inc", -555))));
assertQ(fieldToUpdate + ": RTG after atomic update"
, req("qt", "/get", "id", "8")
, "count(//doc)=1"