private VersionedIntervalTimeline < String , DataSegment > buildVersionedIntervalTimeline ( final String dataSource , final Collection < Interval > intervals , final Handle handle ) { return VersionedIntervalTimeline . forSegments ( intervals . stream ( ) . flatMap ( interval -> handle . createQuery ( StringUtils . format ( "SELECT payload FROM %1$s WHERE dataSource = :dataSource AND start < :end AND %2$send%2$s > :start AND used = true" , getSegmentsTable ( ) , connector . getQuoteString ( ) ) ) . setFetchSize ( connector . getStreamingFetchSize ( ) ) . bind ( "dataSource" , dataSource ) . bind ( "start" , interval . getStart ( ) . toString ( ) ) . bind ( "end" , interval . getEnd ( ) . toString ( ) ) . map ( ( i , resultSet , context ) -> { try { return jsonMapper . readValue ( resultSet . getBytes ( "payload" ) , DataSegment . class ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } ) . list ( ) . stream ( ) ) . iterator ( ) ) ; }
Builds a VersionedIntervalTimeline containing used segments that overlap the intervals passed .