Skip to content

Commit 09cc70b

Browse files
ubonesskimchy
authored andcommitted
added predefined empty implementation for all atomic field datas
1 parent 6b92b59 commit 09cc70b

39 files changed

+1484
-27
lines changed

src/main/java/org/elasticsearch/index/fielddata/AtomicFieldData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,5 @@ public interface AtomicFieldData<Script extends ScriptDocValues> {
6363
* Returns a "scripting" based values.
6464
*/
6565
Script getScriptValues();
66+
6667
}

src/main/java/org/elasticsearch/index/fielddata/AtomicGeoPointFieldData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
99
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
10+
* http://www.apache.org/licenses/LICENSE-2.0
1111
*
1212
* Unless required by applicable law or agreed to in writing,
1313
* software distributed under the License is distributed on an
@@ -24,4 +24,5 @@
2424
public interface AtomicGeoPointFieldData<Script extends ScriptDocValues> extends AtomicFieldData<Script> {
2525

2626
GeoPointValues getGeoPointValues();
27+
2728
}

src/main/java/org/elasticsearch/index/fielddata/AtomicNumericFieldData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ public interface AtomicNumericFieldData<Script extends ScriptDocValues> extends
3434
FloatValues getFloatValues();
3535

3636
DoubleValues getDoubleValues();
37+
3738
}

src/main/java/org/elasticsearch/index/fielddata/AtomicOrdinalFieldData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ public interface AtomicOrdinalFieldData<Script extends ScriptDocValues> extends
3737
* Use a non thread safe (lightweight) view of the values as strings.
3838
*/
3939
OrdinalsStringValues getStringValues();
40+
4041
}

src/main/java/org/elasticsearch/index/fielddata/ByteValues.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
public interface ByteValues {
3030

31+
static ByteValues EMPTY = new Empty();
32+
3133
/**
3234
* Is one of the documents in this field data values is multi valued?
3335
*/
@@ -100,6 +102,43 @@ public byte next() {
100102
}
101103
}
102104

105+
static class Empty implements ByteValues {
106+
@Override
107+
public boolean isMultiValued() {
108+
return false;
109+
}
110+
111+
@Override
112+
public boolean hasValue(int docId) {
113+
return false;
114+
}
115+
116+
@Override
117+
public byte getValue(int docId) {
118+
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty ByteValues");
119+
}
120+
121+
@Override
122+
public byte getValueMissing(int docId, byte missingValue) {
123+
return missingValue;
124+
}
125+
126+
@Override
127+
public ByteArrayRef getValues(int docId) {
128+
return ByteArrayRef.EMPTY;
129+
}
130+
131+
@Override
132+
public Iter getIter(int docId) {
133+
return Iter.Empty.INSTANCE;
134+
}
135+
136+
@Override
137+
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
138+
proc.onMissing(docId);
139+
}
140+
}
141+
103142
public static class IntBased implements ByteValues {
104143

105144
private final IntValues values;

src/main/java/org/elasticsearch/index/fielddata/BytesValues.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
public interface BytesValues {
3030

31+
static final BytesValues EMPTY = new Empty();
32+
3133
/**
3234
* Is one of the documents in this field data values is multi valued?
3335
*/
@@ -122,6 +124,51 @@ public BytesRef next() {
122124
}
123125
}
124126

127+
static class Empty implements BytesValues {
128+
@Override
129+
public boolean isMultiValued() {
130+
return false;
131+
}
132+
133+
@Override
134+
public boolean hasValue(int docId) {
135+
return false;
136+
}
137+
138+
@Override
139+
public BytesRef getValue(int docId) {
140+
return null;
141+
}
142+
143+
@Override
144+
public BytesRefArrayRef getValues(int docId) {
145+
return BytesRefArrayRef.EMPTY;
146+
}
147+
148+
@Override
149+
public Iter getIter(int docId) {
150+
return Iter.Empty.INSTANCE;
151+
}
152+
153+
@Override
154+
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
155+
proc.onMissing(docId);
156+
}
157+
158+
@Override
159+
public BytesRef makeSafe(BytesRef bytes) {
160+
//todo we can also throw an excepiton here as the only value this method accepts is a scratch value...
161+
//todo ...extracted from this ByteValues, in our case, there are not values, so this should never be called!?!?
162+
return BytesRef.deepCopyOf(bytes);
163+
}
164+
165+
@Override
166+
public BytesRef getValueScratch(int docId, BytesRef ret) {
167+
ret.length = 0;
168+
return ret;
169+
}
170+
}
171+
125172
public static class StringBased implements BytesValues {
126173

127174
private final StringValues values;

src/main/java/org/elasticsearch/index/fielddata/DoubleValues.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
public interface DoubleValues {
3030

31+
static final DoubleValues EMPTY = new Empty();
32+
3133
/**
3234
* Is one of the documents in this field data values is multi valued?
3335
*/
@@ -100,6 +102,43 @@ public double next() {
100102
}
101103
}
102104

105+
static class Empty implements DoubleValues {
106+
@Override
107+
public boolean isMultiValued() {
108+
return false;
109+
}
110+
111+
@Override
112+
public boolean hasValue(int docId) {
113+
return false;
114+
}
115+
116+
@Override
117+
public double getValue(int docId) {
118+
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty DoubleValues");
119+
}
120+
121+
@Override
122+
public double getValueMissing(int docId, double missingValue) {
123+
return missingValue;
124+
}
125+
126+
@Override
127+
public DoubleArrayRef getValues(int docId) {
128+
return DoubleArrayRef.EMPTY;
129+
}
130+
131+
@Override
132+
public Iter getIter(int docId) {
133+
return Iter.Empty.INSTANCE;
134+
}
135+
136+
@Override
137+
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
138+
proc.onMissing(docId);
139+
}
140+
}
141+
103142
public static class LongBased implements DoubleValues {
104143

105144
private final LongValues values;

src/main/java/org/elasticsearch/index/fielddata/FloatValues.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
public interface FloatValues {
2929

30+
static final FloatValues EMPTY = new Empty();
31+
3032
/**
3133
* Is one of the documents in this field data values is multi valued?
3234
*/
@@ -99,6 +101,43 @@ public float next() {
99101
}
100102
}
101103

104+
static class Empty implements FloatValues {
105+
@Override
106+
public boolean isMultiValued() {
107+
return false;
108+
}
109+
110+
@Override
111+
public boolean hasValue(int docId) {
112+
return false;
113+
}
114+
115+
@Override
116+
public float getValue(int docId) {
117+
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty FloatValues");
118+
}
119+
120+
@Override
121+
public float getValueMissing(int docId, float missingValue) {
122+
return missingValue;
123+
}
124+
125+
@Override
126+
public FloatArrayRef getValues(int docId) {
127+
return FloatArrayRef.EMPTY;
128+
}
129+
130+
@Override
131+
public Iter getIter(int docId) {
132+
return Iter.Empty.INSTANCE;
133+
}
134+
135+
@Override
136+
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
137+
proc.onMissing(docId);
138+
}
139+
}
140+
102141
public static class DoubleBased implements FloatValues {
103142

104143
private final DoubleValues values;

src/main/java/org/elasticsearch/index/fielddata/GeoPointValues.java

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
99
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
10+
* http://www.apache.org/licenses/LICENSE-2.0
1111
*
1212
* Unless required by applicable law or agreed to in writing,
1313
* software distributed under the License is distributed on an
@@ -27,6 +27,8 @@
2727
*/
2828
public interface GeoPointValues {
2929

30+
static final GeoPointValues EMPTY = new Empty();
31+
3032
/**
3133
* Is one of the documents in this field data values is multi valued?
3234
*/
@@ -119,4 +121,56 @@ public GeoPoint next() {
119121
}
120122
}
121123
}
124+
125+
static class Empty implements GeoPointValues {
126+
@Override
127+
public boolean isMultiValued() {
128+
return false;
129+
}
130+
131+
@Override
132+
public boolean hasValue(int docId) {
133+
return false;
134+
}
135+
136+
@Override
137+
public GeoPoint getValueSafe(int docId) {
138+
return getValue(docId);
139+
}
140+
141+
@Override
142+
public Iter getIterSafe(int docId) {
143+
return getIter(docId);
144+
}
145+
146+
@Override
147+
public void forEachSafeValueInDoc(int docId, ValueInDocProc proc) {
148+
149+
}
150+
151+
@Override
152+
public void forEachLatLonValueInDoc(int docId, LatLonValueInDocProc proc) {
153+
//To change body of implemented methods use File | Settings | File Templates.
154+
}
155+
156+
@Override
157+
public GeoPoint getValue(int docId) {
158+
throw new ElasticSearchIllegalStateException("Can't retrieve a value from an empty GeoPointValues");
159+
}
160+
161+
@Override
162+
public GeoPointArrayRef getValues(int docId) {
163+
return GeoPointArrayRef.EMPTY;
164+
}
165+
166+
@Override
167+
public Iter getIter(int docId) {
168+
return Iter.Empty.INSTANCE;
169+
}
170+
171+
@Override
172+
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
173+
proc.onMissing(docId);
174+
}
175+
}
122176
}

src/main/java/org/elasticsearch/index/fielddata/HashedBytesValues.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
public interface HashedBytesValues {
2929

30+
static final HashedBytesValues EMPTY = new Empty();
31+
3032
/**
3133
* Is one of the documents in this field data values is multi valued?
3234
*/
@@ -111,6 +113,40 @@ public HashedBytesRef next() {
111113
}
112114
}
113115

116+
static class Empty implements HashedBytesValues {
117+
@Override
118+
public boolean isMultiValued() {
119+
return false;
120+
}
121+
122+
@Override
123+
public boolean hasValue(int docId) {
124+
return false;
125+
}
126+
127+
@Override
128+
public HashedBytesRef getValue(int docId) {
129+
return null;
130+
}
131+
132+
@Override
133+
public Iter getIter(int docId) {
134+
return Iter.Empty.INSTANCE;
135+
}
136+
137+
@Override
138+
public void forEachValueInDoc(int docId, ValueInDocProc proc) {
139+
proc.onMissing(docId);
140+
}
141+
142+
@Override
143+
public HashedBytesRef makeSafe(HashedBytesRef bytes) {
144+
//todo maybe better to throw an excepiton here as the only value this method accepts is a scratch value...
145+
//todo ...extracted from this ByteValues, in our case, there are not values, so this should never be called!?!?
146+
return HashedBytesRef.deepCopyOf(bytes);
147+
}
148+
}
149+
114150
/**
115151
* A {@link BytesValues} based implementation.
116152
*/

0 commit comments

Comments
 (0)