Add getPages method to PagesIndex
@@ -24,6 +24,7 @@ import com.facebook.presto.sql.gen.JoinCompiler;
import com.facebook.presto.sql.gen.JoinCompiler.LookupSourceSupplierFactory;
import com.facebook.presto.sql.gen.JoinFilterFunctionCompiler.JoinFilterFunctionFactory;
import com.facebook.presto.sql.gen.OrderingCompiler;
+import com.google.common.collect.AbstractIterator;
import com.google.common.collect.ImmutableList;
import io.airlift.log.Logger;
import io.airlift.slice.Slice;
@@ -35,10 +36,12 @@ import org.openjdk.jol.info.ClassLayout;
import javax.inject.Inject;
+import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.IntStream;
+import java.util.stream.Stream;
import static com.facebook.presto.operator.SyntheticAddress.decodePosition;
import static com.facebook.presto.operator.SyntheticAddress.decodeSliceIndex;
@@ -477,4 +480,26 @@ public class PagesIndex
.add("estimatedSize", estimatedSize)
.toString();
}
+
+ public Iterator<Page> getPages()
+ {
+ return new AbstractIterator<Page>()
+ {
+ private int pageCounter;
+
+ @Override
+ protected Page computeNext()
+ {
+ if (pageCounter == channels[0].size()) {
+ return endOfData();
+ }
+
+ Block[] blocks = Stream.of(channels)
+ .map(channel -> channel.get(pageCounter))
+ .toArray(Block[]::new);
+ pageCounter++;
+ return new Page(blocks);
+ }
+ };
+ }
}
