@Override public IndexSample sampleResult() { return new IndexSample(); }
public IndexSample result() { return new IndexSample( count, count, count ); } }
@Override public IndexSample sampleResult() { return new IndexSample(); }
@Override public IndexSample sampleIndex() { return new IndexSample( value, value, value * 2 ); } }
@Override public IndexSample sampleResult() { return new IndexSample(); } };
@Override public IndexSample sampleIndex() { return new IndexSample( sampleValue, sampleValue, sampleValue ); } }
@Override public IndexSample result( int numDocs ) { if ( !values.isEmpty() ) { nextStep(); } long uniqueValues = sampledSteps != 0 ? accumulatedUniqueValues / sampledSteps : 0; long sampledSize = sampledSteps != 0 ? accumulatedSampledSize / sampledSteps : 0; return new IndexSample( numDocs < 0 ? accumulatedSampledSize : numDocs, uniqueValues, sampledSize ); }
@Override public IndexSample sampleResult() { long indexSize = 0; for ( Set<Long> nodeIds : indexSamples.values() ) { indexSize += nodeIds.size(); } return new IndexSample( indexSize, indexSamples.size(), indexSize ); }
private static IndexPopulator createIndexPopulator() { IndexPopulator populator = mock( IndexPopulator.class ); when( populator.sampleResult() ).thenReturn( new IndexSample() ); return populator; }
@Before public void setup() throws IndexNotFoundKernelException { when( indexProxy.getDescriptor() ).thenReturn( indexDescriptor ); when( indexProxy.newReader() ).thenReturn( indexReader ); when( indexReader.createSampler() ).thenReturn( indexSampler ); when( indexSampler.sampleIndex() ).thenReturn( new IndexSample( indexSize, indexUniqueValues, indexSize ) ); } }
@Before public void setUp() { when( populator.sampleResult() ).thenReturn( new IndexSample() ); when( storeView.indexSample( anyLong(), any( DoubleLongRegister.class ) ) ) .thenAnswer( invocation -> invocation.getArgument( 1 ) ); }
@Test public void samplingOverPartitions() throws IndexNotFoundKernelException { PartitionedIndexReader indexReader = createPartitionedReaderFromReaders(); when( indexReader1.createSampler() ).thenReturn( new SimpleSampler( 1 ) ); when( indexReader2.createSampler() ).thenReturn( new SimpleSampler( 2 ) ); when( indexReader3.createSampler() ).thenReturn( new SimpleSampler( 3 ) ); IndexSampler sampler = indexReader.createSampler(); assertEquals( new IndexSample( 6, 6, 6 ), sampler.sampleIndex() ); }
@Test void sampleEmptyIndex() throws IOException { populator = newPopulator(); IndexSample sample = populator.sampleResult(); assertEquals( new IndexSample(), sample ); }
public IndexSample combine( IndexSample sample1, IndexSample sample2 ) { long indexSize = Math.addExact( sample1.indexSize(), sample2.indexSize() ); long uniqueValues = Math.addExact( sample1.uniqueValues(), sample2.uniqueValues() ); long sampleSize = Math.addExact( sample1.sampleSize(), sample2.sampleSize() ); return new IndexSample( indexSize, uniqueValues, sampleSize ); } }
@Test public void sampleEmptyIndex() throws Exception { populator = newPopulator(); IndexSample sample = populator.sampleResult(); assertEquals( new IndexSample(), sample ); }
@Test void sampleIncludedUpdates() throws Exception { populator = newPopulator(); List<IndexEntryUpdate<?>> updates = Arrays.asList( add( 1, labelSchemaDescriptor, "aaa" ), add( 2, labelSchemaDescriptor, "bbb" ), add( 3, labelSchemaDescriptor, "ccc" ) ); updates.forEach( populator::includeSample ); IndexSample sample = populator.sampleResult(); assertEquals( new IndexSample( 3, 3, 3 ), sample ); }
@Test void sampleIncludedUpdatesWithDuplicates() throws Exception { populator = newPopulator(); List<IndexEntryUpdate<?>> updates = Arrays.asList( add( 1, labelSchemaDescriptor, "foo" ), add( 2, labelSchemaDescriptor, "bar" ), add( 3, labelSchemaDescriptor, "foo" ) ); updates.forEach( populator::includeSample ); IndexSample sample = populator.sampleResult(); assertEquals( new IndexSample( 3, 2, 3 ), sample ); }
@Test void samplePartitionedIndex() { List<IndexSampler> samplers = Arrays.asList( createSampler( 1 ), createSampler( 2 ) ); AggregatingIndexSampler partitionedSampler = new AggregatingIndexSampler( samplers ); IndexSample sample = partitionedSampler.sampleIndex(); assertEquals( new IndexSample( 3, 3, 6 ), sample ); }
@Test public void sampleIncludedUpdates() throws Exception { LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel( 1, 1 ); populator = newPopulator(); List<IndexEntryUpdate<?>> updates = Arrays.asList( add( 1, schemaDescriptor, "foo" ), add( 2, schemaDescriptor, "bar" ), add( 3, schemaDescriptor, "baz" ), add( 4, schemaDescriptor, "qux" ) ); updates.forEach( populator::includeSample ); IndexSample sample = populator.sampleResult(); assertEquals( new IndexSample( 4, 4, 4 ), sample ); }
@Test void nonUniqueIndexSampling() throws Exception { Terms aTerms = getTerms( "a", 1 ); Terms idTerms = getTerms( "id", 2 ); Terms bTerms = getTerms( "b", 3 ); Map<String,Terms> fieldTermsMap = MapUtil.genericMap( "0string", aTerms, "id", idTerms, "0array", bTerms ); IndexReaderStub indexReader = new IndexReaderStub( new SamplingFields( fieldTermsMap ) ); indexReader.setElements( new String[4] ); when( indexSearcher.getIndexReader() ).thenReturn( indexReader ); assertEquals( new IndexSample( 4, 2, 4 ), createSampler().sampleIndex() ); }