mirror of https://github.com/apache/lucene.git
SOLR-9838: 'inc' atomic update doesn't respect default field value
This commit is contained in:
parent
d5181ec8e5
commit
a06c39f3e5
|
@ -227,6 +227,8 @@ Bug Fixes
|
||||||
|
|
||||||
* SOLR-10226: add back "totalTime" metric to all handlers. See also the back-compat note. (ab)
|
* 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
|
Optimizations
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -316,12 +316,11 @@ public class AtomicUpdateDocumentMerger {
|
||||||
|
|
||||||
protected void doInc(SolrInputDocument toDoc, SolrInputField sif, Object fieldVal) {
|
protected void doInc(SolrInputDocument toDoc, SolrInputField sif, Object fieldVal) {
|
||||||
SolrInputField numericField = toDoc.get(sif.getName());
|
SolrInputField numericField = toDoc.get(sif.getName());
|
||||||
if (numericField == null) {
|
SchemaField sf = schema.getField(sif.getName());
|
||||||
toDoc.setField(sif.getName(), fieldVal);
|
if (numericField != null || sf.getDefaultValue() != null) {
|
||||||
} else {
|
|
||||||
// TODO: fieldtype needs externalToObject?
|
// TODO: fieldtype needs externalToObject?
|
||||||
String oldValS = numericField.getFirstValue().toString();
|
String oldValS = (numericField != null) ?
|
||||||
SchemaField sf = schema.getField(sif.getName());
|
numericField.getFirstValue().toString(): sf.getDefaultValue().toString();
|
||||||
BytesRefBuilder term = new BytesRefBuilder();
|
BytesRefBuilder term = new BytesRefBuilder();
|
||||||
sf.getType().readableToIndexed(oldValS, term);
|
sf.getType().readableToIndexed(oldValS, term);
|
||||||
Object oldVal = sf.getType().toObject(sf, term.get());
|
Object oldVal = sf.getType().toObject(sf, term.get());
|
||||||
|
@ -340,6 +339,8 @@ public class AtomicUpdateDocumentMerger {
|
||||||
}
|
}
|
||||||
|
|
||||||
toDoc.setField(sif.getName(), result);
|
toDoc.setField(sif.getName(), result);
|
||||||
|
} else {
|
||||||
|
toDoc.setField(sif.getName(), fieldVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1204,7 +1204,6 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/SOLR-9838")
|
|
||||||
public void testAtomicUpdateOfFieldsWithDefaultValue() {
|
public void testAtomicUpdateOfFieldsWithDefaultValue() {
|
||||||
// both fields have the same default value (42)
|
// both fields have the same default value (42)
|
||||||
for (String fieldToUpdate : Arrays.asList("intDefault", "intDvoDefault")) {
|
for (String fieldToUpdate : Arrays.asList("intDefault", "intDvoDefault")) {
|
||||||
|
@ -1254,7 +1253,7 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {
|
||||||
, "count(//doc/*)=6"
|
, "count(//doc/*)=6"
|
||||||
);
|
);
|
||||||
// do atomic update
|
// 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"
|
assertQ(fieldToUpdate + ": RTG after atomic update"
|
||||||
, req("qt", "/get", "id", "8")
|
, req("qt", "/get", "id", "8")
|
||||||
, "count(//doc)=1"
|
, "count(//doc)=1"
|
||||||
|
|
Loading…
Reference in New Issue