public Batch < T > getWrites ( WriteBuilder writeBuilder , T op ) { Map < Address , T > outputMap = Maps . newHashMap ( ) ; for ( Rollup rollup : rollups ) { List < Set < byte [ ] > > coordSets = new ArrayList < Set < byte [ ] > > ( rollup . getComponents ( ) . size ( ) ) ; boolean dimensionHadNoBucket = false ; for ( DimensionAndBucketType dimAndBucketType : rollup . getComponents ( ) ) { Dimension < ? > dimension = dimAndBucketType . dimension ; BucketType bucketType = dimAndBucketType . bucketType ; SetMultimap < BucketType , byte [ ] > bucketsForDimension = writeBuilder . getBuckets ( ) . get ( dimension ) ; if ( bucketsForDimension == null || bucketsForDimension . isEmpty ( ) ) { dimensionHadNoBucket = true ; break ; } Set < byte [ ] > coords = bucketsForDimension . get ( bucketType ) ; if ( coords == null || coords . isEmpty ( ) ) { dimensionHadNoBucket = true ; break ; } coordSets . add ( coords ) ; } if ( dimensionHadNoBucket ) { // Skip this rollup since one of its input buckets was not present. log . debug ( "Skipping rollup due to dimension with no buckets" ) ; continue ; } Set < List < byte [ ] > > crossProduct = Sets . cartesianProduct ( coordSets ) ; for ( List < byte [ ] > crossProductTuple : crossProduct ) { Address outputAddress = new Address ( this , rollup ) ; // Start out with all dimensions wildcard, overwrite with other values later for ( Dimension < ? > dimension : dims ) { outputAddress . at ( dimension , BucketTypeAndBucket . WILDCARD ) ; } for ( int i = 0 ; i < crossProductTuple . size ( ) ; i ++ ) { byte [ ] coord = crossProductTuple . get ( i ) ; Dimension < ? > dim = rollup . getComponents ( ) . get ( i ) . dimension ; BucketType bucketType = rollup . getComponents ( ) . get ( i ) . bucketType ; outputAddress . at ( dim , new BucketTypeAndBucket ( bucketType , coord ) ) ; } boolean shouldWrite = true ; if ( shouldWrite ) { outputMap . put ( outputAddress , op ) ; } } } return new Batch < T > ( outputMap ) ; }
Get a batch of writes that when applied to the database will make the change given by op .