Skip to content

Commit ee11a00

Browse files
authored
[8.x] Fixing MultiDenseVectorScriptDocValuesTests tests (#116940) (#116976)
* Fixing MultiDenseVectorScriptDocValuesTests tests (#116940) This fixes two test issues: - 1. Now the tests skip if the multi_dense_vector feature isn't enabled - 2. fixes silly bwc testing where we were testing for big-endian floats, which aren't possible. closes: #116862 closes: #116863 (cherry picked from commit 82c02de) * fixing backport
1 parent 8d5615f commit ee11a00

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

server/src/test/java/org/elasticsearch/index/mapper/vectors/MultiDenseVectorScriptDocValuesTests.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.script.field.vectors.MultiDenseVector;
1919
import org.elasticsearch.script.field.vectors.MultiDenseVectorDocValuesField;
2020
import org.elasticsearch.test.ESTestCase;
21+
import org.junit.BeforeClass;
2122

2223
import java.io.IOException;
2324
import java.nio.ByteBuffer;
@@ -28,13 +29,17 @@
2829

2930
public class MultiDenseVectorScriptDocValuesTests extends ESTestCase {
3031

32+
@BeforeClass
33+
public static void setup() {
34+
assumeTrue("Requires multi-dense vector support", MultiDenseVectorFieldMapper.FEATURE_FLAG.isEnabled());
35+
}
36+
3137
public void testFloatGetVectorValueAndGetMagnitude() throws IOException {
3238
int dims = 3;
3339
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
3440
float[][] expectedMagnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
3541

36-
IndexVersion indexVersion = IndexVersion.current();
37-
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT, indexVersion);
42+
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT);
3843
BinaryDocValues magnitudeValues = wrap(expectedMagnitudes);
3944
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField(
4045
docValues,
@@ -64,7 +69,7 @@ public void testByteGetVectorValueAndGetMagnitude() throws IOException {
6469
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
6570
float[][] expectedMagnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
6671

67-
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE, IndexVersion.current());
72+
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE);
6873
BinaryDocValues magnitudeValues = wrap(expectedMagnitudes);
6974
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField(
7075
docValues,
@@ -91,10 +96,9 @@ public void testByteGetVectorValueAndGetMagnitude() throws IOException {
9196

9297
public void testFloatMetadataAndIterator() throws IOException {
9398
int dims = 3;
94-
IndexVersion indexVersion = IndexVersion.current();
9599
float[][][] vectors = new float[][][] { fill(new float[3][dims], ElementType.FLOAT), fill(new float[2][dims], ElementType.FLOAT) };
96100
float[][] magnitudes = new float[][] { new float[3], new float[2] };
97-
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT, indexVersion);
101+
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT);
98102
BinaryDocValues magnitudeValues = wrap(magnitudes);
99103

100104
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField(
@@ -120,10 +124,9 @@ public void testFloatMetadataAndIterator() throws IOException {
120124

121125
public void testByteMetadataAndIterator() throws IOException {
122126
int dims = 3;
123-
IndexVersion indexVersion = IndexVersion.current();
124127
float[][][] vectors = new float[][][] { fill(new float[3][dims], ElementType.BYTE), fill(new float[2][dims], ElementType.BYTE) };
125128
float[][] magnitudes = new float[][] { new float[3], new float[2] };
126-
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE, indexVersion);
129+
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE);
127130
BinaryDocValues magnitudeValues = wrap(magnitudes);
128131
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField(
129132
docValues,
@@ -159,7 +162,7 @@ public void testFloatMissingValues() throws IOException {
159162
int dims = 3;
160163
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
161164
float[][] magnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
162-
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT, IndexVersion.current());
165+
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT);
163166
BinaryDocValues magnitudeValues = wrap(magnitudes);
164167
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField(
165168
docValues,
@@ -183,7 +186,7 @@ public void testByteMissingValues() throws IOException {
183186
int dims = 3;
184187
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
185188
float[][] magnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
186-
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE, IndexVersion.current());
189+
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE);
187190
BinaryDocValues magnitudeValues = wrap(magnitudes);
188191
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField(
189192
docValues,
@@ -207,7 +210,7 @@ public void testFloatGetFunctionIsNotAccessible() throws IOException {
207210
int dims = 3;
208211
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
209212
float[][] magnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
210-
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT, IndexVersion.current());
213+
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT);
211214
BinaryDocValues magnitudeValues = wrap(magnitudes);
212215
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField(
213216
docValues,
@@ -233,7 +236,7 @@ public void testByteGetFunctionIsNotAccessible() throws IOException {
233236
int dims = 3;
234237
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
235238
float[][] magnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
236-
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE, IndexVersion.current());
239+
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE);
237240
BinaryDocValues magnitudeValues = wrap(magnitudes);
238241
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField(
239242
docValues,
@@ -303,7 +306,7 @@ public long cost() {
303306
};
304307
}
305308

306-
public static BinaryDocValues wrap(float[][][] vectors, ElementType elementType, IndexVersion indexVersion) {
309+
public static BinaryDocValues wrap(float[][][] vectors, ElementType elementType) {
307310
return new BinaryDocValues() {
308311
int idx = -1;
309312
int maxIdx = vectors.length;
@@ -313,7 +316,7 @@ public BytesRef binaryValue() {
313316
if (idx >= maxIdx) {
314317
throw new IllegalStateException("max index exceeded");
315318
}
316-
return mockEncodeDenseVector(vectors[idx], elementType, indexVersion);
319+
return mockEncodeDenseVector(vectors[idx], elementType, IndexVersion.current());
317320
}
318321

319322
@Override

0 commit comments

Comments
 (0)