Buggy code:
@ Override public Sequence < Result < TopNResultValue > > mergeSequencesUnordered ( Sequence < Sequence < Result < TopNResultValue > > > seqOfSequences ) { } @ Override public Builder makeMetricBuilder ( TopNQuery query ) { } @ Override public Function < Result < TopNResultValue > , Result < TopNResultValue > > makePreComputeManipulatorFn ( final TopNQuery query , final MetricManipulationFn fn ) { } @ Override public Function < Result < TopNResultValue > , Result < TopNResultValue > > makePostComputeManipulatorFn ( final TopNQuery query , final MetricManipulationFn fn ) { } @ Override public TypeReference < Result < TopNResultValue > > getResultTypeReference ( ) { } @ Override public CacheStrategy < Result < TopNResultValue > , Object , TopNQuery > getCacheStrategy ( final TopNQuery query ) { return new CacheStrategy < Result < TopNResultValue > , Object , TopNQuery > ( ) { private final List < AggregatorFactory > aggs = Lists . newArrayList ( query . getAggregatorSpecs ( ) ) ; private final List < PostAggregator > postAggs = AggregatorUtil . pruneDependentPostAgg ( query . getPostAggregatorSpecs ( ) , query . getTopNMetricSpec ( ) . getMetricName ( query . getDimensionSpec ( ) ) ) ; @ Override public byte [ ] computeCacheKey ( TopNQuery query ) { final byte [ ] dimensionSpecBytes = query . getDimensionSpec ( ) . getCacheKey ( ) ; final byte [ ] metricSpecBytes = query . getTopNMetricSpec ( ) . getCacheKey ( ) ; final DimFilter dimFilter = query . getDimensionsFilter ( ) ; final byte [ ] filterBytes = ( dimFilter == null ) ? new byte [ ] { } : dimFilter . getCacheKey ( ) ; final byte [ ] aggregatorBytes = QueryCacheHelper . computeAggregatorBytes ( query . getAggregatorSpecs ( ) ) ; final byte [ ] granularityBytes = query . getGranularity ( ) . cacheKey ( ) ; return ByteBuffer . allocate ( ( ( ( ( ( ( 1 + ( dimensionSpecBytes . length ) ) + ( metricSpecBytes . length ) ) + 4 ) + ( granularityBytes . length ) ) + ( filterBytes . length ) ) + ( aggregatorBytes . length ) ) ) . put ( TopNQueryQueryToolChest . TOPN_QUERY ) . put ( dimensionSpecBytes ) . put ( metricSpecBytes ) . put ( Ints . toByteArray ( query . getThreshold ( ) ) ) . put ( granularityBytes ) . put ( filterBytes ) . put ( aggregatorBytes ) . array ( ) ; } @ Override public TypeReference < Object > getCacheObjectClazz ( ) { return TopNQueryQueryToolChest . OBJECT_TYPE_REFERENCE ; } @ Override public Function < Result < TopNResultValue > , Object > prepareForCache ( ) { return new Function < Result < TopNResultValue > , Object > ( ) { private final String [ ] aggFactoryNames = TopNQueryQueryToolChest . extractFactoryName ( query . getAggregatorSpecs ( ) ) ; @ Override public Object apply ( final Result < TopNResultValue > input ) { List < DimensionAndMetricValueExtractor > results = Lists . newArrayList ( input . getValue ( ) ) ; final List < Object > retVal = Lists . newArrayListWithCapacity ( ( ( results . size ( ) ) + 1 ) ) ; retVal . add ( input . getTimestamp ( ) . getMillis ( ) ) ; for ( DimensionAndMetricValueExtractor result : results ) { List < Object > vals = Lists . newArrayListWithCapacity ( ( ( aggFactoryNames . length ) + 2 ) ) ; vals . add ( result . getStringDimensionValue ( query . getDimensionSpec ( ) . getOutputName ( ) ) ) ; for ( String aggName : aggFactoryNames ) { vals . add ( result . getMetric ( aggName ) ) ; } retVal . add ( vals ) ; } return retVal ; } } ; } @ Override public Function < Object , Result < TopNResultValue > > pullFromCache ( ) { return new Function < Object , Result < TopNResultValue > > ( ) { private final QueryGranularity granularity = query . getGranularity ( ) ; @ Override public Result < TopNResultValue > apply ( Object input ) { List < Object > results = ( ( List < Object > ) ( input ) ) ; List < Map < String , Object > > retVal = Lists . newArrayListWithCapacity ( results . size ( ) ) ; Iterator < Object > inputIter = results . iterator ( ) ; <START_BUG> DateTime timestamp = granularity . toDateTime ( new DateTime ( inputIter . next ( ) ) . getMillis ( ) ) ; <END_BUG> while ( inputIter . hasNext ( ) ) { List < Object > result = ( ( List < Object > ) ( inputIter . next ( ) ) ) ; Map < String , Object > vals = Maps . newLinkedHashMap ( ) ; Iterator < AggregatorFactory > aggIter = aggs . iterator ( ) ; Iterator < Object > resultIter = result . iterator ( ) ; vals . put ( query . getDimensionSpec ( ) . getOutputName ( ) , resultIter . next ( ) ) ; while ( ( aggIter . hasNext ( ) ) && ( resultIter . hasNext ( ) ) ) { final AggregatorFactory factory = aggIter . next ( ) ; vals . put ( factory . getName ( ) , factory . deserialize ( resultIter . next ( ) ) ) ; } for ( PostAggregator postAgg : postAggs ) { vals . put ( postAgg . getName ( ) , postAgg . compute ( vals ) ) ; } retVal . add ( vals ) ; } return new Result ( timestamp , new TopNResultValue ( retVal ) ) ; } } ; } @ Override public Sequence < Result < TopNResultValue > > mergeSequences ( Sequence < Sequence < Result < TopNResultValue > > > seqOfSequences ) { return new com . metamx . common . guava . MergeSequence ( getOrdering ( ) , seqOfSequences ) ; }

Fix:
DateTime timestamp = granularity . toDateTime ( ( ( Number ) ( inputIter . next ( ) ) ) . longValue ( ) ) ;