use of com.carrotsearch.hppc.ObjectArrayList in project elasticsearch by elastic.
the class BinaryDVFieldDataTests method testDocValue.
public void testDocValue() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("test").startObject("properties").startObject("field").field("type", "binary").field("doc_values", true).endObject().endObject().endObject().endObject().string();
final DocumentMapper mapper = mapperService.documentMapperParser().parse("test", new CompressedXContent(mapping));
ObjectArrayList<byte[]> bytesList1 = new ObjectArrayList<>(2);
bytesList1.add(randomBytes());
bytesList1.add(randomBytes());
XContentBuilder doc = XContentFactory.jsonBuilder().startObject().startArray("field").value(bytesList1.get(0)).value(bytesList1.get(1)).endArray().endObject();
ParsedDocument d = mapper.parse("test", "test", "1", doc.bytes());
writer.addDocument(d.rootDoc());
byte[] bytes1 = randomBytes();
doc = XContentFactory.jsonBuilder().startObject().field("field", bytes1).endObject();
d = mapper.parse("test", "test", "2", doc.bytes());
writer.addDocument(d.rootDoc());
doc = XContentFactory.jsonBuilder().startObject().endObject();
d = mapper.parse("test", "test", "3", doc.bytes());
writer.addDocument(d.rootDoc());
// test remove duplicate value
ObjectArrayList<byte[]> bytesList2 = new ObjectArrayList<>(2);
bytesList2.add(randomBytes());
bytesList2.add(randomBytes());
doc = XContentFactory.jsonBuilder().startObject().startArray("field").value(bytesList2.get(0)).value(bytesList2.get(1)).value(bytesList2.get(0)).endArray().endObject();
d = mapper.parse("test", "test", "4", doc.bytes());
writer.addDocument(d.rootDoc());
List<LeafReaderContext> readers = refreshReader();
IndexFieldData<?> indexFieldData = getForField("field");
for (LeafReaderContext reader : readers) {
AtomicFieldData fieldData = indexFieldData.load(reader);
SortedBinaryDocValues bytesValues = fieldData.getBytesValues();
CollectionUtils.sortAndDedup(bytesList1);
bytesValues.setDocument(0);
assertThat(bytesValues.count(), equalTo(2));
assertThat(bytesValues.valueAt(0), equalTo(new BytesRef(bytesList1.get(0))));
assertThat(bytesValues.valueAt(1), equalTo(new BytesRef(bytesList1.get(1))));
bytesValues.setDocument(1);
assertThat(bytesValues.count(), equalTo(1));
assertThat(bytesValues.valueAt(0), equalTo(new BytesRef(bytes1)));
bytesValues.setDocument(2);
assertThat(bytesValues.count(), equalTo(0));
CollectionUtils.sortAndDedup(bytesList2);
bytesValues.setDocument(3);
assertThat(bytesValues.count(), equalTo(2));
assertThat(bytesValues.valueAt(0), equalTo(new BytesRef(bytesList2.get(0))));
assertThat(bytesValues.valueAt(1), equalTo(new BytesRef(bytesList2.get(1))));
}
}
Aggregations