promql/native/batch.rs
1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! The batches native nodes hand to each other.
16//!
17//! These are ordinary Rust values passed by call, not DataFusion streams and not encoded messages:
18//! the Arrow arrays, buffers and shared schemas inside them are reused as they are.
19//!
20//! Two rules make a chunk self-describing:
21//!
22//! - A grid position is absolute on the chunk's grid. Batch-local row numbers never stand in for
23//! one, and an inner grid is never addressed with an outer grid's index.
24//! - A series closes exactly once, on the chunk that carries [`EvaluatedChunk::is_last`]. A closed
25//! prefix still has to be followed by a final chunk even when that chunk holds no values, so a
26//! consumer can tell "nothing more here" from "no more input". This is per input series, not per
27//! label set: a node that rewrites labels can hand two input series over under one label set, and
28//! each of them still closes on its own chunk, so a label set may be closed more than once. A
29//! series that produced values closes it, and a later input series with no result at all closes it
30//! again on the chunk that ends it; a node that can merge two inputs into one series must not read
31//! the second close as a defect.
32
33//!
34//! The chunk type itself is [`crate::evaluated::EvaluatedChunk`]: one chunk protocol serves both the
35//! evaluator that produces chunks and the native nodes that consume them. Defining a second one
36//! here would let the two drift apart, and a chunk produced by the evaluator could not be handed to
37//! a node without translation.
38
39pub use crate::evaluated::EvaluatedChunk;