-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
string_stats.hpp
76 lines (63 loc) · 3.3 KB
/
string_stats.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//===----------------------------------------------------------------------===//
// DuckDB
//
// duckdb/storage/statistics/string_stats.hpp
//
//
//===----------------------------------------------------------------------===//
#pragma once
#include "duckdb/common/common.hpp"
#include "duckdb/common/exception.hpp"
#include "duckdb/common/types/hugeint.hpp"
#include "duckdb/common/enums/filter_propagate_result.hpp"
#include "duckdb/common/enums/expression_type.hpp"
#include "duckdb/common/operator/comparison_operators.hpp"
namespace duckdb {
class BaseStatistics;
struct SelectionVector;
class Vector;
struct StringStatsData {
constexpr static uint32_t MAX_STRING_MINMAX_SIZE = 8;
//! The minimum value of the segment, potentially truncated
data_t min[MAX_STRING_MINMAX_SIZE];
//! The maximum value of the segment, potentially truncated
data_t max[MAX_STRING_MINMAX_SIZE];
//! Whether or not the column can contain unicode characters
bool has_unicode;
//! Whether or not the maximum string length is known
bool has_max_string_length;
//! The maximum string length in bytes
uint32_t max_string_length;
};
struct StringStats {
//! Unknown statistics - i.e. "has_unicode" is true, "max_string_length" is unknown, "min" is \0, max is \xFF
DUCKDB_API static BaseStatistics CreateUnknown(LogicalType type);
//! Empty statistics - i.e. "has_unicode" is false, "max_string_length" is 0, "min" is \xFF, max is \x00
DUCKDB_API static BaseStatistics CreateEmpty(LogicalType type);
//! Whether or not the statistics have a maximum string length defined
DUCKDB_API static bool HasMaxStringLength(const BaseStatistics &stats);
//! Returns the maximum string length, or throws an exception if !HasMaxStringLength()
DUCKDB_API static uint32_t MaxStringLength(const BaseStatistics &stats);
//! Whether or not the strings can contain unicode
DUCKDB_API static bool CanContainUnicode(const BaseStatistics &stats);
//! Returns the min value (up to a length of StringStatsData::MAX_STRING_MINMAX_SIZE)
DUCKDB_API static string Min(const BaseStatistics &stats);
//! Returns the max value (up to a length of StringStatsData::MAX_STRING_MINMAX_SIZE)
DUCKDB_API static string Max(const BaseStatistics &stats);
//! Resets the max string length so HasMaxStringLength() is false
DUCKDB_API static void ResetMaxStringLength(BaseStatistics &stats);
//! FIXME: make this part of Set on statistics
DUCKDB_API static void SetContainsUnicode(BaseStatistics &stats);
DUCKDB_API static void Serialize(const BaseStatistics &stats, Serializer &serializer);
DUCKDB_API static void Deserialize(Deserializer &deserializer, BaseStatistics &base);
DUCKDB_API static string ToString(const BaseStatistics &stats);
DUCKDB_API static FilterPropagateResult CheckZonemap(const BaseStatistics &stats, ExpressionType comparison_type,
const string &value);
DUCKDB_API static void Update(BaseStatistics &stats, const string_t &value);
DUCKDB_API static void Merge(BaseStatistics &stats, const BaseStatistics &other);
DUCKDB_API static void Verify(const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count);
private:
static StringStatsData &GetDataUnsafe(BaseStatistics &stats);
static const StringStatsData &GetDataUnsafe(const BaseStatistics &stats);
};
} // namespace duckdb