Skip to content

Split off the values supplier for ScriptDocValues #80635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -26,6 +26,7 @@
import org.elasticsearch.index.fielddata.LeafNumericFieldData;
import org.elasticsearch.index.fielddata.NumericDoubleValues;
import org.elasticsearch.index.fielddata.ScriptDocValues.Doubles;
import org.elasticsearch.index.fielddata.ScriptDocValues.DoublesSupplier;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
Expand Down Expand Up @@ -269,7 +270,7 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S
return new ScaledFloatIndexFieldData(
scaledValues,
scalingFactor,
(dv, n) -> new DelegateDocValuesField(new Doubles(dv), n)
(dv, n) -> new DelegateDocValuesField(new Doubles(new DoublesSupplier(dv)), n)
);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import org.elasticsearch.index.fielddata.ScriptDocValues.Longs;
import org.elasticsearch.index.fielddata.ScriptDocValues.LongsSupplier;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.DocumentParserContext;
import org.elasticsearch.index.mapper.FieldMapper;
Expand Down Expand Up @@ -83,7 +84,10 @@ public Murmur3FieldMapper build(MapperBuilderContext context) {
// this only exists so a check can be done to match the field type to using murmur3 hashing...
public static class Murmur3FieldType extends MappedFieldType {

public static final ToScriptField<SortedNumericDocValues> TO_SCRIPT_FIELD = (dv, n) -> new DelegateDocValuesField(new Longs(dv), n);
public static final ToScriptField<SortedNumericDocValues> TO_SCRIPT_FIELD = (dv, n) -> new DelegateDocValuesField(
new Longs(new LongsSupplier(dv)),
n
);

private Murmur3FieldType(String name, boolean isStored, Map<String, String> meta) {
super(name, false, isStored, true, TextSearchInfo.NONE, meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.index.fielddata.ScriptDocValues.Strings;
import org.elasticsearch.index.fielddata.ScriptDocValues.StringsSupplier;
import org.elasticsearch.index.mapper.IpFieldMapper;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.script.IpFieldScript;
Expand Down Expand Up @@ -53,7 +55,7 @@ public BinaryScriptLeafFieldData loadDirect(LeafReaderContext context) throws Ex
return new BinaryScriptLeafFieldData() {
@Override
public DocValuesField<?> getScriptField(String name) {
return new DelegateDocValuesField(new IpScriptDocValues(getBytesValues()), name);
return new DelegateDocValuesField(new Strings(new IpSupplier(getBytesValues())), name);
}

@Override
Expand All @@ -69,18 +71,19 @@ public ValuesSourceType getValuesSourceType() {
}

/**
* Doc values implementation for ips. We can't share
* Doc values supplier implementation for ips. We can't share
* {@link IpFieldMapper.IpFieldType.IpScriptDocValues} because it is based
* on global ordinals and we don't have those.
*/
public static class IpScriptDocValues extends ScriptDocValues.Strings {
public IpScriptDocValues(SortedBinaryDocValues in) {
public static class IpSupplier extends StringsSupplier {

public IpSupplier(SortedBinaryDocValues in) {
super(in);
}

@Override
protected String bytesToString(BytesRef bytes) {
InetAddress addr = InetAddressPoint.decode(BytesReference.toBytes(new BytesArray(bytes)));
protected String bytesToString(BytesRef bytesRef) {
InetAddress addr = InetAddressPoint.decode(BytesReference.toBytes(new BytesArray(bytesRef)));
return InetAddresses.toAddrString(addr);
}
}
Expand Down
Loading