Skip to content

Commit dfbb686

Browse files
committed
WIP
1 parent 04684ed commit dfbb686

File tree

3 files changed

+567
-11
lines changed

3 files changed

+567
-11
lines changed

server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper;
2626
import org.elasticsearch.index.query.SearchExecutionContext;
2727
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
28+
import org.elasticsearch.ingest.ESONSource;
29+
import org.elasticsearch.ingest.ESONXContentParser;
2830
import org.elasticsearch.plugins.internal.XContentMeteringParserDecorator;
2931
import org.elasticsearch.search.lookup.SearchLookup;
3032
import org.elasticsearch.search.lookup.Source;
@@ -131,12 +133,21 @@ private XContentParser getParser(SourceToParse source, @Nullable Map<String, Obj
131133
xContentType
132134
);
133135
} else {
134-
return new MapXContentParser(
135-
NamedXContentRegistry.EMPTY,
136-
DeprecationHandler.IGNORE_DEPRECATIONS,
137-
structuredSource,
138-
xContentType
139-
);
136+
if (structuredSource instanceof ESONSource.ESONObject esonObject) {
137+
return new ESONXContentParser(
138+
esonObject,
139+
NamedXContentRegistry.EMPTY,
140+
DeprecationHandler.IGNORE_DEPRECATIONS,
141+
xContentType
142+
);
143+
} else {
144+
return new MapXContentParser(
145+
NamedXContentRegistry.EMPTY,
146+
DeprecationHandler.IGNORE_DEPRECATIONS,
147+
structuredSource,
148+
xContentType
149+
);
150+
}
140151
}
141152
}
142153

server/src/main/java/org/elasticsearch/ingest/ESONSource.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ public int size() {
321321
// TODO: test remove
322322
@Override
323323
public Set<Entry<String, Object>> entrySet() {
324+
return entrySet(true);
325+
}
326+
327+
public Set<Entry<String, Object>> entrySet(boolean shouldComputeValue) {
324328
return new AbstractSet<>() {
325329
@Override
326330
public Iterator<Entry<String, Object>> iterator() {
@@ -335,7 +339,7 @@ public boolean hasNext() {
335339
@Override
336340
public Entry<String, Object> next() {
337341
Map.Entry<String, Type> mapEntry = mapIterator.next();
338-
return new LazyEntry(mapEntry.getKey(), mapEntry.getValue());
342+
return new LazyEntry(mapEntry.getKey(), mapEntry.getValue(), shouldComputeValue);
339343
}
340344

341345
@Override
@@ -421,11 +425,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
421425

422426
private class LazyEntry implements Entry<String, Object> {
423427
private final String key;
428+
private final Type type;
429+
private final boolean shouldComputeValue;
424430
private Object cachedValue;
425431
private boolean valueComputed = false;
426432

427-
LazyEntry(String key, Type type) {
433+
LazyEntry(String key, Type type, boolean shouldComputeValue) {
428434
this.key = key;
435+
this.type = type;
436+
this.shouldComputeValue = shouldComputeValue;
429437
}
430438

431439
@Override
@@ -435,8 +443,14 @@ public String getKey() {
435443

436444
@Override
437445
public Object getValue() {
438-
if (valueComputed == false) {
439-
cachedValue = ESONObject.this.get(key); // Use the object's get method to handle modifications
446+
if (shouldComputeValue && valueComputed == false) {
447+
if (type == null) {
448+
cachedValue = null;
449+
} else if (type instanceof Mutation mutation) {
450+
cachedValue = mutation.object();
451+
} else {
452+
cachedValue = convertTypeToValue(type);
453+
}
440454
valueComputed = true;
441455
}
442456
return cachedValue;
@@ -445,7 +459,9 @@ public Object getValue() {
445459
@Override
446460
public Object setValue(Object value) {
447461
Object oldValue = ESONObject.this.put(key, value);
448-
cachedValue = value;
462+
if (shouldComputeValue) {
463+
cachedValue = value;
464+
}
449465
return oldValue;
450466
}
451467

@@ -492,6 +508,18 @@ public ESONArray(List<Type> elements, Supplier<Values> arrayValues) {
492508
this.arrayValues = arrayValues;
493509
}
494510

511+
public Supplier<Values> arrayValues() {
512+
return arrayValues;
513+
}
514+
515+
public Iterator<?> iterator(boolean shouldMaterialize) {
516+
if (shouldMaterialize) {
517+
return super.iterator();
518+
} else {
519+
return elements.iterator();
520+
}
521+
}
522+
495523
@Override
496524
public Object get(int index) {
497525
Type type = elements.get(index);

0 commit comments

Comments
 (0)