Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ private DerivedFieldScript.LeafFactory compile(String expression, SearchLookup l
return factory.newFactory(Collections.emptyMap(), lookup);
}

public void testEmittingFloatField() throws IOException {
SearchLookup lookup = mock(SearchLookup.class);

// Mock LeafReaderContext
MemoryIndex index = new MemoryIndex();
LeafReaderContext leafReaderContext = index.createSearcher().getIndexReader().leaves().get(0);

LeafSearchLookup leafSearchLookup = mock(LeafSearchLookup.class);
when(lookup.getLeafSearchLookup(leafReaderContext)).thenReturn(leafSearchLookup);

// Script that emits a float value
DerivedFieldScript script = compile("emit(3.14f)", lookup).newInstance(leafReaderContext);
script.setDocument(1);
script.execute();

List<Object> result = script.getEmittedValues();
assertEquals(1, result.size());
assertEquals(3.14f, result.get(0));
}

public void testEmittingDoubleField() throws IOException {
// Mocking field value to be returned
NumberFieldType fieldType = new NumberFieldType("test_double_field", NumberType.DOUBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ private int getObjectByteSize(Object obj) {
return Long.BYTES;
} else if (obj instanceof Double) {
return Double.BYTES;
} else if (obj instanceof Float) {
return Float.BYTES;
} else if (obj instanceof Boolean) {
return Byte.BYTES; // Assuming 1 byte for boolean
} else if (obj instanceof Tuple) {
Expand Down
Loading