public QueryableIndex cache ( String dataSource , Iterable < InputRow > loader , IncrementalIndexSchema indexSchema ) throws IOException { IncrementalIndex < ? > incIndex = new OnheapIncrementalIndex ( indexSchema , true , Integer . MAX_VALUE ) ; for ( InputRow row : loader ) { incIndex . add ( row ) ; } String tmpDir = System . getProperty ( "druid.segment.dir" ) ; if ( tmpDir == null ) { tmpDir = System . getProperty ( "java.io.tmpdir" ) + File . separator + "druid-tmp-index-" ; } File tmpIndexDir = new File ( tmpDir + loader . hashCode ( ) ) ; IndexIO indexIO = new IndexIO ( new DefaultObjectMapper ( ) , new ColumnConfig ( ) { @ Override public int columnCacheSizeBytes ( ) { return 0 ; } } ) ; if ( OSCheck . isWindows ( ) ) { new SlowIndexMerger ( new DefaultObjectMapper ( ) , indexIO ) . persist ( incIndex , tmpIndexDir , new IndexSpec ( ) ) ; } else { new IndexMerger ( new DefaultObjectMapper ( ) , indexIO ) . persist ( incIndex , tmpIndexDir , new IndexSpec ( ) ) ; } this . indexMap . put ( dataSource , indexIO . loadIndex ( tmpIndexDir ) ) ; return this . indexMap . get ( dataSource ) ; }
Builds and caches a QueryableIndex from an Iterable by building persisting and reloading an IncrementalIndex