Search in sources :

Example 1 with Longs

use of org.elasticsearch.index.fielddata.ScriptDocValues.Longs in project elasticsearch by elastic.

the class ScriptDocValuesLongsTests method testLongs.

public void testLongs() {
    long[][] values = new long[between(3, 10)][];
    for (int d = 0; d < values.length; d++) {
        values[d] = new long[randomBoolean() ? randomBoolean() ? 0 : 1 : between(2, 100)];
        for (int i = 0; i < values[d].length; i++) {
            values[d][i] = randomLong();
        }
    }
    Longs longs = wrap(values);
    for (int round = 0; round < 10; round++) {
        int d = between(0, values.length - 1);
        longs.setNextDocId(d);
        assertEquals(values[d].length > 0 ? values[d][0] : 0, longs.getValue());
        assertEquals(values[d].length, longs.size());
        assertEquals(values[d].length, longs.getValues().size());
        for (int i = 0; i < values[d].length; i++) {
            assertEquals(values[d][i], longs.get(i).longValue());
            assertEquals(values[d][i], longs.getValues().get(i).longValue());
        }
        Exception e = expectThrows(UnsupportedOperationException.class, () -> longs.getValues().add(100L));
        assertEquals("doc values are unmodifiable", e.getMessage());
    }
}
Also used : Longs(org.elasticsearch.index.fielddata.ScriptDocValues.Longs)

Example 2 with Longs

use of org.elasticsearch.index.fielddata.ScriptDocValues.Longs in project elasticsearch by elastic.

the class ScriptDocValuesLongsTests method testDates.

public void testDates() {
    long[][] values = new long[between(3, 10)][];
    ReadableDateTime[][] dates = new ReadableDateTime[values.length][];
    for (int d = 0; d < values.length; d++) {
        values[d] = new long[randomBoolean() ? randomBoolean() ? 0 : 1 : between(2, 100)];
        dates[d] = new ReadableDateTime[values[d].length];
        for (int i = 0; i < values[d].length; i++) {
            dates[d][i] = new DateTime(randomNonNegativeLong(), DateTimeZone.UTC);
            values[d][i] = dates[d][i].getMillis();
        }
    }
    Longs longs = wrap(values);
    for (int round = 0; round < 10; round++) {
        int d = between(0, values.length - 1);
        longs.setNextDocId(d);
        assertEquals(dates[d].length > 0 ? dates[d][0] : new DateTime(0, DateTimeZone.UTC), longs.getDate());
        assertEquals(values[d].length, longs.getDates().size());
        for (int i = 0; i < values[d].length; i++) {
            assertEquals(dates[d][i], longs.getDates().get(i));
        }
        Exception e = expectThrows(UnsupportedOperationException.class, () -> longs.getDates().add(new DateTime()));
        assertEquals("doc values are unmodifiable", e.getMessage());
    }
    assertWarnings("getDate on numeric fields is deprecated. Use a date field to get dates.", "getDates on numeric fields is deprecated. Use a date field to get dates.");
}
Also used : ReadableDateTime(org.joda.time.ReadableDateTime) Longs(org.elasticsearch.index.fielddata.ScriptDocValues.Longs) ReadableDateTime(org.joda.time.ReadableDateTime) DateTime(org.joda.time.DateTime)

Aggregations

Longs (org.elasticsearch.index.fielddata.ScriptDocValues.Longs)2 DateTime (org.joda.time.DateTime)1 ReadableDateTime (org.joda.time.ReadableDateTime)1