Skip to content

Apache Lucene open-source search software

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

Ishan Chattopadhyayaa06c39f3e50a
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 7bf679ffffa..6e96cbbc65d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -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
----------------------
diff --git a/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java b/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
index 093149a1893..90612354bb1 100644
--- a/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
+++ b/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
@@ -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);
}
}
diff --git a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java
index 7bae2c9a617..bfcf01523f2 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java
@@ -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"