Skip to main content

mito2/read/series_scan/
raw.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#[cfg(test)]
16mod tests;
17
18use std::collections::VecDeque;
19use std::pin::Pin;
20use std::sync::Arc;
21use std::task::{Context, Poll};
22use std::time::Instant;
23
24use common_error::ext::BoxedError;
25use common_query::error::Error as QueryError;
26use common_query::native_histogram::{
27    histogram_samples_from_arrow, is_native_histogram_value_type,
28};
29use common_query::series_frame::label_decode_spec;
30use common_recordbatch::filter;
31use datafusion::physical_plan::PhysicalExpr;
32use datatypes::arrow::array::{Array, BinaryArray, BooleanArray, Float64Array, StructArray};
33use datatypes::arrow::buffer::Buffer;
34use datatypes::arrow::compute::{self, cast, concat_batches};
35use datatypes::arrow::datatypes::ArrowNativeType;
36use datatypes::arrow::datatypes::DataType;
37use datatypes::arrow::record_batch::RecordBatch;
38use datatypes::prelude::ConcreteDataType;
39use datatypes::series::SeriesOrdering;
40use datatypes::series::frame::LabelDecodeSpec;
41use datatypes::series::raw::{RawSeriesChunk, RawTimestamps};
42use datatypes::series::samples::{Samples, SeriesFields, SeriesSchema};
43use datatypes::timestamp::timestamp_array_to_primitive;
44use futures::stream::BoxStream;
45use futures::{FutureExt, Stream, StreamExt, TryStreamExt};
46use snafu::Location;
47use snafu::{IntoError, ResultExt};
48use store_api::region_engine::{RawLabelSource, RawSeriesStream, SendableRawSeriesStream};
49
50use crate::error::{
51    ComputeArrowSnafu, DataTypeMismatchSnafu, Error, ExternalSnafu, InvalidRecordBatchSnafu,
52};
53use crate::read::scan_util::PartitionMetrics;
54use crate::read::series_scan::SeriesBatch;
55use crate::read::stream::{ScanBatch, ScanBatchStream};
56use crate::sst::parquet::flat_format::{primary_key_column_index, time_index_column_index};
57use crate::sst::parquet::format::PrimaryKeyArray;
58
59fn boxed(error: Error) -> BoxedError {
60    BoxedError::new(error)
61}
62
63fn invalid(reason: impl Into<String>) -> BoxedError {
64    boxed(
65        InvalidRecordBatchSnafu {
66            reason: reason.into(),
67        }
68        .build(),
69    )
70}
71
72fn chunk(
73    batch: &RecordBatch,
74    start: usize,
75    end: usize,
76    key: Buffer,
77    schema: &SeriesSchema,
78    fields: &[(usize, ConcreteDataType)],
79) -> Result<RawSeriesChunk, BoxedError> {
80    // The ticks are handed over in the time index's own unit; the consumer is bound to that unit.
81    let (timestamp, _) =
82        timestamp_array_to_primitive(batch.column(time_index_column_index(batch.num_columns())))
83            .ok_or_else(|| invalid("non-timestamp time index array"))?;
84    if (start..end).any(|row| !timestamp.is_valid(row)) {
85        return Err(invalid("null timestamp"));
86    }
87    let time = RawTimestamps::try_new(timestamp.values().slice(start, end - start))
88        .context(DataTypeMismatchSnafu)
89        .map_err(BoxedError::new)?;
90    let mut samples = Vec::with_capacity(fields.len());
91    for (index, data_type) in fields {
92        let array = batch.column(*index).slice(start, end - start);
93        if is_native_histogram_value_type(data_type) {
94            let hist = array
95                .as_any()
96                .downcast_ref::<StructArray>()
97                .ok_or_else(|| invalid("invalid native histogram array"))?;
98            samples.push(histogram_samples_from_arrow(hist).map_err(|error| {
99                let source = QueryError::GeneralDataFusion {
100                    error,
101                    location: Location::new(file!(), line!(), column!()),
102                };
103                BoxedError::new(
104                    ExternalSnafu {
105                        context: "native histogram conversion".to_string(),
106                    }
107                    .into_error(BoxedError::new(source)),
108                )
109            })?);
110        } else {
111            let values = cast(&array, &DataType::Float64)
112                .context(ComputeArrowSnafu)
113                .map_err(boxed)?;
114            let values = values
115                .as_any()
116                .downcast_ref::<Float64Array>()
117                .ok_or_else(|| invalid("invalid numeric field array"))?;
118            samples.push(Samples::from_float(values.clone()));
119        }
120    }
121    let fields = SeriesFields::try_from_vec(samples)
122        .context(DataTypeMismatchSnafu)
123        .map_err(BoxedError::new)?;
124    RawSeriesChunk::try_new(schema, key, None, time, fields, false)
125        .context(DataTypeMismatchSnafu)
126        .map_err(BoxedError::new)
127}
128
129struct RawStream {
130    schema: Arc<SeriesSchema>,
131    label_source: RawLabelSource,
132    /// The label decode description this stream declares, derived from `label_source` once.
133    ///
134    /// Key-encoded chunks leave `metric` as `None`, so a consumer that holds only the stream needs
135    /// the description to decode them; deriving it here makes the producer self-describing instead
136    /// of leaving the derivation to whoever packs the chunks. An invalid binding is cached as
137    /// derived and rejected by the decoder downstream, never silently turned into `None`.
138    label_decode_spec: Option<LabelDecodeSpec>,
139    ordering: SeriesOrdering,
140    inner: BoxStream<'static, Result<RawSeriesChunk, BoxedError>>,
141}
142
143impl Stream for RawStream {
144    type Item = Result<RawSeriesChunk, BoxedError>;
145    fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
146        self.inner.as_mut().poll_next(cx)
147    }
148}
149
150impl RawSeriesStream for RawStream {
151    fn schema(&self) -> &Arc<SeriesSchema> {
152        &self.schema
153    }
154    fn label_source(&self) -> &RawLabelSource {
155        &self.label_source
156    }
157    /// Returns the description derived from this stream's binding before the first poll; chunks
158    /// carry key-encoded labels, so the description is what decoding needs.
159    fn label_decode_spec(&self) -> Option<&LabelDecodeSpec> {
160        self.label_decode_spec.as_ref()
161    }
162    fn ordering(&self) -> SeriesOrdering {
163        self.ordering
164    }
165}
166
167/// Attaches shared labels after the identity-only merge establishes ordering and finality.
168/// The resolver must preserve identity and key ordering; output keys are opaque identities.
169pub(crate) fn with_series_labels(
170    stream: SendableRawSeriesStream,
171    resolve: impl Fn(Buffer) -> Result<(Buffer, datatypes::series::SeriesLabels), BoxedError>
172    + Send
173    + Sync
174    + 'static,
175) -> SendableRawSeriesStream {
176    Box::pin(RawStream {
177        schema: stream.schema().clone(),
178        label_source: stream.label_source().clone(),
179        label_decode_spec: None,
180        ordering: stream.ordering(),
181        inner: Box::pin(stream.and_then(move |mut chunk| {
182            let key = resolve(chunk.primary_key.clone());
183            async move {
184                let (key, labels) = key?;
185                chunk.primary_key = key;
186                chunk.metric = Some(labels);
187                Ok(chunk)
188            }
189        })),
190    })
191}
192
193/// Rows accumulated before the residual predicates are evaluated over one record.
194///
195/// A predicate pass is dominated by per-call setup (Arc refcount traffic, `DataType` clones and
196/// the filtered `RecordBatch` allocation) rather than by per-row comparison, and one `ScanBatch`
197/// carries the rows of a single series. Buffering up to this many rows and evaluating the
198/// predicates once per group pays that setup once per group of series instead of once per series.
199///
200/// A record that alone reaches this many rows is not concatenated with its neighbours: it heads its
201/// own group and is taken unchanged. A smaller record can still push a group past the threshold, so
202/// a group holds fewer than this many rows plus one such record's rows, and both the buffered and
203/// the concatenated arrays are alive while it is built. The value is a tuning choice, not a memory
204/// bound; it also does not bound the bytes, since a record's rows are of variable width.
205const PREDICATE_BATCH_ROWS: usize = 4096;
206
207/// Returns the primary key at `row` of `record`, or `None` when the row cannot be decoded.
208///
209/// A `None` leaves reporting the malformed row to the chunk loop; it only decides how records are
210/// grouped, never whether a record is valid.
211fn primary_key_at_row(record: &RecordBatch, row: usize) -> Option<&[u8]> {
212    let primary_key = record
213        .column(primary_key_column_index(record.num_columns()))
214        .as_any()
215        .downcast_ref::<PrimaryKeyArray>()?;
216    let values = primary_key
217        .values()
218        .as_any()
219        .downcast_ref::<BinaryArray>()?;
220    if !primary_key.keys().is_valid(row) {
221        return None;
222    }
223    let index = primary_key.keys().value(row) as usize;
224    if index >= values.len() || !values.is_valid(index) {
225        return None;
226    }
227    Some(values.value(index))
228}
229
230/// Whether `next` continues the series that ends in `previous`.
231///
232/// Such a record must head its own group: concatenation merges a series' rows into one
233/// primary-key run, which would fuse the two records' runs and change the chunk boundaries.
234/// A record whose boundary key cannot be decoded is treated as a continuation, which isolates it
235/// in its own group so the records before it keep their chunks and their error order.
236fn continues_series(previous: &RecordBatch, next: &RecordBatch) -> bool {
237    match (
238        primary_key_at_row(previous, previous.num_rows() - 1),
239        primary_key_at_row(next, 0),
240    ) {
241        (Some(previous), Some(next)) => previous == next,
242        _ => true,
243    }
244}
245
246/// A scanned record together with whether it ends the flat package it came from.
247///
248/// The divider only emits a [`SeriesBatch::Flat`] once it holds every row of the series in it, so
249/// the record that ends such a package also ends the last series in it. A plain
250/// [`ScanBatch::RecordBatch`] carries no such fact: an Arrow batch boundary is not a series
251/// boundary, so its records always leave the flag clear.
252struct IncomingRecord {
253    batch: RecordBatch,
254    ends_package: bool,
255}
256
257/// The last kept `(primary key, timestamp tick)`, carried across records so a tie split by a
258/// boundary collapses.
259type LastKeptRow = Option<(Buffer, i64)>;
260
261/// Drops a row that repeats the `(primary key, timestamp)` an earlier row of its series kept: an
262/// append-mode tie keeps its first row, the one written last, which is also the row the existing
263/// PromQL plan reads.
264fn collapse_repeated_samples(
265    record: RecordBatch,
266    last_kept: &mut LastKeptRow,
267) -> Result<RecordBatch, BoxedError> {
268    let num_columns = record.num_columns();
269    let primary_key = record
270        .column(primary_key_column_index(num_columns))
271        .as_any()
272        .downcast_ref::<PrimaryKeyArray>()
273        .ok_or_else(|| invalid("invalid primary-key array"))?;
274    let values = primary_key
275        .values()
276        .as_any()
277        .downcast_ref::<BinaryArray>()
278        .ok_or_else(|| invalid("invalid primary-key dictionary"))?;
279    let time_column = record.column(time_index_column_index(num_columns));
280    if !matches!(time_column.data_type(), DataType::Timestamp(..)) {
281        return Err(invalid("non-timestamp time index array"));
282    }
283    // The comparison stays on the stored ticks, in whatever unit the table's time index uses: a
284    // tie is an exact repeat of a tick, so converting the column to a coarser unit first would
285    // fuse the distinct samples written at the other ticks of that unit.
286    let timestamps = crate::read::timestamp_array_to_i64_slice(time_column);
287    if time_column.null_count() > 0 {
288        // A row without a timestamp takes part in no tie, and the chunk loop below reports it.
289        return Ok(record);
290    }
291    let mut keep = Vec::with_capacity(record.num_rows());
292    let mut dropped = false;
293    for (row, timestamp) in timestamps.iter().enumerate() {
294        let index = if primary_key.keys().is_valid(row) {
295            primary_key.keys().value(row).as_usize()
296        } else {
297            return Err(invalid("null primary key"));
298        };
299        if index >= values.len() || !values.is_valid(index) {
300            return Err(invalid("invalid primary-key dictionary value"));
301        }
302        let key = values.value(index);
303        let timestamp = *timestamp;
304        let repeated = last_kept.as_ref().is_some_and(|(kept, kept_timestamp)| {
305            kept.as_slice() == key && *kept_timestamp == timestamp
306        });
307        if !repeated {
308            match &mut *last_kept {
309                Some((kept, kept_timestamp)) if kept.as_slice() == key => {
310                    *kept_timestamp = timestamp;
311                }
312                // A new series never repeats the row before it, whatever its timestamp: rows arrive
313                // sorted by `(primary key, timestamp)`, so the single slot suffices.
314                slot => {
315                    *slot = Some((Buffer::from(key), timestamp));
316                }
317            }
318        }
319        dropped |= repeated;
320        keep.push(!repeated);
321    }
322    if !dropped {
323        return Ok(record);
324    }
325    compute::filter_record_batch(&record, &BooleanArray::from(keep))
326        .context(ComputeArrowSnafu)
327        .map_err(boxed)
328}
329
330#[allow(clippy::too_many_arguments)]
331pub(crate) fn make_stream(
332    inner: ScanBatchStream,
333    schema: Arc<SeriesSchema>,
334    label_source: RawLabelSource,
335    fields: Vec<(usize, ConcreteDataType)>,
336    metrics: PartitionMetrics,
337    predicates: Vec<Arc<dyn PhysicalExpr>>,
338    ordering: SeriesOrdering,
339    append_mode: bool,
340) -> SendableRawSeriesStream {
341    let output_schema = schema.clone();
342    let label_decode_spec = label_decode_spec(&label_source);
343    let stream = async_stream::stream! {
344        let mut input = inner;
345        let mut pending: Option<RawSeriesChunk> = None;
346        let mut last_package_key: Option<Buffer> = None;
347        // Records waiting for one predicate pass, and the number of rows they hold.
348        let mut buffered: Vec<RecordBatch> = Vec::new();
349        let mut buffered_rows = 0;
350        // Without a predicate there is no per-call cost to amortize, so the threshold drops to one
351        // record and buffering only reproduces the per-record stream this replaced.
352        let coalesce_rows = if predicates.is_empty() { 1 } else { PREDICATE_BATCH_ROWS };
353        // Records of the last scanned batch that are not buffered yet, and a record held back
354        // because it continues the series the buffer ends with.
355        let mut incoming: VecDeque<IncomingRecord> = VecDeque::new();
356        let mut held: Option<IncomingRecord> = None;
357        let mut exhausted = false;
358        let mut last_kept: LastKeptRow = None;
359        // An upstream error is reported only after the records buffered before it are processed,
360        // so the chunks that precede it are still yielded first.
361        let mut upstream_error: Option<Error> = None;
362        loop {
363            // The last complete package tail admitted to this predicate group, if any.
364            let mut group_last_package_key: Option<Buffer> = None;
365            // Fill: pull records until one predicate pass is amortized by the group.
366            while !exhausted && upstream_error.is_none() && buffered_rows < coalesce_rows {
367                let record = match held.take() {
368                    Some(record) => record,
369                    None => match incoming.pop_front() {
370                        Some(record) => record,
371                        None => {
372                            let next = if group_last_package_key.is_none() {
373                                input.next().await
374                            } else {
375                                match input.next().now_or_never() {
376                                    Some(next) => next,
377                                    None => break,
378                                }
379                            };
380                            match next {
381                            Some(Ok(ScanBatch::Series(SeriesBatch::Flat(flat)))) => {
382                                // A package holds every row of the series in it, so the record that
383                                // ends it closes the last of them. Empty records carry no rows and no
384                                // series, which puts the flag on the last record that has rows; a
385                                // package without any ends no series and closes nothing.
386                                let ends_package = if ordering == SeriesOrdering::KeyThenTime {
387                                    flat.batches
388                                        .iter()
389                                        .rposition(|batch| batch.num_rows() > 0)
390                                } else {
391                                    None
392                                };
393                                for (index, batch) in flat.batches.into_iter().enumerate() {
394                                    if batch.num_rows() == 0 {
395                                        continue;
396                                    }
397                                    incoming.push_back(IncomingRecord {
398                                        batch,
399                                        ends_package: Some(index) == ends_package,
400                                    });
401                                }
402                                continue;
403                            }
404                            Some(Ok(ScanBatch::RecordBatch(batch))) => IncomingRecord {
405                                batch,
406                                ends_package: false,
407                            },
408                            Some(Err(error)) => { upstream_error = Some(error); break; }
409                            None => { exhausted = true; break; }
410                            }
411                        },
412                    },
413                };
414                if record.batch.num_rows() == 0 { continue; }
415                // A record that reaches the threshold alone is a full batch: concatenating it with
416                // what is buffered would copy it for no saving, since its predicate pass is paid
417                // once either way. Let it head its own group, where the single-record path takes it
418                // unchanged. A record that continues the buffered series is held back for the
419                // reason `continues_series` documents.
420                if let Some(previous) = buffered.last()
421                    && (record.batch.num_rows() >= coalesce_rows
422                        || continues_series(previous, &record.batch))
423                {
424                    held = Some(record);
425                    break;
426                }
427                if ordering == SeriesOrdering::KeyThenTime
428                    && let Some(previous) = last_package_key.as_ref()
429                    && let Some(first) = primary_key_at_row(&record.batch, 0)
430                    && first <= previous.as_slice()
431                {
432                    upstream_error = Some(InvalidRecordBatchSnafu {
433                        reason: "raw series primary keys are not strictly increasing".to_string(),
434                    }.build());
435                    break;
436                }
437                buffered_rows += record.batch.num_rows();
438                if record.ends_package
439                    && let Some(key) = record.batch.num_rows().checked_sub(1)
440                        .and_then(|row| primary_key_at_row(&record.batch, row))
441                {
442                    let key = Buffer::from(key);
443                    last_package_key = Some(key.clone());
444                    group_last_package_key = Some(key);
445                }
446                buffered.push(record.batch);
447            }
448            if buffered.is_empty() { break; }
449            // Take the rows out of the buffer before processing them, so an early return cannot
450            // replay them. A pending upstream error is reported only after these records, so the
451            // chunks they hold are still yielded first; a coalesced group whose predicate fails
452            // also withholds its `pending` chunk, and the two paths agree on that.
453            let mut group: Vec<RecordBatch> = std::mem::take(&mut buffered);
454            buffered_rows = 0;
455            // A group of one record needs no concatenation, and copying it would only add work to
456            // the case coalescing cannot help with.
457            let mut record = if group.len() == 1 {
458                group.pop().expect("group is non-empty")
459            } else {
460                match concat_batches(&group[0].schema(), &group) {
461                    Ok(record) => record,
462                    Err(error) => { yield Err(boxed(ComputeArrowSnafu.into_error(error))); return; }
463                }
464            };
465            // The concatenated arrays own their buffers, so the source records can go now instead of
466            // staying alive across this round's filtering and per-chunk yields.
467            drop(group);
468            // Completion metadata was captured before predicates, so a filtered tail still closes its package.
469            for predicate in &predicates {
470                record = match filter::batch_filter(&record, predicate) {
471                    Ok(record) => record,
472                    Err(error) => {
473                        let source = QueryError::GeneralDataFusion {
474                            error,
475                            location: Location::new(file!(), line!(), column!()),
476                        };
477                        yield Err(BoxedError::new(ExternalSnafu {
478                            context: "raw predicate evaluation".to_string(),
479                        }.into_error(BoxedError::new(source))));
480                        return;
481                    }
482                };
483                if record.num_rows() == 0 {
484                    break;
485                }
486            }
487            // After the predicates, so the row kept is the first row of the tie that survives them.
488            if append_mode {
489                record = match collapse_repeated_samples(record, &mut last_kept) {
490                    Ok(record) => record,
491                    Err(error) => { yield Err(error); return; }
492                };
493            }
494            // An emptied group contributes no chunk, and the chunk loop below yields nothing for it.
495            if record.num_rows() > 0 {
496                let pk_column = record.column(primary_key_column_index(record.num_columns()));
497                let primary_key = match pk_column.as_any().downcast_ref::<PrimaryKeyArray>() {
498                    Some(primary_key) => primary_key,
499                    None => { yield Err(invalid("invalid primary-key array")); return; }
500                };
501                let values = match primary_key.values().as_any().downcast_ref::<BinaryArray>() {
502                    Some(values) => values,
503                    None => { yield Err(invalid("invalid primary-key dictionary")); return; }
504                };
505                let mut start = 0;
506                while start < record.num_rows() {
507                    let index = if primary_key.keys().is_valid(start) {
508                        primary_key.keys().value(start).as_usize()
509                    } else {
510                        yield Err(invalid("null primary key")); return;
511                    };
512                    if index >= values.len() || !values.is_valid(index) {
513                        yield Err(invalid("invalid primary-key dictionary value")); return;
514                    }
515                    let mut end = start + 1;
516                    while end < record.num_rows() {
517                        let next_index = if primary_key.keys().is_valid(end) {
518                            primary_key.keys().value(end).as_usize()
519                        } else {
520                            yield Err(invalid("null primary key")); return;
521                        };
522                        if next_index >= values.len() || !values.is_valid(next_index) {
523                            yield Err(invalid("invalid primary-key dictionary value")); return;
524                        }
525                        if super::primary_key_at(primary_key, values, end)
526                            == super::primary_key_at(primary_key, values, start)
527                        {
528                            end += 1;
529                        } else {
530                            break;
531                        }
532                    }
533                    let offsets = values.value_offsets();
534                    let value_start = offsets[index].as_usize();
535                    let value_len = offsets[index + 1].as_usize() - value_start;
536                    let key = values.values().slice_with_length(value_start, value_len);
537                    let begun = Instant::now();
538                    let current = match chunk(&record, start, end, key, &output_schema, &fields) {
539                        Ok(chunk) => chunk, Err(error) => { yield Err(error); return; }
540                    };
541                    metrics.inc_convert_batch_cost(begun.elapsed());
542                    if let Some(old) = pending.as_ref()
543                        && ordering == SeriesOrdering::KeyThenTime
544                        && old.primary_key.as_slice() != current.primary_key.as_slice()
545                        && current.primary_key.as_slice() <= old.primary_key.as_slice()
546                    {
547                        yield Err(invalid("raw series primary keys are not strictly increasing")); return;
548                    }
549                    if let Some(old) = pending.as_ref()
550                        && old.primary_key.as_slice() == current.primary_key.as_slice()
551                        && current.time.timestamp(0).zip(old.time.timestamp(old.time.len() - 1))
552                            .is_some_and(|(next, previous)| next <= previous)
553                    {
554                        yield Err(invalid("raw timestamps are not strictly increasing")); return;
555                    }
556                    // Legacy flat producers declare `KeyThenTime`; the ordered-key comparison
557                    // rejects a key that reopens after a package has completed it.
558                    if let Some(mut old) = pending.take() {
559                        if old.primary_key.as_slice() != current.primary_key.as_slice() {
560                            old.is_last = true;
561                        }
562                        yield Ok(old);
563                    }
564                    pending = Some(current);
565                    start = end;
566                }
567            }
568            if let Some(package_last_key) = group_last_package_key
569                && pending.as_ref().is_some_and(|last| last.primary_key.as_slice() <= package_last_key.as_slice())
570                && let Some(mut last) = pending.take()
571            {
572                last.is_last = true;
573                yield Ok(last);
574            }
575        }
576        if let Some(error) = upstream_error { yield Err(BoxedError::new(error)); return; }
577        if let Some(mut last) = pending { last.is_last = true; yield Ok(last); }
578    };
579    Box::pin(RawStream {
580        schema,
581        label_source,
582        label_decode_spec,
583        ordering,
584        inner: Box::pin(stream),
585    })
586}
587
588/// Wraps deferred preparation while exposing the scan contract before polling.
589pub(crate) fn from_stream(
590    schema: Arc<SeriesSchema>,
591    label_source: RawLabelSource,
592    ordering: SeriesOrdering,
593    explicit_labels: bool,
594    inner: BoxStream<'static, Result<RawSeriesChunk, BoxedError>>,
595) -> SendableRawSeriesStream {
596    Box::pin(RawStream {
597        schema,
598        label_decode_spec: if explicit_labels {
599            None
600        } else {
601            label_decode_spec(&label_source)
602        },
603        label_source,
604        ordering,
605        inner,
606    })
607}