Skip to content

Commit

Permalink
Modifications after master merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mayya-sharipova committed Aug 18, 2020
1 parent 612b7da commit ada3422
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ protected static Long parseUpperRangeTerm(Object value, boolean include) {

private Explicit<Boolean> ignoreMalformed;
private final String nullValue;
private final Long nullValueNumeric;
private final Long nullValueIndexed; // null value to use for indexing, represented as shifted to signed long range
private final Number nullValueFormatted; // null value to use in place of a {@code null} value in the document source

private UnsignedLongFieldMapper(
String simpleName,
Expand All @@ -391,7 +392,15 @@ private UnsignedLongFieldMapper(
) {
super(simpleName, fieldType, mappedFieldType, multiFields, copyTo);
this.nullValue = nullValue;
this.nullValueNumeric = nullValue == null ? null : convertToSignedLong(parseUnsignedLong(nullValue));
if (nullValue == null) {
this.nullValueIndexed = null;
this.nullValueFormatted = null;
} else {
long parsed = parseUnsignedLong(nullValue);
this.nullValueIndexed = convertToSignedLong(parsed);
this.nullValueFormatted = parsed >= 0 ? parsed : BigInteger.valueOf(parsed).and(BIGINTEGER_2_64_MINUS_ONE);
}

this.ignoreMalformed = ignoreMalformed;
}

Expand All @@ -410,6 +419,11 @@ protected UnsignedLongFieldMapper clone() {
return (UnsignedLongFieldMapper) super.clone();
}

@Override
protected Number nullValue() {
return nullValueFormatted;
}

@Override
protected void parseCreateField(ParseContext context) throws IOException {
XContentParser parser = context.parser();
Expand Down Expand Up @@ -437,7 +451,7 @@ protected void parseCreateField(ParseContext context) throws IOException {
}
}
if (numericValue == null) {
numericValue = nullValueNumeric;
numericValue = nullValueIndexed;
if (numericValue == null) return;
} else {
numericValue = convertToSignedLong(numericValue);
Expand All @@ -454,6 +468,23 @@ protected void parseCreateField(ParseContext context) throws IOException {
}
}

@Override
protected Number parseSourceValue(Object value, String format) {
if (format != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats.");
}

if (value.equals("")) {
return nullValueFormatted;
}
long ulValue = parseUnsignedLong(value);
if (ulValue >= 0) {
return ulValue;
} else {
return BigInteger.valueOf(ulValue).and(BIGINTEGER_2_64_MINUS_ONE);
}
}

@Override
protected void mergeOptions(FieldMapper other, List<String> conflicts) {
UnsignedLongFieldMapper mergeWith = (UnsignedLongFieldMapper) other;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ protected boolean sortRequiresCustomComparator() {
return true;
}

@Override
public void clear() {
signedLongIFD.clear();
}

@Override
public NumericType getNumericType() {
return NumericType.LONG;
Expand Down

0 comments on commit ada3422

Please sign in to comment.