mirror of https://github.com/apache/lucene.git
SOLR-7209: /update/json/docs carry forward fields from previous records
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1665341 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4fbb2b36e8
commit
00005759ba
|
@ -212,6 +212,9 @@ Bug Fixes
|
|||
* SOLR-4464: DIH Processed documents counter resets to zero after first entity is processed.
|
||||
(Dave Cook, Shawn Heisey, Aaron Greenspan, Thomas Champagne via shalin)
|
||||
|
||||
* SOLR-7209: /update/json/docs carry forward fields from previous records (Noble Paul)
|
||||
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -320,7 +320,7 @@ public class JsonRecordReader {
|
|||
|
||||
final boolean isRecordStarted = recordStarted || isRecord;
|
||||
Set<String> valuesAddedinThisFrame = null;
|
||||
if (isRecord) {
|
||||
if (isRecord || !recordStarted) {
|
||||
// This Node is a match for an PATH from a forEach attribute,
|
||||
// prepare for the clean up that will occurr when the record
|
||||
// is emitted after its END_ELEMENT is matched
|
||||
|
@ -384,7 +384,7 @@ public class JsonRecordReader {
|
|||
Object val = parseSingleFieldValue(event, parser, runnable);
|
||||
if (val != null) {
|
||||
putValue(values, nameInRecord, val);
|
||||
if (isRecordStarted) valuesAddedinThisFrame.add(nameInRecord);
|
||||
valuesAddedinThisFrame.add(nameInRecord);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -414,13 +414,10 @@ public class JsonRecordReader {
|
|||
}
|
||||
}
|
||||
} finally {
|
||||
if ((isRecord() || !isRecordStarted) && !stack.empty()) {
|
||||
Set<String> cleanThis = stack.pop();
|
||||
if (cleanThis != null) {
|
||||
for (String fld : cleanThis) {
|
||||
if ((isRecord() || !isRecordStarted) ) {
|
||||
for (String fld : valuesAddedinThisFrame) {
|
||||
values.remove(fld);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,4 +220,37 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {
|
|||
records = streamer.getAllRecords(new StringReader(json));
|
||||
assertEquals(2, records.size());
|
||||
}
|
||||
public void testClearPreviousRecordFields() throws Exception{
|
||||
String json= "{\n" +
|
||||
"'first': 'John',\n" +
|
||||
"'exams': [\n" +
|
||||
"{'subject': 'Maths', 'test' : 'term1', 'marks':90},\n" +
|
||||
"{'subject': 'Biology', 'test' : 'term1', 'marks':86}\n" +
|
||||
"]\n" +
|
||||
"}\n" +
|
||||
"{\n" +
|
||||
"'first': 'Bob',\n" +
|
||||
"'exams': [\n" +
|
||||
"{'subject': 'Maths', 'test': 'term1', 'marks': 95\n" +
|
||||
"}\n" +
|
||||
",\n" +
|
||||
"{\n" +
|
||||
"'subject': 'Biology', 'test' : 'term1', 'marks': 92}\n" +
|
||||
"]\n" +
|
||||
"}";
|
||||
|
||||
|
||||
JsonRecordReader streamer;
|
||||
List<Map<String, Object>> records;
|
||||
|
||||
streamer = JsonRecordReader.getInst("/exams", Collections.singletonList("/**"));
|
||||
records = streamer.getAllRecords(new StringReader(json));
|
||||
assertEquals(4, records.size());
|
||||
|
||||
for (Map<String, Object> record : records) {
|
||||
for (Map.Entry<String, Object> e : record.entrySet()) {
|
||||
assertFalse(e.getValue() instanceof List);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue