Search in sources :

Example 11 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class PartitionedLuceneLabelScanStoreReaderTest method nodesWithLabelOverPartitions.

@Test
public void nodesWithLabelOverPartitions() {
    PartitionedLuceneLabelScanStoreReader storeReader = createPartitionedReaderWithReaders();
    when(indexReader1.nodesWithLabel(1)).thenReturn(PrimitiveLongCollections.iterator(1));
    when(indexReader2.nodesWithLabel(1)).thenReturn(PrimitiveLongCollections.iterator(2));
    when(indexReader3.nodesWithLabel(1)).thenReturn(PrimitiveLongCollections.iterator(3));
    PrimitiveLongSet result = PrimitiveLongCollections.asSet(storeReader.nodesWithLabel(1));
    verifyResult(result);
}
Also used : PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Test(org.junit.Test)

Example 12 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class PartitionedIndexReaderTest method rangeSeekByStringOverPartitions.

@Test
public void rangeSeekByStringOverPartitions() throws Exception {
    PartitionedIndexReader indexReader = createPartitionedReaderFromReaders();
    IndexQuery.StringRangePredicate query = IndexQuery.range(1, "a", false, "b", true);
    when(indexReader1.query(query)).thenReturn(PrimitiveLongCollections.iterator(1));
    when(indexReader2.query(query)).thenReturn(PrimitiveLongCollections.iterator(2));
    when(indexReader3.query(query)).thenReturn(PrimitiveLongCollections.iterator(3));
    PrimitiveLongSet results = PrimitiveLongCollections.asSet(indexReader.query(query));
    verifyResult(results);
}
Also used : IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Test(org.junit.Test)

Example 13 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class PartitionedIndexReaderTest method seekOverAllPartitions.

@Test
public void seekOverAllPartitions() throws Exception {
    PartitionedIndexReader indexReader = createPartitionedReaderFromReaders();
    IndexQuery.ExactPredicate query = IndexQuery.exact(1, "Test");
    when(indexReader1.query(query)).thenReturn(PrimitiveLongCollections.iterator(1));
    when(indexReader2.query(query)).thenReturn(PrimitiveLongCollections.iterator(2));
    when(indexReader3.query(query)).thenReturn(PrimitiveLongCollections.iterator(3));
    PrimitiveLongSet results = PrimitiveLongCollections.asSet(indexReader.query(query));
    verifyResult(results);
}
Also used : IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Test(org.junit.Test)

Example 14 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategy method labelsForNode.

@Override
public PrimitiveLongIterator labelsForNode(IndexSearcher searcher, long nodeId) {
    try {
        TopDocs topDocs = searcher.search(format.rangeQuery(format.bitmapFormat().rangeOf(nodeId)), 1);
        if (topDocs.scoreDocs.length < 1) {
            return PrimitiveLongCollections.emptyIterator();
        } else if (topDocs.scoreDocs.length > 1) {
            throw new RuntimeException("This label scan store seems to contain an incorrect number of entries (" + topDocs.scoreDocs.length + ")");
        }
        int doc = topDocs.scoreDocs[0].doc;
        PrimitiveLongSet labels = Primitive.longSet();
        for (IndexableField fields : searcher.doc(doc).getFields()) {
            if ("range".equals(fields.name())) {
                continue;
            }
            Number numericValue = fields.numericValue();
            if (numericValue != null) {
                Long bitmap = numericValue.longValue();
                if (format.bitmapFormat().hasLabel(bitmap, nodeId)) {
                    labels.add(Long.decode(fields.name()));
                }
            }
        }
        return labels.iterator();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) IndexableField(org.apache.lucene.index.IndexableField) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) IOException(java.io.IOException)

Example 15 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class NodeLabelReader method getListOfLabels.

public static long[] getListOfLabels(NodeRecord nodeRecord, RecordStore<DynamicRecord> labels) {
    long field = nodeRecord.getLabelField();
    if (NodeLabelsField.fieldPointsToDynamicRecordOfLabels(field)) {
        List<DynamicRecord> recordList = new ArrayList<>();
        PrimitiveLongSet alreadySeen = Primitive.longSet(16);
        long id = NodeLabelsField.firstDynamicLabelRecordId(field);
        while (!Record.NULL_REFERENCE.is(id)) {
            DynamicRecord record = labels.getRecord(id, labels.newRecord(), FORCE);
            if (!record.inUse() || !alreadySeen.add(id)) {
                return PrimitiveLongCollections.EMPTY_LONG_ARRAY;
            }
            recordList.add(record);
        }
        return LabelChainWalker.labelIds(recordList);
    }
    return InlineNodeLabels.get(nodeRecord);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) ArrayList(java.util.ArrayList)

Aggregations

PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)36 Test (org.junit.Test)27 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)5 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)5 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 Statement (org.neo4j.kernel.api.Statement)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 IOException (java.io.IOException)3 CCVar (apoc.algo.wcc.CCVar)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CCResult (apoc.result.CCResult)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringReader (java.io.StringReader)1 java.util (java.util)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1