next is the core functionality of this iterator and returns the next matching result. This may involve inspecting multiple row groups, pages, and values until a match is found. When we run out of things to inspect, it returns nil. The reason this method is distinct from Next() is because it doesn't
()
| 806 | // Next() is because it doesn't wrap the results in an IteratorResult, which is more efficient |
| 807 | // when being called multiple times and throwing away the results like in SeekTo(). |
| 808 | func (c *SyncIterator) next() (RowNumber, *pq.Value, error) { |
| 809 | for { |
| 810 | if c.currRowGroup == nil { |
| 811 | rg, minRN, maxRN := c.popRowGroup() |
| 812 | if rg == nil { |
| 813 | return EmptyRowNumber(), nil, nil |
| 814 | } |
| 815 | |
| 816 | cc := &ColumnChunkHelper{ColumnChunk: rg.ColumnChunks()[c.column]} |
| 817 | if c.filter != nil && !c.filter.KeepColumnChunk(cc) { |
| 818 | cc.Close() |
| 819 | continue |
| 820 | } |
| 821 | |
| 822 | c.setRowGroup(rg, minRN, maxRN, cc) |
| 823 | } |
| 824 | |
| 825 | if c.currPage == nil { |
| 826 | pg, err := c.currChunk.NextPage() |
| 827 | if err != nil && !errors.Is(err, io.EOF) { |
| 828 | return EmptyRowNumber(), nil, err |
| 829 | } |
| 830 | if pg == nil || errors.Is(err, io.EOF) { |
| 831 | // This row group is exhausted |
| 832 | c.closeCurrRowGroup() |
| 833 | continue |
| 834 | } |
| 835 | if c.filter != nil && !c.filter.KeepPage(pg) { |
| 836 | // This page filtered out |
| 837 | c.curr.Skip(pg.NumRows()) |
| 838 | pq.Release(pg) |
| 839 | continue |
| 840 | } |
| 841 | c.setPage(pg) |
| 842 | } |
| 843 | |
| 844 | // Read next batch of values if needed |
| 845 | if c.currBuf == nil { |
| 846 | c.currBuf = syncIteratorPoolGet(c.readSize, 0) |
| 847 | } |
| 848 | if c.currBufN >= len(c.currBuf) || len(c.currBuf) == 0 { |
| 849 | c.currBuf = c.currBuf[:cap(c.currBuf)] |
| 850 | n, err := c.currValues.ReadValues(c.currBuf) |
| 851 | if err != nil && !errors.Is(err, io.EOF) { |
| 852 | return EmptyRowNumber(), nil, err |
| 853 | } |
| 854 | c.currBuf = c.currBuf[:n] |
| 855 | c.currBufN = 0 |
| 856 | if n == 0 { |
| 857 | // This value reader and page are exhausted. |
| 858 | c.setPage(nil) |
| 859 | continue |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | // Consume current buffer until empty |
| 864 | for c.currBufN < len(c.currBuf) { |
| 865 | v := &c.currBuf[c.currBufN] |
no test coverage detected