store_api/storage/requests.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
15use common_recordbatch::OrderOption;
16use datafusion_expr::expr::Expr;
17use strum::Display;
18
19use crate::storage::SequenceNumber;
20
21/// A hint on how to select rows from a time-series.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
23pub enum TimeSeriesRowSelector {
24 /// Only keep the last row of each time-series.
25 LastRow,
26}
27
28/// A hint on how to distribute time-series data on the scan output.
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
30pub enum TimeSeriesDistribution {
31 /// Data are distributed by time window first. The scanner will
32 /// return all data within one time window before moving to the next one.
33 TimeWindowed,
34 /// Data are organized by time-series first. The scanner will return
35 /// all data for one time-series before moving to the next one.
36 PerSeries,
37}
38
39#[derive(Default, Clone, Debug, PartialEq, Eq)]
40pub struct ScanRequest {
41 /// Indices of columns to read, `None` to read all columns. This indices is
42 /// based on table schema.
43 pub projection: Option<Vec<usize>>,
44 /// Filters pushed down
45 pub filters: Vec<Expr>,
46 /// Expected output ordering. This is only a hint and isn't guaranteed.
47 pub output_ordering: Option<Vec<OrderOption>>,
48 /// limit can be used to reduce the amount scanned
49 /// from the datasource as a performance optimization.
50 /// If set, it contains the amount of rows needed by the caller,
51 /// The data source should return *at least* this number of rows if available.
52 pub limit: Option<usize>,
53 /// Optional hint to select rows from time-series.
54 pub series_row_selector: Option<TimeSeriesRowSelector>,
55 /// Optional constraint on the sequence number of the rows to read.
56 /// If set, only rows with a sequence number lesser or equal to this value
57 /// will be returned.
58 pub sequence: Option<SequenceNumber>,
59 /// Optional hint for the distribution of time-series data.
60 pub distribution: Option<TimeSeriesDistribution>,
61}