Search in sources :

Example 26 with PrimitiveLongIterator

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

the class StorageLayerLabelTest method should_return_all_nodes_with_label.

@Test
public void should_return_all_nodes_with_label() throws Exception {
    // GIVEN
    Node node1 = createLabeledNode(db, map("name", "First", "age", 1L), label1);
    Node node2 = createLabeledNode(db, map("type", "Node", "count", 10), label1, label2);
    int labelId1 = disk.labelGetForName(label1.name());
    int labelId2 = disk.labelGetForName(label2.name());
    // WHEN
    PrimitiveLongIterator nodesForLabel1 = disk.nodesGetForLabel(state.getStoreStatement(), labelId1);
    PrimitiveLongIterator nodesForLabel2 = disk.nodesGetForLabel(state.getStoreStatement(), labelId2);
    // THEN
    assertEquals(asSet(node1.getId(), node2.getId()), PrimitiveLongCollections.toSet(nodesForLabel1));
    assertEquals(asSet(node2.getId()), PrimitiveLongCollections.toSet(nodesForLabel2));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 27 with PrimitiveLongIterator

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

the class LabelScanViewNodeStoreScanTest method iterateOverLabeledNodeIds.

@Test
public void iterateOverLabeledNodeIds() throws Exception {
    PrimitiveLongIterator labeledNodes = PrimitiveLongCollections.iterator(1, 2, 4, 8);
    when(nodeStore.getHighId()).thenReturn(15L);
    when(labelScanReader.nodesWithAnyOfLabels(1, 2)).thenReturn(labeledNodes);
    int[] labelIds = new int[] { 1, 2 };
    LabelScanViewNodeStoreScan<Exception> storeScan = getLabelScanViewStoreScan(labelIds);
    PrimitiveLongResourceIterator idIterator = storeScan.getNodeIdIterator();
    List<Long> visitedNodeIds = PrimitiveLongCollections.asList(idIterator);
    assertThat(visitedNodeIds, Matchers.hasSize(4));
    assertThat(visitedNodeIds, Matchers.hasItems(1L, 2L, 4L, 8L));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) PrimitiveLongResourceIterator(org.neo4j.collection.primitive.PrimitiveLongResourceIterator) Test(org.junit.Test)

Example 28 with PrimitiveLongIterator

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

the class FullTxData method internalQuery.

private Collection<EntityId> internalQuery(Query query, QueryContext contextOrNull) {
    if (this.directory == null) {
        return Collections.emptySet();
    }
    try {
        Sort sorting = contextOrNull != null ? contextOrNull.getSorting() : null;
        boolean prioritizeCorrectness = contextOrNull == null || !contextOrNull.getTradeCorrectnessForSpeed();
        IndexSearcher theSearcher = searcher(prioritizeCorrectness);
        query = includeOrphans(query);
        DocValuesCollector docValuesCollector = new DocValuesCollector(prioritizeCorrectness);
        theSearcher.search(query, docValuesCollector);
        Collection<EntityId> result = new ArrayList<>();
        PrimitiveLongIterator valuesIterator = docValuesCollector.getSortedValuesIterator(KEY_DOC_ID, sorting);
        while (valuesIterator.hasNext()) {
            result.add(new EntityId.IdData(valuesIterator.next()));
        }
        return result;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) ArrayList(java.util.ArrayList) Sort(org.apache.lucene.search.Sort) IOException(java.io.IOException)

Example 29 with PrimitiveLongIterator

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

the class RecordIdIteratorTest method assertIds.

private void assertIds(RecordIdIterator ids, long[]... expectedIds) {
    for (long[] expectedArray : expectedIds) {
        PrimitiveLongIterator iterator = ids.nextBatch();
        assertNotNull(iterator);
        for (long expectedId : expectedArray) {
            assertEquals(expectedId, iterator.next());
        }
        assertFalse(iterator.hasNext());
    }
    assertNull(ids.nextBatch());
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator)

Example 30 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j-apoc-procedures by neo4j-contrib.

the class PregelTest method runPageRank.

@Test
public void runPageRank() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(GraphDatabaseSettings.pagecache_memory, "100M").newGraphDatabase();
    int nodeCount = 100_001;
    int[] degrees = new int[nodeCount];
    createRankTestData(db, nodeCount, degrees);
    long start = System.currentTimeMillis();
    Pregel pregel = new Pregel(db, guard).withBatchSize(10000);
    PrimitiveLongIterator nodes;
    try (Transaction tx = db.beginTx()) {
        ReadOperations reads = pregel.statement().readOperations();
        nodes = reads.nodesGetAll();
        tx.success();
    }
    float[] ranks = pregel.runProgram2(nodes, new Pregel.AllExpander(), new PageRankProgram(nodeCount, degrees, new float[nodeCount], new LinkedList<>()));
    long time = System.currentTimeMillis() - start;
    Arrays.sort(ranks);
    // System.err.println("PageRank Program ran for "+nodeCount+" nodes in "+time+" ms. 10 hightest Ranks "+Arrays.toString(Arrays.copyOfRange(ranks,ranks.length-10,ranks.length)));
    db.shutdown();
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) ReadOperations(org.neo4j.kernel.api.ReadOperations) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Aggregations

PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)68 Test (org.junit.Test)47 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)15 Transaction (org.neo4j.graphdb.Transaction)10 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)10 ReadOperations (org.neo4j.kernel.api.ReadOperations)8 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)8 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)8 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)8 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)8 IOException (java.io.IOException)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Node (org.neo4j.graphdb.Node)4 Statement (org.neo4j.kernel.api.Statement)4 DiffSets (org.neo4j.kernel.impl.util.diffsets.DiffSets)4 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)4 ArrayList (java.util.ArrayList)3 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2