Class StatsCapturingIterator
java.lang.Object
org.elasticsearch.xpack.esql.datasources.cache.StatsCapturingIterator
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterator<Page>,CloseableIterator<Page>,ColumnExtractorProducer
public final class StatsCapturingIterator
extends Object
implements CloseableIterator<Page>, ColumnExtractorProducer
Wraps a
The wrapper unconditionally declares the
CloseableIterator so the iterator's close() runs with an
ExternalStatsCapture sink bound on the current thread. The text-format iterators'
close hooks call ExternalStatsCapture.record(...) on the bound sink; whichever
operator drove the iteration owns the sink and reads its contents back via
AsyncExternalSourceBuffer#capturedSourceMetadataSnapshot() or equivalent.
The wrapper is a thin pass-through for hasNext / next; the only behavior
change is at close time. Multiple iterators wrapped against the same sink accumulate
contributions in the sink — natural fit for multi-file and multi-split paths.
ColumnExtractorProducer forwarding
The wrapper unconditionally declares the ColumnExtractorProducer capability and forwards
createColumnExtractor() / setExtractorId(int) to its delegate, mirroring
SchemaAdaptingIterator. A non-producer delegate makes the consumer's
instanceof ColumnExtractorProducer check a necessary-but-not-sufficient guard — the
dispatch into the delegate fails loud (see innerProducer()). Without this forwarding the
stats wrapper would hide a producer-capable reader from the deferred-extraction wiring in
AsyncExternalSourceOperatorFactory#wrapWithEncoderIfNeeded, breaking _rowPosition
encoding whenever stats capture and deferred extraction are both active on the same read.-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Creates theColumnExtractormatching this iterator's addressing space.booleanhasNext()next()voidsetExtractorId(int id) Hands the iterator theSourceExtractors-assigned id under which its matchingColumnExtractoris registered.Forward the async-ready signal to the delegate.static CloseableIterator<Page> wrap(CloseableIterator<Page> delegate, ConcurrentMap<String, List<Map<String, Object>>> sink) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Method Details
-
wrap
public static CloseableIterator<Page> wrap(CloseableIterator<Page> delegate, ConcurrentMap<String, List<Map<String, Object>>> sink) -
hasNext
public boolean hasNext() -
next
-
waitForReady
Forward the async-ready signal to the delegate. This wrapper is a thin pass-through forhasNext/next, so it must be one for readiness too: the producer-loop drain callswaitForReady()on the outermost iterator and parks the executor thread while it is not done. Without this override the defaultCloseableIterator.waitForReady()(immediately done) would swallow the delegate's real signal, and the drain would fall through to a blockinghasNext()on a parser-backed delegate — the multi-file text-read deadlock.- Specified by:
waitForReadyin interfaceCloseableIterator<Page>
-
tryAdvance
- Specified by:
tryAdvancein interfaceCloseableIterator<Page>
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
createColumnExtractor
Description copied from interface:ColumnExtractorProducerCreates theColumnExtractormatching this iterator's addressing space.The iterator must already be positioned to emit pages with
ColumnExtractor.ROW_POSITION_COLUMNbefore this is called; implementations may capture iterator-internal state (such as a range-restricted footer) at construction time.- Specified by:
createColumnExtractorin interfaceColumnExtractorProducer- Throws:
IOException
-
setExtractorId
public void setExtractorId(int id) Description copied from interface:ColumnExtractorProducerHands the iterator theSourceExtractors-assigned id under which its matchingColumnExtractoris registered. Must be called once, afterColumnExtractorProducer.createColumnExtractor()and before the first page is drained. Every subsequent page the iterator emits must carry_rowPositionvalues already encoded with this id (typically by OR-ing((long) id << 48)into each value as it is materialised).Calling this method twice on the same iterator, or skipping it on the deferred path, is a programmer error: the iterator's pages either carry mismatched ids or unencoded raw row offsets that the lookup registry cannot route.
- Specified by:
setExtractorIdin interfaceColumnExtractorProducer- Parameters:
id- registry-assigned extractor id; must be in[0, MAX_EXTRACTOR_ID](seeSourceExtractors)
-