added predefined empty implementation for all atomic field datas

This commit is contained in:
uboness 2013-01-22 14:45:09 +01:00 committed by Shay Banon
parent 6b92b592b4
commit 09cc70b8c9
39 changed files with 1484 additions and 27 deletions

View File

@ -63,4 +63,5 @@ public interface AtomicFieldData<Script extends ScriptDocValues> {
* Returns a "scripting" based values.
*/
Script getScriptValues();
}

View File

@ -24,4 +24,5 @@ package org.elasticsearch.index.fielddata;
public interface AtomicGeoPointFieldData<Script extends ScriptDocValues> extends AtomicFieldData<Script> {
GeoPointValues getGeoPointValues();
}

View File

@ -34,4 +34,5 @@ public interface AtomicNumericFieldData<Script extends ScriptDocValues> extends
FloatValues getFloatValues();
DoubleValues getDoubleValues();
}

View File

@ -37,4 +37,5 @@ public interface AtomicOrdinalFieldData<Script extends ScriptDocValues> extends
* Use a non thread safe (lightweight) view of the values as strings.
*/
OrdinalsStringValues getStringValues();
}

View File

@ -28,6 +28,8 @@ import org.elasticsearch.index.fielddata.util.LongArrayRef;
*/
public interface ByteValues {
static ByteValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
@ -100,6 +102,43 @@ public interface ByteValues {
}
}
static class Empty implements ByteValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public byte getValue(int docId) {
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty ByteValues");
}
@Override
public byte getValueMissing(int docId, byte missingValue) {
return missingValue;
}
@Override
public ByteArrayRef getValues(int docId) {
return ByteArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
public static class IntBased implements ByteValues {
private final IntValues values;

View File

@ -28,6 +28,8 @@ import org.elasticsearch.index.fielddata.util.StringArrayRef;
*/
public interface BytesValues {
static final BytesValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
@ -122,6 +124,51 @@ public interface BytesValues {
}
}
static class Empty implements BytesValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public BytesRef getValue(int docId) {
return null;
}
@Override
public BytesRefArrayRef getValues(int docId) {
return BytesRefArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
@Override
public BytesRef makeSafe(BytesRef bytes) {
//todo we can also throw an excepiton here as the only value this method accepts is a scratch value...
//todo ...extracted from this ByteValues, in our case, there are not values, so this should never be called!?!?
return BytesRef.deepCopyOf(bytes);
}
@Override
public BytesRef getValueScratch(int docId, BytesRef ret) {
ret.length = 0;
return ret;
}
}
public static class StringBased implements BytesValues {
private final StringValues values;

View File

@ -28,6 +28,8 @@ import org.elasticsearch.index.fielddata.util.LongArrayRef;
*/
public interface DoubleValues {
static final DoubleValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
@ -100,6 +102,43 @@ public interface DoubleValues {
}
}
static class Empty implements DoubleValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public double getValue(int docId) {
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty DoubleValues");
}
@Override
public double getValueMissing(int docId, double missingValue) {
return missingValue;
}
@Override
public DoubleArrayRef getValues(int docId) {
return DoubleArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
public static class LongBased implements DoubleValues {
private final LongValues values;

View File

@ -27,6 +27,8 @@ import org.elasticsearch.index.fielddata.util.FloatArrayRef;
*/
public interface FloatValues {
static final FloatValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
@ -99,6 +101,43 @@ public interface FloatValues {
}
}
static class Empty implements FloatValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public float getValue(int docId) {
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty FloatValues");
}
@Override
public float getValueMissing(int docId, float missingValue) {
return missingValue;
}
@Override
public FloatArrayRef getValues(int docId) {
return FloatArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
public static class DoubleBased implements FloatValues {
private final DoubleValues values;

View File

@ -27,6 +27,8 @@ import org.elasticsearch.index.mapper.geo.GeoPoint;
*/
public interface GeoPointValues {
static final GeoPointValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
@ -119,4 +121,56 @@ public interface GeoPointValues {
}
}
}
static class Empty implements GeoPointValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public GeoPoint getValueSafe(int docId) {
return getValue(docId);
}
@Override
public Iter getIterSafe(int docId) {
return getIter(docId);
}
@Override
public void forEachSafeValueInDoc(int docId, ValueInDocProc proc) {
}
@Override
public void forEachLatLonValueInDoc(int docId, LatLonValueInDocProc proc) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public GeoPoint getValue(int docId) {
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty GeoPointValues");
}
@Override
public GeoPointArrayRef getValues(int docId) {
return GeoPointArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
}

View File

@ -27,6 +27,8 @@ import org.elasticsearch.common.lucene.HashedBytesRef;
*/
public interface HashedBytesValues {
static final HashedBytesValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
@ -111,6 +113,40 @@ public interface HashedBytesValues {
}
}
static class Empty implements HashedBytesValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public HashedBytesRef getValue(int docId) {
return null;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
@Override
public HashedBytesRef makeSafe(HashedBytesRef bytes) {
//todo maybe better to throw an excepiton here as the only value this method accepts is a scratch value...
//todo ...extracted from this ByteValues, in our case, there are not values, so this should never be called!?!?
return HashedBytesRef.deepCopyOf(bytes);
}
}
/**
* A {@link BytesValues} based implementation.
*/

View File

@ -27,6 +27,8 @@ import org.elasticsearch.index.fielddata.util.LongArrayRef;
*/
public interface IntValues {
static final IntValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
@ -99,6 +101,43 @@ public interface IntValues {
}
}
static class Empty implements IntValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public int getValue(int docId) {
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty IntValues");
}
@Override
public int getValueMissing(int docId, int missingValue) {
return missingValue;
}
@Override
public IntArrayRef getValues(int docId) {
return IntArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
public static class LongBased implements IntValues {
private final LongValues values;

View File

@ -27,6 +27,8 @@ import org.elasticsearch.index.fielddata.util.LongArrayRef;
*/
public interface LongValues {
static final LongValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
@ -100,4 +102,41 @@ public interface LongValues {
}
}
static class Empty implements LongValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public long getValue(int docId) {
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty LongValues");
}
@Override
public long getValueMissing(int docId, long missingValue) {
return missingValue;
}
@Override
public LongArrayRef getValues(int docId) {
return LongArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
}

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.fielddata;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
/**
@ -39,6 +40,36 @@ public interface OrdinalsBytesValues extends BytesValues {
BytesRef getSafeValueByOrd(int ord);
public static class Empty extends BytesValues.Empty implements OrdinalsBytesValues {
private final Ordinals ordinals;
public Empty(EmptyOrdinals ordinals) {
this.ordinals = ordinals;
}
@Override
public Ordinals.Docs ordinals() {
return ordinals.ordinals();
}
@Override
public BytesRef getValueByOrd(int ord) {
return null;
}
@Override
public BytesRef getValueScratchByOrd(int ord, BytesRef ret) {
ret.length = 0;
return ret;
}
@Override
public BytesRef getSafeValueByOrd(int ord) {
return null;
}
}
public static class StringBased extends BytesValues.StringBased implements OrdinalsBytesValues {
private final OrdinalsStringValues values;

View File

@ -21,6 +21,7 @@ package org.elasticsearch.index.fielddata;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.lucene.HashedBytesRef;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
/**
@ -33,6 +34,30 @@ public interface OrdinalsHashedBytesValues extends HashedBytesValues {
HashedBytesRef getSafeValueByOrd(int ord);
public static class Empty extends HashedBytesValues.Empty implements OrdinalsHashedBytesValues {
private final Ordinals ordinals;
public Empty(EmptyOrdinals ordinals) {
this.ordinals = ordinals;
}
@Override
public Ordinals.Docs ordinals() {
return ordinals.ordinals();
}
@Override
public HashedBytesRef getValueByOrd(int ord) {
return null;
}
@Override
public HashedBytesRef getSafeValueByOrd(int ord) {
return null;
}
}
static class BytesBased extends HashedBytesValues.BytesBased implements OrdinalsHashedBytesValues {
private final OrdinalsBytesValues values;

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.fielddata;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
/**
@ -28,4 +29,23 @@ public interface OrdinalsStringValues extends StringValues {
Ordinals.Docs ordinals();
String getValueByOrd(int ord);
public static class Empty extends StringValues.Empty implements OrdinalsStringValues {
private final Ordinals ordinals;
public Empty(EmptyOrdinals ordinals) {
this.ordinals = ordinals;
}
@Override
public Ordinals.Docs ordinals() {
return ordinals.ordinals();
}
@Override
public String getValueByOrd(int ord) {
return null;
}
}
}

View File

@ -32,10 +32,24 @@ import org.joda.time.MutableDateTime;
*/
public interface ScriptDocValues {
static final ScriptDocValues EMPTY = new Empty();
static final Strings EMPTY_STRINGS = new Strings(StringValues.EMPTY);
void setNextDocId(int docId);
boolean isEmpty();
static class Empty implements ScriptDocValues {
@Override
public void setNextDocId(int docId) {
}
@Override
public boolean isEmpty() {
return true;
}
}
static class Strings implements ScriptDocValues {
private final StringValues values;

View File

@ -28,6 +28,8 @@ import org.elasticsearch.index.fielddata.util.ShortArrayRef;
*/
public interface ShortValues {
static final ShortValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
@ -100,6 +102,43 @@ public interface ShortValues {
}
}
static class Empty implements ShortValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public short getValue(int docId) {
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty ShortValues");
}
@Override
public short getValueMissing(int docId, short missingValue) {
return missingValue;
}
@Override
public ShortArrayRef getValues(int docId) {
return ShortArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
public static class IntBased implements ShortValues {
private final IntValues values;

View File

@ -26,6 +26,8 @@ import org.elasticsearch.index.fielddata.util.*;
*/
public interface StringValues {
static final StringValues EMPTY = new Empty();
/**
* Is one of the documents in this field data values is multi valued?
*/
@ -100,6 +102,38 @@ public interface StringValues {
}
}
static class Empty implements StringValues {
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean hasValue(int docId) {
return false;
}
@Override
public String getValue(int docId) {
return null;
}
@Override
public StringArrayRef getValues(int docId) {
return StringArrayRef.EMPTY;
}
@Override
public Iter getIter(int docId) {
return Iter.Empty.INSTANCE;
}
@Override
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
proc.onMissing(docId);
}
}
public static class ByteBased implements StringValues {
private final ByteValues values;

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.fielddata.ordinals;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
/**
@ -149,5 +150,7 @@ public interface Ordinals {
return actual;
}
}
}
}

View File

@ -32,6 +32,8 @@ import org.elasticsearch.index.fielddata.util.LongArrayRef;
*/
public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData {
public static final ByteArrayAtomicFieldData EMPTY = new Empty();
protected final byte[] values;
private final int numDocs;
@ -47,6 +49,78 @@ public abstract class ByteArrayAtomicFieldData implements AtomicNumericFieldData
return numDocs;
}
static class Empty extends ByteArrayAtomicFieldData {
Empty() {
super(null, 0);
}
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override
public LongValues getLongValues() {
return LongValues.EMPTY;
}
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override
public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean isValuesOrdered() {
return false;
}
@Override
public long getMemorySizeInBytes() {
return 0;
}
@Override
public BytesValues getBytesValues() {
return BytesValues.EMPTY;
}
@Override
public HashedBytesValues getHashedBytesValues() {
return HashedBytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
}
}
public static class WithOrdinals extends ByteArrayAtomicFieldData {
private final Ordinals ordinals;

View File

@ -83,7 +83,7 @@ public class ByteArrayIndexFieldData extends AbstractIndexFieldData<ByteArrayAto
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
return new ByteArrayAtomicFieldData.SingleFixedSet(new byte[1], 0, new FixedBitSet(1));
return ByteArrayAtomicFieldData.EMPTY;
}
// TODO: how can we guess the number of terms? numerics end up creating more terms per value...

View File

@ -23,6 +23,7 @@ import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.lucene.HashedBytesRef;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.BytesRefArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -32,9 +33,13 @@ import org.elasticsearch.index.fielddata.util.StringArrayRef;
*/
public class ConcreteBytesRefAtomicFieldData implements AtomicOrdinalFieldData<ScriptDocValues.Strings> {
public static ConcreteBytesRefAtomicFieldData empty(int numDocs) {
return new Empty(numDocs);
}
// 0 ordinal in values means no value (its null)
private final BytesRef[] values;
private final Ordinals ordinals;
protected final Ordinals ordinals;
private int[] hashes;
private long size = -1;
@ -586,4 +591,51 @@ public class ConcreteBytesRefAtomicFieldData implements AtomicOrdinalFieldData<S
}
}
}
static class Empty extends ConcreteBytesRefAtomicFieldData {
Empty(int numDocs) {
super(null, new EmptyOrdinals(numDocs));
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public int getNumDocs() {
return ordinals.getNumDocs();
}
@Override
public boolean isValuesOrdered() {
return true;
}
@Override
public long getMemorySizeInBytes() {
return 0;
}
@Override
public OrdinalsBytesValues getBytesValues() {
return new OrdinalsBytesValues.Empty((EmptyOrdinals) ordinals);
}
@Override
public OrdinalsHashedBytesValues getHashedBytesValues() {
return new OrdinalsHashedBytesValues.Empty((EmptyOrdinals) ordinals);
}
@Override
public OrdinalsStringValues getStringValues() {
return new OrdinalsStringValues.Empty((EmptyOrdinals) ordinals);
}
@Override
public ScriptDocValues.Strings getScriptValues() {
return ScriptDocValues.EMPTY_STRINGS;
}
}
}

View File

@ -27,7 +27,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
import org.elasticsearch.index.fielddata.ordinals.SingleArrayOrdinals;
import org.elasticsearch.index.mapper.FieldMapper;
@ -75,7 +74,7 @@ public class ConcreteBytesRefIndexFieldData extends AbstractIndexFieldData<Concr
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
return new ConcreteBytesRefAtomicFieldData(new BytesRef[1], new EmptyOrdinals(reader.maxDoc()));
return ConcreteBytesRefAtomicFieldData.empty(reader.maxDoc());
}
long size = terms.size();

View File

@ -32,6 +32,8 @@ import org.elasticsearch.index.fielddata.util.StringArrayRef;
*/
public abstract class DoubleArrayAtomicFieldData implements AtomicNumericFieldData {
public static final DoubleArrayAtomicFieldData EMPTY = new Empty();
protected final double[] values;
private final int numDocs;
@ -47,6 +49,78 @@ public abstract class DoubleArrayAtomicFieldData implements AtomicNumericFieldDa
return numDocs;
}
static class Empty extends DoubleArrayAtomicFieldData {
Empty() {
super(null, 0);
}
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override
public LongValues getLongValues() {
return LongValues.EMPTY;
}
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override
public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean isValuesOrdered() {
return false;
}
@Override
public long getMemorySizeInBytes() {
return 0;
}
@Override
public BytesValues getBytesValues() {
return BytesValues.EMPTY;
}
@Override
public HashedBytesValues getHashedBytesValues() {
return HashedBytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
}
}
public static class WithOrdinals extends DoubleArrayAtomicFieldData {
private final Ordinals ordinals;

View File

@ -83,7 +83,7 @@ public class DoubleArrayIndexFieldData extends AbstractIndexFieldData<DoubleArra
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
return new DoubleArrayAtomicFieldData.SingleFixedSet(new double[1], 0, new FixedBitSet(1));
return DoubleArrayAtomicFieldData.EMPTY;
}
// TODO: how can we guess the number of terms? numerics end up creating more terms per value...

View File

@ -32,6 +32,8 @@ import org.elasticsearch.index.fielddata.util.LongArrayRef;
*/
public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldData {
public static final FloatArrayAtomicFieldData EMPTY = new Empty();
protected final float[] values;
private final int numDocs;
@ -47,6 +49,78 @@ public abstract class FloatArrayAtomicFieldData implements AtomicNumericFieldDat
return numDocs;
}
static class Empty extends FloatArrayAtomicFieldData {
Empty() {
super(null, 0);
}
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override
public LongValues getLongValues() {
return LongValues.EMPTY;
}
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override
public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean isValuesOrdered() {
return false;
}
@Override
public long getMemorySizeInBytes() {
return 0;
}
@Override
public BytesValues getBytesValues() {
return BytesValues.EMPTY;
}
@Override
public HashedBytesValues getHashedBytesValues() {
return HashedBytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
}
}
public static class WithOrdinals extends FloatArrayAtomicFieldData {
private final Ordinals ordinals;

View File

@ -83,7 +83,7 @@ public class FloatArrayIndexFieldData extends AbstractIndexFieldData<FloatArrayA
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
return new FloatArrayAtomicFieldData.SingleFixedSet(new float[1], 0, new FixedBitSet(1));
return FloatArrayAtomicFieldData.EMPTY;
}
// TODO: how can we guess the number of terms? numerics end up creating more terms per value...

View File

@ -21,10 +21,7 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.AtomicGeoPointFieldData;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.HashedBytesValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.GeoPointArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -36,6 +33,8 @@ import org.elasticsearch.index.search.geo.GeoHashUtils;
*/
public abstract class GeoPointDoubleArrayAtomicFieldData implements AtomicGeoPointFieldData {
public static final GeoPointDoubleArrayAtomicFieldData EMPTY = new Empty();
protected final double[] lon;
protected final double[] lat;
private final int numDocs;
@ -58,6 +57,53 @@ public abstract class GeoPointDoubleArrayAtomicFieldData implements AtomicGeoPoi
return new ScriptDocValues.GeoPoints(getGeoPointValues());
}
static class Empty extends GeoPointDoubleArrayAtomicFieldData {
Empty() {
super(null, null, 0);
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean isValuesOrdered() {
return false;
}
@Override
public long getMemorySizeInBytes() {
return 0;
}
@Override
public BytesValues getBytesValues() {
return BytesValues.EMPTY;
}
@Override
public HashedBytesValues getHashedBytesValues() {
return HashedBytesValues.EMPTY;
}
@Override
public GeoPointValues getGeoPointValues() {
return GeoPointValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
}
}
public static class WithOrdinals extends GeoPointDoubleArrayAtomicFieldData {
private final Ordinals ordinals;

View File

@ -77,7 +77,7 @@ public class GeoPointDoubleArrayIndexFieldData extends AbstractIndexFieldData<Ge
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
return new GeoPointDoubleArrayAtomicFieldData.SingleFixedSet(new double[1], new double[1], 0, new FixedBitSet(1));
return GeoPointDoubleArrayAtomicFieldData.EMPTY;
}
// TODO: how can we guess the number of terms? numerics end up creating more terms per value...

View File

@ -31,6 +31,8 @@ import org.elasticsearch.index.fielddata.util.LongArrayRef;
*/
public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData {
public static final IntArrayAtomicFieldData EMPTY = new Empty();
protected final int[] values;
private final int numDocs;
@ -46,6 +48,78 @@ public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData
return numDocs;
}
static class Empty extends IntArrayAtomicFieldData {
Empty() {
super(null, 0);
}
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override
public LongValues getLongValues() {
return LongValues.EMPTY;
}
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override
public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean isValuesOrdered() {
return false;
}
@Override
public long getMemorySizeInBytes() {
return 0;
}
@Override
public BytesValues getBytesValues() {
return BytesValues.EMPTY;
}
@Override
public HashedBytesValues getHashedBytesValues() {
return HashedBytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
}
}
public static class WithOrdinals extends IntArrayAtomicFieldData {
private final Ordinals ordinals;
@ -835,6 +909,7 @@ public abstract class IntArrayAtomicFieldData implements AtomicNumericFieldData
private final Iter.Single iter = new Iter.Single();
LongValues(int[] values) {
assert values.length != 0;
this.values = values;
}

View File

@ -83,7 +83,7 @@ public class IntArrayIndexFieldData extends AbstractIndexFieldData<IntArrayAtomi
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
return new IntArrayAtomicFieldData.SingleFixedSet(new int[1], 0, new FixedBitSet(1));
return IntArrayAtomicFieldData.EMPTY;
}
// TODO: how can we guess the number of terms? numerics end up creating more terms per value...

View File

@ -32,6 +32,8 @@ import org.elasticsearch.index.fielddata.util.StringArrayRef;
*/
public abstract class LongArrayAtomicFieldData implements AtomicNumericFieldData {
public static final LongArrayAtomicFieldData EMPTY = new Empty();
protected final long[] values;
private final int numDocs;
@ -47,6 +49,78 @@ public abstract class LongArrayAtomicFieldData implements AtomicNumericFieldData
return numDocs;
}
static class Empty extends LongArrayAtomicFieldData {
Empty() {
super(null, 0);
}
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override
public LongValues getLongValues() {
return LongValues.EMPTY;
}
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override
public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean isValuesOrdered() {
return false;
}
@Override
public long getMemorySizeInBytes() {
return 0;
}
@Override
public BytesValues getBytesValues() {
return BytesValues.EMPTY;
}
@Override
public HashedBytesValues getHashedBytesValues() {
return HashedBytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
}
}
public static class WithOrdinals extends LongArrayAtomicFieldData {
private final Ordinals ordinals;

View File

@ -83,7 +83,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<LongArrayAto
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
return new LongArrayAtomicFieldData.SingleFixedSet(new long[1], 0, new FixedBitSet(1));
return LongArrayAtomicFieldData.EMPTY;
}
// TODO: how can we guess the number of terms? numerics end up creating more terms per value...

View File

@ -21,10 +21,12 @@ package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.PagedBytes;
import org.apache.lucene.util.packed.GrowableWriter;
import org.apache.lucene.util.packed.PackedInts;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.common.lucene.HashedBytesRef;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.util.BytesRefArrayRef;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -34,10 +36,14 @@ import org.elasticsearch.index.fielddata.util.StringArrayRef;
*/
public class PagedBytesAtomicFieldData implements AtomicOrdinalFieldData<ScriptDocValues.Strings> {
public static PagedBytesAtomicFieldData empty(int numDocs) {
return new Empty(numDocs);
}
// 0 ordinal in values means no value (its null)
private final PagedBytes.Reader bytes;
private final PackedInts.Reader termOrdToBytesOffset;
private final Ordinals ordinals;
protected final Ordinals ordinals;
private int[] hashes;
private long size = -1;
@ -595,4 +601,53 @@ public class PagedBytesAtomicFieldData implements AtomicOrdinalFieldData<ScriptD
}
}
}
static class Empty extends PagedBytesAtomicFieldData {
Empty(int numDocs) {
super(emptyBytes(), new GrowableWriter(1, 2, PackedInts.FASTEST).getMutable(), new EmptyOrdinals(numDocs));
}
static PagedBytes.Reader emptyBytes() {
PagedBytes bytes = new PagedBytes(1);
bytes.copyUsingLengthPrefix(new BytesRef());
return bytes.freeze(true);
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public int getNumDocs() {
return ordinals.getNumDocs();
}
@Override
public boolean isValuesOrdered() {
return true;
}
@Override
public OrdinalsBytesValues getBytesValues() {
return new OrdinalsBytesValues.Empty((EmptyOrdinals) ordinals);
}
@Override
public OrdinalsHashedBytesValues getHashedBytesValues() {
return new HashedBytesValues.Empty((EmptyOrdinals) ordinals);
}
@Override
public OrdinalsStringValues getStringValues() {
return new OrdinalsStringValues.Empty((EmptyOrdinals) ordinals);
}
@Override
public ScriptDocValues.Strings getScriptValues() {
return ScriptDocValues.EMPTY_STRINGS;
}
}
}

View File

@ -31,7 +31,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
import org.elasticsearch.index.fielddata.ordinals.SingleArrayOrdinals;
import org.elasticsearch.index.mapper.FieldMapper;
@ -79,11 +78,7 @@ public class PagedBytesIndexFieldData extends AbstractIndexFieldData<PagedBytesA
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
final PagedBytes bytes = new PagedBytes(1);
// 0 is reserved for "unset"
bytes.copyUsingLengthPrefix(new BytesRef());
GrowableWriter termOrdToBytesOffset = new GrowableWriter(1, 2, PackedInts.FASTEST);
return new PagedBytesAtomicFieldData(bytes.freeze(true), termOrdToBytesOffset.getMutable(), new EmptyOrdinals(reader.maxDoc()));
return PagedBytesAtomicFieldData.empty(reader.maxDoc());
}
final PagedBytes bytes = new PagedBytes(15);

View File

@ -32,6 +32,8 @@ import org.elasticsearch.index.fielddata.util.ShortArrayRef;
*/
public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldData {
public static final ShortArrayAtomicFieldData EMPTY = new Empty();
protected final short[] values;
private final int numDocs;
@ -47,6 +49,78 @@ public abstract class ShortArrayAtomicFieldData implements AtomicNumericFieldDat
return numDocs;
}
static class Empty extends ShortArrayAtomicFieldData {
Empty() {
super(null, 0);
}
@Override
public ByteValues getByteValues() {
return ByteValues.EMPTY;
}
@Override
public ShortValues getShortValues() {
return ShortValues.EMPTY;
}
@Override
public IntValues getIntValues() {
return IntValues.EMPTY;
}
@Override
public LongValues getLongValues() {
return LongValues.EMPTY;
}
@Override
public FloatValues getFloatValues() {
return FloatValues.EMPTY;
}
@Override
public DoubleValues getDoubleValues() {
return DoubleValues.EMPTY;
}
@Override
public boolean isMultiValued() {
return false;
}
@Override
public boolean isValuesOrdered() {
return false;
}
@Override
public long getMemorySizeInBytes() {
return 0;
}
@Override
public BytesValues getBytesValues() {
return BytesValues.EMPTY;
}
@Override
public HashedBytesValues getHashedBytesValues() {
return HashedBytesValues.EMPTY;
}
@Override
public StringValues getStringValues() {
return StringValues.EMPTY;
}
@Override
public ScriptDocValues getScriptValues() {
return ScriptDocValues.EMPTY;
}
}
public static class WithOrdinals extends ShortArrayAtomicFieldData {
private final Ordinals ordinals;

View File

@ -83,7 +83,7 @@ public class ShortArrayIndexFieldData extends AbstractIndexFieldData<ShortArrayA
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
return new ShortArrayAtomicFieldData.SingleFixedSet(new short[1], 0, new FixedBitSet(1));
return ShortArrayAtomicFieldData.EMPTY;
}
// TODO: how can we guess the number of terms? numerics end up creating more terms per value...

View File

@ -19,6 +19,9 @@
package org.elasticsearch.test.unit.index.fielddata;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.search.*;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.util.*;
@ -1247,4 +1250,243 @@ public abstract class NumericFieldDataTests extends StringFieldDataTests {
floatValues.forEachValueInDoc(1, new FloatValuesVerifierProc(1).addMissing());
floatValues.forEachValueInDoc(2, new FloatValuesVerifierProc(2).addExpected(3f));
}
@Test
public void testMissingValueForAll() throws Exception {
fillAllMissing();
IndexNumericFieldData indexFieldData = getForField("value");
AtomicNumericFieldData fieldData = indexFieldData.load(refreshReader());
assertThat(fieldData.getNumDocs(), equalTo(0));
// long values
LongValues longValues = fieldData.getLongValues();
assertThat(longValues.isMultiValued(), equalTo(false));
assertThat(longValues.hasValue(0), equalTo(false));
assertThat(longValues.hasValue(1), equalTo(false));
assertThat(longValues.hasValue(2), equalTo(false));
assertThat(longValues.getValueMissing(0, -1), equalTo(-1l));
assertThat(longValues.getValueMissing(1, -1), equalTo(-1l));
assertThat(longValues.getValueMissing(2, -1), equalTo(-1l));
LongArrayRef longArrayRef = longValues.getValues(0);
assertThat(longArrayRef.size(), equalTo(0));
longArrayRef = longValues.getValues(1);
assertThat(longArrayRef.size(), equalTo(0));
longArrayRef = longValues.getValues(2);
assertThat(longArrayRef.size(), equalTo(0));
LongValues.Iter longValuesIter = longValues.getIter(0);
assertThat(longValuesIter.hasNext(), equalTo(false));
longValuesIter = longValues.getIter(1);
assertThat(longValuesIter.hasNext(), equalTo(false));
longValuesIter = longValues.getIter(2);
assertThat(longValuesIter.hasNext(), equalTo(false));
longValues.forEachValueInDoc(0, new LongValuesVerifierProc(0).addMissing());
longValues.forEachValueInDoc(1, new LongValuesVerifierProc(1).addMissing());
longValues.forEachValueInDoc(2, new LongValuesVerifierProc(2).addMissing());
// double values
DoubleValues doubleValues = fieldData.getDoubleValues();
assertThat(doubleValues.isMultiValued(), equalTo(false));
assertThat(doubleValues.hasValue(0), equalTo(false));
assertThat(doubleValues.hasValue(1), equalTo(false));
assertThat(doubleValues.hasValue(2), equalTo(false));
assertThat(doubleValues.getValueMissing(0, -1), equalTo(-1d));
assertThat(doubleValues.getValueMissing(1, -1), equalTo(-1d));
assertThat(doubleValues.getValueMissing(2, -1), equalTo(-1d));
DoubleArrayRef doubleArrayRef = doubleValues.getValues(0);
assertThat(doubleArrayRef.size(), equalTo(0));
doubleArrayRef = doubleValues.getValues(1);
assertThat(doubleArrayRef.size(), equalTo(0));
doubleArrayRef = doubleValues.getValues(2);
assertThat(doubleArrayRef.size(), equalTo(0));
DoubleValues.Iter doubleValuesIter = doubleValues.getIter(0);
assertThat(doubleValuesIter.hasNext(), equalTo(false));
doubleValuesIter = doubleValues.getIter(1);
assertThat(doubleValuesIter.hasNext(), equalTo(false));
doubleValuesIter = doubleValues.getIter(2);
assertThat(doubleValuesIter.hasNext(), equalTo(false));
doubleValues.forEachValueInDoc(0, new DoubleValuesVerifierProc(0).addMissing());
doubleValues.forEachValueInDoc(1, new DoubleValuesVerifierProc(1).addMissing());
doubleValues.forEachValueInDoc(2, new DoubleValuesVerifierProc(2).addMissing());
// byte values
ByteValues byteValues = fieldData.getByteValues();
assertThat(byteValues.isMultiValued(), equalTo(false));
assertThat(byteValues.hasValue(0), equalTo(false));
assertThat(byteValues.hasValue(1), equalTo(false));
assertThat(byteValues.hasValue(2), equalTo(false));
assertThat(byteValues.getValueMissing(0, (byte) -1), equalTo((byte) -1));
assertThat(byteValues.getValueMissing(1, (byte) -1), equalTo((byte) -1));
assertThat(byteValues.getValueMissing(2, (byte) -1), equalTo((byte) -1));
ByteArrayRef byteArrayRef = byteValues.getValues(0);
assertThat(byteArrayRef.size(), equalTo(0));
byteArrayRef = byteValues.getValues(1);
assertThat(byteArrayRef.size(), equalTo(0));
byteArrayRef = byteValues.getValues(2);
assertThat(byteArrayRef.size(), equalTo(0));
ByteValues.Iter byteValuesIter = byteValues.getIter(0);
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(1);
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValuesIter = byteValues.getIter(2);
assertThat(byteValuesIter.hasNext(), equalTo(false));
byteValues.forEachValueInDoc(0, new ByteValuesVerifierProc(0).addMissing());
byteValues.forEachValueInDoc(1, new ByteValuesVerifierProc(1).addMissing());
byteValues.forEachValueInDoc(2, new ByteValuesVerifierProc(2).addMissing());
// short values
ShortValues shortValues = fieldData.getShortValues();
assertThat(shortValues.isMultiValued(), equalTo(false));
assertThat(shortValues.hasValue(0), equalTo(false));
assertThat(shortValues.hasValue(1), equalTo(false));
assertThat(shortValues.hasValue(2), equalTo(false));
assertThat(shortValues.getValueMissing(0, (short) -1), equalTo((short) -1));
assertThat(shortValues.getValueMissing(1, (short) -1), equalTo((short) -1));
assertThat(shortValues.getValueMissing(2, (short) -1), equalTo((short) -1));
ShortArrayRef shortArrayRef = shortValues.getValues(0);
assertThat(shortArrayRef.size(), equalTo(0));
shortArrayRef = shortValues.getValues(1);
assertThat(shortArrayRef.size(), equalTo(0));
shortArrayRef = shortValues.getValues(2);
assertThat(shortArrayRef.size(), equalTo(0));
ShortValues.Iter shortValuesIter = shortValues.getIter(0);
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(1);
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValuesIter = shortValues.getIter(2);
assertThat(shortValuesIter.hasNext(), equalTo(false));
shortValues.forEachValueInDoc(0, new ShortValuesVerifierProc(0).addMissing());
shortValues.forEachValueInDoc(1, new ShortValuesVerifierProc(1).addMissing());
shortValues.forEachValueInDoc(2, new ShortValuesVerifierProc(2).addMissing());
// int values
IntValues intValues = fieldData.getIntValues();
assertThat(intValues.isMultiValued(), equalTo(false));
assertThat(intValues.hasValue(0), equalTo(false));
assertThat(intValues.hasValue(1), equalTo(false));
assertThat(intValues.hasValue(2), equalTo(false));
assertThat(intValues.getValueMissing(0, -1), equalTo(-1));
assertThat(intValues.getValueMissing(1, -1), equalTo(-1));
assertThat(intValues.getValueMissing(2, -1), equalTo(-1));
IntArrayRef intArrayRef = intValues.getValues(0);
assertThat(intArrayRef.size(), equalTo(0));
intArrayRef = intValues.getValues(1);
assertThat(intArrayRef.size(), equalTo(0));
intArrayRef = intValues.getValues(2);
assertThat(intArrayRef.size(), equalTo(0));
IntValues.Iter intValuesIter = intValues.getIter(0);
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(1);
assertThat(intValuesIter.hasNext(), equalTo(false));
intValuesIter = intValues.getIter(2);
assertThat(intValuesIter.hasNext(), equalTo(false));
intValues.forEachValueInDoc(0, new IntValuesVerifierProc(0).addMissing());
intValues.forEachValueInDoc(1, new IntValuesVerifierProc(1).addMissing());
intValues.forEachValueInDoc(2, new IntValuesVerifierProc(2).addMissing());
// float
FloatValues floatValues = fieldData.getFloatValues();
assertThat(floatValues.isMultiValued(), equalTo(false));
assertThat(floatValues.hasValue(0), equalTo(false));
assertThat(floatValues.hasValue(1), equalTo(false));
assertThat(floatValues.hasValue(2), equalTo(false));
assertThat(floatValues.getValueMissing(0, -1), equalTo(-1f));
assertThat(floatValues.getValueMissing(1, -1), equalTo(-1f));
assertThat(floatValues.getValueMissing(2, -1), equalTo(-1f));
FloatArrayRef floatArrayRef = floatValues.getValues(0);
assertThat(floatArrayRef.size(), equalTo(0));
floatArrayRef = floatValues.getValues(1);
assertThat(floatArrayRef.size(), equalTo(0));
floatArrayRef = floatValues.getValues(2);
assertThat(floatArrayRef.size(), equalTo(0));
FloatValues.Iter floatValuesIter = floatValues.getIter(0);
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(1);
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValuesIter = floatValues.getIter(2);
assertThat(floatValuesIter.hasNext(), equalTo(false));
floatValues.forEachValueInDoc(0, new FloatValuesVerifierProc(0).addMissing());
floatValues.forEachValueInDoc(1, new FloatValuesVerifierProc(1).addMissing());
floatValues.forEachValueInDoc(2, new FloatValuesVerifierProc(2).addMissing());
}
protected void fillAllMissing() throws Exception {
Document d = new Document();
d.add(new StringField("_id", "1", Field.Store.NO));
writer.addDocument(d);
d = new Document();
d.add(new StringField("_id", "2", Field.Store.NO));
writer.addDocument(d);
d = new Document();
d.add(new StringField("_id", "3", Field.Store.NO));
writer.addDocument(d);
}
}

View File

@ -624,4 +624,125 @@ public abstract class StringFieldDataTests extends AbstractFieldDataTests {
stringValues.forEachValueInDoc(1, new StringValuesVerifierProc(1).addMissing());
stringValues.forEachValueInDoc(2, new StringValuesVerifierProc(2).addExpected(three()));
}
public void testMissingValueForAll() throws Exception {
fillAllMissing();
IndexFieldData indexFieldData = getForField("value");
AtomicFieldData fieldData = indexFieldData.load(refreshReader());
assertThat(fieldData.getNumDocs(), equalTo(3));
BytesValues bytesValues = fieldData.getBytesValues();
assertThat(bytesValues.isMultiValued(), equalTo(false));
assertThat(bytesValues.hasValue(0), equalTo(false));
assertThat(bytesValues.hasValue(1), equalTo(false));
assertThat(bytesValues.hasValue(2), equalTo(false));
assertThat(bytesValues.getValue(0), nullValue());
assertThat(bytesValues.getValue(1), nullValue());
assertThat(bytesValues.getValue(2), nullValue());
BytesRef bytesRef = new BytesRef();
assertThat(bytesValues.getValueScratch(0, bytesRef), equalTo(new BytesRef()));
assertThat(bytesRef, equalTo(new BytesRef()));
assertThat(bytesValues.getValueScratch(1, bytesRef), equalTo(new BytesRef()));
assertThat(bytesRef, equalTo(new BytesRef()));
assertThat(bytesValues.getValueScratch(2, bytesRef), equalTo(new BytesRef()));
assertThat(bytesRef, equalTo(new BytesRef()));
BytesRefArrayRef bytesRefArrayRef = bytesValues.getValues(0);
assertThat(bytesRefArrayRef.size(), equalTo(0));
bytesRefArrayRef = bytesValues.getValues(1);
assertThat(bytesRefArrayRef.size(), equalTo(0));
bytesRefArrayRef = bytesValues.getValues(2);
assertThat(bytesRefArrayRef.size(), equalTo(0));
BytesValues.Iter bytesValuesIter = bytesValues.getIter(0);
assertThat(bytesValuesIter.hasNext(), equalTo(false));
bytesValuesIter = bytesValues.getIter(1);
assertThat(bytesValuesIter.hasNext(), equalTo(false));
bytesValuesIter = bytesValues.getIter(2);
assertThat(bytesValuesIter.hasNext(), equalTo(false));
bytesValues.forEachValueInDoc(0, new BytesValuesVerifierProc(0).addMissing());
bytesValues.forEachValueInDoc(1, new BytesValuesVerifierProc(1).addMissing());
bytesValues.forEachValueInDoc(2, new BytesValuesVerifierProc(2).addMissing());
HashedBytesValues hashedBytesValues = fieldData.getHashedBytesValues();
assertThat(hashedBytesValues.hasValue(0), equalTo(false));
assertThat(hashedBytesValues.hasValue(1), equalTo(false));
assertThat(hashedBytesValues.hasValue(2), equalTo(false));
assertThat(hashedBytesValues.getValue(0), nullValue());
assertThat(hashedBytesValues.getValue(1), nullValue());
assertThat(hashedBytesValues.getValue(2), nullValue());
HashedBytesValues.Iter hashedBytesValuesIter = hashedBytesValues.getIter(0);
assertThat(hashedBytesValuesIter.hasNext(), equalTo(false));
hashedBytesValuesIter = hashedBytesValues.getIter(1);
assertThat(hashedBytesValuesIter.hasNext(), equalTo(false));
hashedBytesValuesIter = hashedBytesValues.getIter(2);
assertThat(hashedBytesValuesIter.hasNext(), equalTo(false));
hashedBytesValues.forEachValueInDoc(0, new HashedBytesValuesVerifierProc(0).addMissing());
hashedBytesValues.forEachValueInDoc(1, new HashedBytesValuesVerifierProc(1).addMissing());
hashedBytesValues.forEachValueInDoc(2, new HashedBytesValuesVerifierProc(2).addMissing());
StringValues stringValues = fieldData.getStringValues();
assertThat(stringValues.hasValue(0), equalTo(false));
assertThat(stringValues.hasValue(1), equalTo(false));
assertThat(stringValues.hasValue(2), equalTo(false));
assertThat(stringValues.getValue(0), nullValue());
assertThat(stringValues.getValue(1), nullValue());
assertThat(stringValues.getValue(2), nullValue());
StringArrayRef stringArrayRef;
stringArrayRef = stringValues.getValues(0);
assertThat(stringArrayRef.size(), equalTo(0));
stringArrayRef = stringValues.getValues(1);
assertThat(stringArrayRef.size(), equalTo(0));
stringArrayRef = stringValues.getValues(2);
assertThat(stringArrayRef.size(), equalTo(0));
StringValues.Iter stringValuesIter = stringValues.getIter(0);
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(1);
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValuesIter = stringValues.getIter(2);
assertThat(stringValuesIter.hasNext(), equalTo(false));
stringValues.forEachValueInDoc(0, new StringValuesVerifierProc(0).addMissing());
stringValues.forEachValueInDoc(1, new StringValuesVerifierProc(1).addMissing());
stringValues.forEachValueInDoc(2, new StringValuesVerifierProc(2).addMissing());
}
protected void fillAllMissing() throws Exception {
Document d = new Document();
d.add(new StringField("_id", "1", Field.Store.NO));
writer.addDocument(d);
d = new Document();
d.add(new StringField("_id", "2", Field.Store.NO));
writer.addDocument(d);
d = new Document();
d.add(new StringField("_id", "3", Field.Store.NO));
writer.addDocument(d);
}
}