Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,13 @@ public MatchOnlyTextFieldType fieldType() {

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
var loader = new StringStoredFieldFieldLoader(fieldType().storedFieldNameForSyntheticSource(), fieldType().name(), leafName()) {
@Override
protected void write(XContentBuilder b, Object value) throws IOException {
b.value((String) value);
return new SyntheticSourceSupport.Native(
() -> new StringStoredFieldFieldLoader(fieldType().storedFieldNameForSyntheticSource(), fieldType().name(), leafName()) {
@Override
protected void write(XContentBuilder b, Object value) throws IOException {
b.value((String) value);
}
}
};

return new SyntheticSourceSupport.Native(loader);
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -707,14 +707,14 @@ public int docValueCount() {
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (hasDocValues) {
var loader = new SortedNumericDocValuesSyntheticFieldLoader(fullPath(), leafName(), ignoreMalformed.value()) {
@Override
protected void writeValue(XContentBuilder b, long value) throws IOException {
b.value(decodeForSyntheticSource(value, scalingFactor));
return new SyntheticSourceSupport.Native(
() -> new SortedNumericDocValuesSyntheticFieldLoader(fullPath(), leafName(), ignoreMalformed.value()) {
@Override
protected void writeValue(XContentBuilder b, long value) throws IOException {
b.value(decodeForSyntheticSource(value, scalingFactor));
}
}
};

return new SyntheticSourceSupport.Native(loader);
);
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,19 +563,17 @@ public FieldMapper.Builder getMergeBuilder() {
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (fieldType.stored()) {
var loader = new StringStoredFieldFieldLoader(fullPath(), leafName()) {
return new SyntheticSourceSupport.Native(() -> new StringStoredFieldFieldLoader(fullPath(), leafName()) {
@Override
protected void write(XContentBuilder b, Object value) throws IOException {
b.value((String) value);
}
};

return new SyntheticSourceSupport.Native(loader);
});
}

var kwd = TextFieldMapper.SyntheticSourceHelper.getKeywordFieldMapperForSyntheticSource(this);
if (kwd != null) {
return new SyntheticSourceSupport.Native(kwd.syntheticFieldLoader(fullPath(), leafName()));
return new SyntheticSourceSupport.Native(() -> kwd.syntheticFieldLoader(fullPath(), leafName()));
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected String contentType() {
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (hasDocValues) {
var loader = new BinaryDocValuesSyntheticFieldLoader(fullPath()) {
return new SyntheticSourceSupport.Native(() -> new BinaryDocValuesSyntheticFieldLoader(fullPath()) {
@Override
protected void writeValue(XContentBuilder b, BytesRef value) throws IOException {
var in = new ByteArrayStreamInput();
Expand All @@ -221,9 +221,7 @@ protected void writeValue(XContentBuilder b, BytesRef value) throws IOException
b.endArray();
}
}
};

return new SyntheticSourceSupport.Native(loader);
});
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,14 @@ protected String contentType() {
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (hasDocValues) {
var loader = new SortedNumericDocValuesSyntheticFieldLoader(fullPath(), leafName(), ignoreMalformed.value()) {
@Override
protected void writeValue(XContentBuilder b, long value) throws IOException {
b.value(value == 1);
return new SyntheticSourceSupport.Native(
() -> new SortedNumericDocValuesSyntheticFieldLoader(fullPath(), leafName(), ignoreMalformed.value()) {
@Override
protected void writeValue(XContentBuilder b, long value) throws IOException {
b.value(value == 1);
}
}
};

return new SyntheticSourceSupport.Native(loader);
);
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,14 +1012,14 @@ public Long getNullValue() {
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (hasDocValues) {
var loader = new SortedNumericDocValuesSyntheticFieldLoader(fullPath(), leafName(), ignoreMalformed) {
@Override
protected void writeValue(XContentBuilder b, long value) throws IOException {
b.value(fieldType().format(value, fieldType().dateTimeFormatter()));
return new SyntheticSourceSupport.Native(
() -> new SortedNumericDocValuesSyntheticFieldLoader(fullPath(), leafName(), ignoreMalformed) {
@Override
protected void writeValue(XContentBuilder b, long value) throws IOException {
b.value(fieldType().format(value, fieldType().dateTimeFormatter()));
}
}
};

return new SyntheticSourceSupport.Native(loader);
);
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static IndexableField field(int count) {

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
return new SyntheticSourceSupport.Native(new SyntheticFieldLoader());
return new SyntheticSourceSupport.Native(SyntheticFieldLoader::new);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ protected String contentType() {
protected SyntheticSourceSupport syntheticSourceSupport() {
// Opt out of fallback synthetic source implementation
// since there is custom logic in #parseCreateField().
return new SyntheticSourceSupport.Native(SourceLoader.SyntheticFieldLoader.NOTHING);
return new SyntheticSourceSupport.Native(() -> SourceLoader.SyntheticFieldLoader.NOTHING);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,27 @@ public SourceLoader.SyntheticFieldLoader loader() {

SyntheticSourceSupport FALLBACK = new Fallback();

record Native(SourceLoader.SyntheticFieldLoader loader) implements SyntheticSourceSupport {
final class Native implements SyntheticSourceSupport {
Supplier<SourceLoader.SyntheticFieldLoader> loaderSupplier;
private SourceLoader.SyntheticFieldLoader loader;

@SuppressWarnings("checkstyle:RedundantModifier")
public Native(Supplier<SourceLoader.SyntheticFieldLoader> loaderSupplier) {
this.loaderSupplier = loaderSupplier;
}

@Override
public SyntheticSourceMode mode() {
return SyntheticSourceMode.NATIVE;
}

@Override
public SourceLoader.SyntheticFieldLoader loader() {
if (loader == null) {
loader = loaderSupplier.get();
}
return loader;
}
}

SyntheticSourceMode mode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,17 +622,17 @@ protected void onMalformedValue(DocumentParserContext context, XContentBuilder m
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (fieldType().hasDocValues()) {
var loader = new SortedNumericDocValuesSyntheticFieldLoader(fullPath(), leafName(), ignoreMalformed()) {
final GeoPoint point = new GeoPoint();

@Override
protected void writeValue(XContentBuilder b, long value) throws IOException {
point.reset(GeoEncodingUtils.decodeLatitude((int) (value >>> 32)), GeoEncodingUtils.decodeLongitude((int) value));
point.toXContent(b, ToXContent.EMPTY_PARAMS);
return new SyntheticSourceSupport.Native(
() -> new SortedNumericDocValuesSyntheticFieldLoader(fullPath(), leafName(), ignoreMalformed()) {
final GeoPoint point = new GeoPoint();

@Override
protected void writeValue(XContentBuilder b, long value) throws IOException {
point.reset(GeoEncodingUtils.decodeLatitude((int) (value >>> 32)), GeoEncodingUtils.decodeLongitude((int) value));
point.toXContent(b, ToXContent.EMPTY_PARAMS);
}
}
};

return new SyntheticSourceSupport.Native(loader);
);
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected SyntheticSourceSupport syntheticSourceSupport() {
// not being available.
// We would like to have an option to lose some values in synthetic source
// but have search not fail.
return new SyntheticSourceSupport.Native(new SourceLoader.SyntheticFieldLoader() {
return new SyntheticSourceSupport.Native(() -> new SourceLoader.SyntheticFieldLoader() {
@Override
public Stream<Map.Entry<String, StoredFieldLoader>> storedFieldLoaders() {
if (indexSettings.getSkipIgnoredSourceRead()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,26 +610,27 @@ public void doValidate(MappingLookup lookup) {
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (hasDocValues) {
var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>();
layers.add(new SortedSetDocValuesSyntheticFieldLoaderLayer(fullPath()) {
@Override
protected BytesRef convert(BytesRef value) {
byte[] bytes = Arrays.copyOfRange(value.bytes, value.offset, value.offset + value.length);
return new BytesRef(NetworkAddress.format(InetAddressPoint.decode(bytes)));
}
return new SyntheticSourceSupport.Native(() -> {
var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>();
layers.add(new SortedSetDocValuesSyntheticFieldLoaderLayer(fullPath()) {
@Override
protected BytesRef convert(BytesRef value) {
byte[] bytes = Arrays.copyOfRange(value.bytes, value.offset, value.offset + value.length);
return new BytesRef(NetworkAddress.format(InetAddressPoint.decode(bytes)));
}

@Override
protected BytesRef preserve(BytesRef value) {
// No need to copy because convert has made a deep copy
return value;
@Override
protected BytesRef preserve(BytesRef value) {
// No need to copy because convert has made a deep copy
return value;
}
});

if (ignoreMalformed) {
layers.add(new CompositeSyntheticFieldLoader.MalformedValuesLayer(fullPath()));
}
return new CompositeSyntheticFieldLoader(leafName(), fullPath(), layers);
});

if (ignoreMalformed) {
layers.add(new CompositeSyntheticFieldLoader.MalformedValuesLayer(fullPath()));
}

return new SyntheticSourceSupport.Native(new CompositeSyntheticFieldLoader(leafName(), fullPath(), layers));
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ protected SyntheticSourceSupport syntheticSourceSupport() {
}

if (fieldType.stored() || hasDocValues) {
return new SyntheticSourceSupport.Native(syntheticFieldLoader(fullPath(), leafName()));
return new SyntheticSourceSupport.Native(() -> syntheticFieldLoader(fullPath(), leafName()));
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,6 @@ public void postParse(DocumentParserContext context) throws IOException {

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
return new SyntheticSourceSupport.Native(SourceLoader.SyntheticFieldLoader.NOTHING);
return new SyntheticSourceSupport.Native(() -> SourceLoader.SyntheticFieldLoader.NOTHING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ public void doValidate(MappingLookup lookup) {
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (hasDocValues) {
return new SyntheticSourceSupport.Native(type.syntheticFieldLoader(fullPath(), leafName(), ignoreMalformed.value()));
return new SyntheticSourceSupport.Native(() -> type.syntheticFieldLoader(fullPath(), leafName(), ignoreMalformed.value()));
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ private static Range parseIpRangeFromCidr(final XContentParser parser) throws IO
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (hasDocValues) {
var loader = new BinaryDocValuesSyntheticFieldLoader(fullPath()) {
return new SyntheticSourceSupport.Native(() -> new BinaryDocValuesSyntheticFieldLoader(fullPath()) {
@Override
protected void writeValue(XContentBuilder b, BytesRef value) throws IOException {
List<Range> ranges = type.decodeRanges(value);
Expand All @@ -487,9 +487,7 @@ protected void writeValue(XContentBuilder b, BytesRef value) throws IOException
b.endArray();
}
}
};

return new SyntheticSourceSupport.Native(loader);
});
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1481,19 +1481,17 @@ protected void doXContentBody(XContentBuilder builder, Params params) throws IOE
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (store) {
var loader = new StringStoredFieldFieldLoader(fullPath(), leafName()) {
return new SyntheticSourceSupport.Native(() -> new StringStoredFieldFieldLoader(fullPath(), leafName()) {
@Override
protected void write(XContentBuilder b, Object value) throws IOException {
b.value((String) value);
}
};

return new SyntheticSourceSupport.Native(loader);
});
}

var kwd = SyntheticSourceHelper.getKeywordFieldMapperForSyntheticSource(this);
if (kwd != null) {
return new SyntheticSourceSupport.Native(kwd.syntheticFieldLoader(fullPath(), leafName()));
return new SyntheticSourceSupport.Native(() -> kwd.syntheticFieldLoader(fullPath(), leafName()));
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,14 +914,14 @@ public FieldMapper.Builder getMergeBuilder() {
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (fieldType().hasDocValues()) {
var loader = new FlattenedSortedSetDocValuesSyntheticFieldLoader(
fullPath(),
fullPath() + KEYED_FIELD_SUFFIX,
ignoreAbove() < Integer.MAX_VALUE ? fullPath() + KEYED_IGNORED_VALUES_FIELD_SUFFIX : null,
leafName()
return new SyntheticSourceSupport.Native(
() -> new FlattenedSortedSetDocValuesSyntheticFieldLoader(
fullPath(),
fullPath() + KEYED_FIELD_SUFFIX,
ignoreAbove() < Integer.MAX_VALUE ? fullPath() + KEYED_IGNORED_VALUES_FIELD_SUFFIX : null,
leafName()
)
);

return new SyntheticSourceSupport.Native(loader);
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2375,11 +2375,11 @@ public String toString() {

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
var loader = fieldType().indexed
? new IndexedSyntheticFieldLoader(indexCreatedVersion, fieldType().similarity)
: new DocValuesSyntheticFieldLoader(indexCreatedVersion);

return new SyntheticSourceSupport.Native(loader);
return new SyntheticSourceSupport.Native(
() -> fieldType().indexed
? new IndexedSyntheticFieldLoader(indexCreatedVersion, fieldType().similarity)
: new DocValuesSyntheticFieldLoader(indexCreatedVersion)
);
}

private class IndexedSyntheticFieldLoader extends SourceLoader.DocValuesBasedSyntheticFieldLoader {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private SparseVectorFieldMapper(String simpleName, MappedFieldType mappedFieldTy
@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
if (fieldType().isStored()) {
return new SyntheticSourceSupport.Native(new SparseVectorSyntheticFieldLoader(fullPath(), leafName()));
return new SyntheticSourceSupport.Native(() -> new SparseVectorSyntheticFieldLoader(fullPath(), leafName()));
}
return super.syntheticSourceSupport();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3303,15 +3303,13 @@ protected String contentType() {

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
var loader = new StringStoredFieldFieldLoader(fullPath(), leafName()) {
return new SyntheticSourceSupport.Native(() -> new StringStoredFieldFieldLoader(fullPath(), leafName()) {
@Override
protected void write(XContentBuilder b, Object value) throws IOException {
BytesRef ref = (BytesRef) value;
b.utf8Value(ref.bytes, ref.offset, ref.length);
}
};

return new SyntheticSourceSupport.Native(loader);
});
}

private static final TypeParser PARSER = new FixedTypeParser(c -> new MockMetadataMapper());
Expand Down
Loading