table/
stats.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 datatypes::value::Value;
16
17/// Statistics for a relation.
18///
19/// Fields are optional and can be inexact because the sources
20/// sometimes provide approximate estimates for performance reasons
21/// and the transformations output are not always predictable.
22#[derive(Debug, Clone, Default, PartialEq, Eq)]
23pub struct TableStatistics {
24    /// The number of table rows
25    pub num_rows: Option<usize>,
26    /// total bytes of the table rows
27    pub total_byte_size: Option<usize>,
28    /// Statistics on a column level
29    pub column_statistics: Option<Vec<ColumnStatistics>>,
30    /// If true, any field that is `Some(..)` is the actual value in the data provided by the operator (it is not
31    /// an estimation). Any or all other fields might still be None, in which case no information is known.
32    /// if false, any field that is `Some(..)` may contain an inexact estimate and may not be the actual value.
33    pub is_exact: bool,
34}
35
36/// Statistics for a column within a relation
37#[derive(Clone, Debug, Default, PartialEq, Eq)]
38pub struct ColumnStatistics {
39    /// Number of null values on column
40    pub null_count: Option<usize>,
41    /// Maximum value of column
42    pub max_value: Option<Value>,
43    /// Minimum value of column
44    pub min_value: Option<Value>,
45    /// Number of distinct values
46    pub distinct_count: Option<usize>,
47    // TODO(discord9): histogram of values
48}