Class SkipWarnings

java.lang.Object
org.elasticsearch.xpack.esql.datasources.spi.SkipWarnings

public class SkipWarnings extends Object
Collects response Warning headers for datasource read paths that skip a malformed input and resume processing (non-strict ErrorPolicy, or similar best-effort fallbacks).

The first recorded detail also emits a one-time summary header so clients see a single line describing the overall situation (e.g. "malformed rows were skipped in file X") followed by per-event details. Per-event details are capped at MAX_ADDED_WARNINGS; on overflow a single "further warnings suppressed" entry is emitted so clients know more were dropped.

By default, writes go through HeaderWarning.addWarning(String, Object...) which attaches them to the current thread's response headers; if no thread context is bound (e.g. in unit tests that don't care), the call is a no-op. This is only correct when add(String) is called on a thread whose ThreadContext response headers actually feed the client response (e.g. the originating request thread). Readers whose decode loop can run on a different thread (e.g. a background reader thread wrapped by AsyncExternalSourceOperatorFactory) must instead supply a sink — typically AsyncExternalSourceBuffer::recordInformationalWarning — via SkipWarnings(String, Consumer) / of(ErrorPolicy, String, Consumer) so the message is relayed and re-emitted on the correct thread instead of being silently dropped. Instances are stateful and not thread-safe: create one per reader iterator or decoder.

Callers working against an ErrorPolicy should use of(ErrorPolicy, String) (or the sink-aware of(ErrorPolicy, String, Consumer)) to obtain either a live collector or the shared NOOP sink, so that call sites never have to null-guard subsequent add(String) invocations.

This utility lives alongside ErrorPolicy in the spi package because datasource plugins may need to emit the same shape of warnings from outside this module; it is a concrete utility rather than an SPI interface.