Search in sources :

Example 1 with Seeker

use of org.neo4j.index.internal.gbptree.Seeker in project neo4j by neo4j.

the class GenericNativeIndexAccessor method newAllEntriesValueReader.

@Override
public IndexEntriesReader[] newAllEntriesValueReader(int partitions, CursorContext cursorContext) {
    GenericKey lowest = layout.newKey();
    lowest.initialize(Long.MIN_VALUE);
    lowest.initValuesAsLowest();
    GenericKey highest = layout.newKey();
    highest.initialize(Long.MAX_VALUE);
    highest.initValuesAsHighest();
    try {
        Collection<Seeker<GenericKey, NativeIndexValue>> seekers = tree.partitionedSeek(lowest, highest, partitions, cursorContext);
        Collection<IndexEntriesReader> readers = new ArrayList<>();
        for (Seeker<GenericKey, NativeIndexValue> seeker : seekers) {
            readers.add(new IndexEntriesReader() {

                @Override
                public long next() {
                    return seeker.key().getEntityId();
                }

                @Override
                public boolean hasNext() {
                    try {
                        return seeker.next();
                    } catch (IOException e) {
                        throw new UncheckedIOException(e);
                    }
                }

                @Override
                public Value[] values() {
                    return seeker.key().asValues();
                }

                @Override
                public void close() {
                    try {
                        seeker.close();
                    } catch (IOException e) {
                        throw new UncheckedIOException(e);
                    }
                }
            });
        }
        return readers.toArray(IndexEntriesReader[]::new);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : IndexEntriesReader(org.neo4j.kernel.api.index.IndexEntriesReader) Seeker(org.neo4j.index.internal.gbptree.Seeker) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 2 with Seeker

use of org.neo4j.index.internal.gbptree.Seeker in project neo4j by neo4j.

the class CombinedPartSeekerTest method shouldCombineAllParts.

@Test
void shouldCombineAllParts() throws IOException {
    // given
    SimpleLongLayout layout = longLayout().withFixedSize(true).build();
    List<Seeker<MutableLong, MutableLong>> parts = new ArrayList<>();
    int partCount = random.nextInt(1, 20);
    List<Pair<MutableLong, MutableLong>> expectedAllData = new ArrayList<>();
    int maxKey = random.nextInt(100, 10_000);
    for (int i = 0; i < partCount; i++) {
        int dataSize = random.nextInt(0, 100);
        List<Pair<MutableLong, MutableLong>> partData = new ArrayList<>(dataSize);
        for (int j = 0; j < dataSize; j++) {
            long key = random.nextLong(maxKey);
            partData.add(Pair.of(new MutableLong(key), new MutableLong(key * 2)));
        }
        partData.sort(HIT_COMPARATOR);
        parts.add(new SimpleSeeker(partData));
        expectedAllData.addAll(partData);
    }
    expectedAllData.sort(HIT_COMPARATOR);
    // when
    CombinedPartSeeker<MutableLong, MutableLong> combinedSeeker = new CombinedPartSeeker<>(layout, parts);
    // then
    for (Pair<MutableLong, MutableLong> expectedHit : expectedAllData) {
        assertTrue(combinedSeeker.next());
        assertEquals(expectedHit.getKey().longValue(), combinedSeeker.key().longValue());
        assertEquals(expectedHit.getValue().longValue(), combinedSeeker.value().longValue());
    }
    assertFalse(combinedSeeker.next());
    // And just ensure it will return false again after that
    assertFalse(combinedSeeker.next());
}
Also used : Seeker(org.neo4j.index.internal.gbptree.Seeker) ArrayList(java.util.ArrayList) SimpleLongLayout(org.neo4j.index.internal.gbptree.SimpleLongLayout) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)2 Seeker (org.neo4j.index.internal.gbptree.Seeker)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Test (org.junit.jupiter.api.Test)1 SimpleLongLayout (org.neo4j.index.internal.gbptree.SimpleLongLayout)1 IndexEntriesReader (org.neo4j.kernel.api.index.IndexEntriesReader)1