LabelScanViewIdIterator( LabelScanReader labelScanReader, int[] labelIds, CURSOR entityCursor ) { this.labelScanReader = labelScanReader; this.entityCursor = entityCursor; this.idIterator = labelScanReader.nodesWithAnyOfLabels( labelIds ); this.labelIds = labelIds; }
/** * @param fromId entity id to start at, exclusive, i.e. the given {@code fromId} will not be included in the result. * @param labelIds label token ids. * @return node ids with any of the given label ids. */ PrimitiveLongResourceIterator nodesWithAnyOfLabels( long fromId, int[] labelIds );
@Override public void invalidateCache() { this.idIterator.close(); this.idIterator = labelScanReader.nodesWithAnyOfLabels( lastReturnedId, labelIds ); } }
@Override public void nodeLabelUnionScan( NodeLabelIndexCursor cursor, int... labels ) { ktx.assertOpen(); DefaultNodeLabelIndexCursor client = (DefaultNodeLabelIndexCursor) cursor; client.setRead( this ); client.unionScan( new NodeLabelIndexProgressor( labelScanReader().nodesWithAnyOfLabels( labels ), client ), false, labels ); }
@Test public void visitOnlyLabeledNodes() throws Exception { LabelScanReader labelScanReader = mock( LabelScanReader.class ); when( labelScanStore.newReader() ).thenReturn( labelScanReader ); when( nodeLabelRanges.maxCount() ).thenReturn( 1L ); PrimitiveLongResourceIterator labeledNodesIterator = PrimitiveLongResourceCollections.iterator( null, 1, 2, 3, 4, 5, 6, 7, 8 ); when( nodeStore.getHighestPossibleIdInUse() ).thenReturn( 200L ); when( nodeStore.getHighId() ).thenReturn( 20L ); when( labelScanReader.nodesWithAnyOfLabels( new int[] {2, 6} ) ).thenReturn( labeledNodesIterator ); when( nodeStore.openPageCursorForReading( anyLong() ) ).thenReturn( mock( PageCursor.class ) ); mockLabelNodeCount( countStore, 2 ); mockLabelNodeCount( countStore, 6 ); DynamicIndexStoreView storeView = dynamicIndexStoreView(); StoreScan<Exception> storeScan = storeView .visitNodes( new int[]{2, 6}, propertyKeyIdFilter, propertyUpdateVisitor, labelUpdateVisitor, false ); storeScan.run(); Mockito.verify( nodeStore, times( 8 ) ) .getRecordByCursor( anyLong(), any( NodeRecord.class ), any( RecordLoad.class ), any( PageCursor.class ) ); }
@Test public void iterateOverLabeledNodeIds() { PrimitiveLongResourceIterator labeledNodes = PrimitiveLongResourceCollections.iterator( null, 1, 2, 4, 8 ); when( nodeStore.getHighId() ).thenReturn( 15L ); int[] labelIds = new int[]{1, 2}; when( labelScanReader.nodesWithAnyOfLabels( labelIds ) ).thenReturn( labeledNodes ); LabelScanViewNodeStoreScan<Exception> storeScan = getLabelScanViewStoreScan( labelIds ); PrimitiveLongResourceIterator idIterator = storeScan.getEntityIdIterator(); List<Long> visitedNodeIds = PrimitiveLongCollections.asList( idIterator ); assertThat(visitedNodeIds, Matchers.hasSize( 4 )); assertThat( visitedNodeIds, Matchers.hasItems( 1L, 2L, 4L, 8L ) ); }
PrimitiveLongCollections.asArray( reader.nodesWithAnyOfLabels( new int[] {labelId1, labelId2} ) ) ); assertArrayEquals( new long[] {1, 2, 3, 4, 5, 8, 9}, PrimitiveLongCollections.asArray( reader.nodesWithAnyOfLabels( new int[] {labelId1, labelId3} ) ) ); assertArrayEquals( new long[] {1, 2, 3, 4, 5, 6, 7, 8, 9}, PrimitiveLongCollections.asArray( reader.nodesWithAnyOfLabels( new int[] {labelId1, labelId2, labelId3} ) ) );
LabelScanViewIdIterator( LabelScanReader labelScanReader, int[] labelIds, CURSOR entityCursor ) { this.labelScanReader = labelScanReader; this.entityCursor = entityCursor; this.idIterator = labelScanReader.nodesWithAnyOfLabels( labelIds ); this.labelIds = labelIds; }
/** * @param fromId entity id to start at, exclusive, i.e. the given {@code fromId} will not be included in the result. * @param labelIds label token ids. * @return node ids with any of the given label ids. */ PrimitiveLongResourceIterator nodesWithAnyOfLabels( long fromId, int[] labelIds );
@Override public void invalidateCache() { this.idIterator.close(); this.idIterator = labelScanReader.nodesWithAnyOfLabels( lastReturnedId, labelIds ); } }
@Override public void nodeLabelUnionScan( NodeLabelIndexCursor cursor, int... labels ) { ktx.assertOpen(); DefaultNodeLabelIndexCursor client = (DefaultNodeLabelIndexCursor) cursor; client.setRead( this ); client.unionScan( new NodeLabelIndexProgressor( labelScanReader().nodesWithAnyOfLabels( labels ), client ), false, labels ); }