Merge pull request #15958 from jpountz/fix/remove_dead_fielddata_code

Remove dead fielddata code.
This commit is contained in:
Adrien Grand 2016-01-13 18:33:35 +01:00
commit aa52ab365a
1 changed files with 8 additions and 172 deletions

View File

@ -19,193 +19,29 @@
package org.elasticsearch.index.fielddata; package org.elasticsearch.index.fielddata;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.SortField;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.NumericUtils;
import org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder;
import org.elasticsearch.index.mapper.core.BooleanFieldMapper;
/** /**
*/ */
public interface IndexNumericFieldData extends IndexFieldData<AtomicNumericFieldData> { public interface IndexNumericFieldData extends IndexFieldData<AtomicNumericFieldData> {
public static enum NumericType { public static enum NumericType {
BOOLEAN(1, false, SortField.Type.INT, 0, 1) { BOOLEAN(false),
@Override BYTE(false),
public long toLong(BytesRef indexForm) { SHORT(false),
if (indexForm.equals(BooleanFieldMapper.Values.FALSE)) { INT(false),
return 0; LONG(false),
} else if (indexForm.equals(BooleanFieldMapper.Values.TRUE)) { FLOAT(true),
return 1; DOUBLE(true);
} else {
throw new IllegalArgumentException("Cannot convert " + indexForm + " to a boolean");
}
}
@Override
public void toIndexForm(Number number, BytesRefBuilder bytes) {
bytes.append(number.intValue() != 0 ? BooleanFieldMapper.Values.TRUE : BooleanFieldMapper.Values.FALSE);
}
@Override
public Number toNumber(BytesRef indexForm) {
return toLong(indexForm);
}
},
BYTE(8, false, SortField.Type.INT, Byte.MIN_VALUE, Byte.MAX_VALUE) {
@Override
public long toLong(BytesRef indexForm) {
return INT.toLong(indexForm);
}
@Override
public void toIndexForm(Number number, BytesRefBuilder bytes) {
INT.toIndexForm(number, bytes);
}
@Override
public Number toNumber(BytesRef indexForm) {
return INT.toNumber(indexForm);
}
},
SHORT(16, false, SortField.Type.INT, Short.MIN_VALUE, Short.MAX_VALUE) {
@Override
public long toLong(BytesRef indexForm) {
return INT.toLong(indexForm);
}
@Override
public void toIndexForm(Number number, BytesRefBuilder bytes) {
INT.toIndexForm(number, bytes);
}
@Override
public Number toNumber(BytesRef indexForm) {
return INT.toNumber(indexForm);
}
},
INT(32, false, SortField.Type.INT, Integer.MIN_VALUE, Integer.MAX_VALUE) {
@Override
public long toLong(BytesRef indexForm) {
return NumericUtils.prefixCodedToInt(indexForm);
}
@Override
public void toIndexForm(Number number, BytesRefBuilder bytes) {
NumericUtils.intToPrefixCodedBytes(number.intValue(), 0, bytes);
}
@Override
public Number toNumber(BytesRef indexForm) {
return NumericUtils.prefixCodedToInt(indexForm);
}
},
LONG(64, false, SortField.Type.LONG, Long.MIN_VALUE, Long.MAX_VALUE) {
@Override
public long toLong(BytesRef indexForm) {
return NumericUtils.prefixCodedToLong(indexForm);
}
@Override
public void toIndexForm(Number number, BytesRefBuilder bytes) {
NumericUtils.longToPrefixCodedBytes(number.longValue(), 0, bytes);
}
@Override
public Number toNumber(BytesRef indexForm) {
return NumericUtils.prefixCodedToLong(indexForm);
}
},
FLOAT(32, true, SortField.Type.FLOAT, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY) {
@Override
public double toDouble(BytesRef indexForm) {
return NumericUtils.sortableIntToFloat(NumericUtils.prefixCodedToInt(indexForm));
}
@Override
public void toIndexForm(Number number, BytesRefBuilder bytes) {
NumericUtils.intToPrefixCodedBytes(NumericUtils.floatToSortableInt(number.floatValue()), 0, bytes);
}
@Override
public Number toNumber(BytesRef indexForm) {
return NumericUtils.sortableIntToFloat(NumericUtils.prefixCodedToInt(indexForm));
}
},
DOUBLE(64, true, SortField.Type.DOUBLE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY) {
@Override
public double toDouble(BytesRef indexForm) {
return NumericUtils.sortableLongToDouble(NumericUtils.prefixCodedToLong(indexForm));
}
@Override
public void toIndexForm(Number number, BytesRefBuilder bytes) {
NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(number.doubleValue()), 0, bytes);
}
@Override
public Number toNumber(BytesRef indexForm) {
return NumericUtils.sortableLongToDouble(NumericUtils.prefixCodedToLong(indexForm));
}
};
private final int requiredBits;
private final boolean floatingPoint; private final boolean floatingPoint;
private final SortField.Type type;
private final Number minValue, maxValue;
private NumericType(int requiredBits, boolean floatingPoint, SortField.Type type, Number minValue, Number maxValue) { private NumericType(boolean floatingPoint) {
this.requiredBits = requiredBits;
this.floatingPoint = floatingPoint; this.floatingPoint = floatingPoint;
this.type = type;
this.minValue = minValue;
this.maxValue = maxValue;
}
public final SortField.Type sortFieldType() {
return type;
}
public final Number minValue() {
return minValue;
}
public final Number maxValue() {
return maxValue;
} }
public final boolean isFloatingPoint() { public final boolean isFloatingPoint() {
return floatingPoint; return floatingPoint;
} }
public final int requiredBits() {
return requiredBits;
}
public abstract void toIndexForm(Number number, BytesRefBuilder bytes);
public long toLong(BytesRef indexForm) {
return (long) toDouble(indexForm);
}
public double toDouble(BytesRef indexForm) {
return (double) toLong(indexForm);
}
public abstract Number toNumber(BytesRef indexForm);
public final TermsEnum wrapTermsEnum(TermsEnum termsEnum) {
if (requiredBits() == 1) { // boolean, no prefix-terms
return termsEnum;
} else if (requiredBits() > 32) {
return OrdinalsBuilder.wrapNumeric64Bit(termsEnum);
} else {
return OrdinalsBuilder.wrapNumeric32Bit(termsEnum);
}
}
} }
NumericType getNumericType(); NumericType getNumericType();