forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTypeObject.h
More file actions
103 lines (78 loc) · 4.33 KB
/
Copy pathDataTypeObject.h
File metadata and controls
103 lines (78 loc) · 4.33 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#pragma once
#include <Core/Field.h>
#include <DataTypes/DataTypeDynamic.h>
#include <DataTypes/IDataType.h>
namespace DB
{
class DataTypeObject final : public IDataType
{
public:
enum class SchemaFormat
{
JSON = 0,
};
static constexpr size_t MAX_TYPED_PATHS = 1000;
static constexpr size_t MAX_DYNAMIC_PATHS_LIMIT = 10000;
/// Don't change this constant, it can break backward compatibility.
static constexpr size_t DEFAULT_MAX_DYNAMIC_PATHS = 1024;
static constexpr const char * SPECIAL_SUBCOLUMN_NAME_FOR_DISTINCT_PATHS_CALCULATION = "__special_subcolumn_name_for_distinct_paths_calculation";
/// Prefix character for sub-object subcolumns, e.g. "^`some`.path.path".
static constexpr char SUB_OBJECT_SUBCOLUMN_PREFIX = '^';
/// Prefix character for combined literal+sub-object subcolumns, e.g. "@`some`.path.path".
static constexpr char COMBINED_SUBCOLUMN_PREFIX = '@';
explicit DataTypeObject(
const SchemaFormat & schema_format_,
std::unordered_map<String, DataTypePtr> typed_paths_ = {},
std::unordered_set<String> paths_to_skip_ = {},
std::vector<String> path_regexps_to_skip_ = {},
size_t max_dynamic_paths_ = DEFAULT_MAX_DYNAMIC_PATHS,
size_t max_dynamic_types_ = DataTypeDynamic::DEFAULT_MAX_DYNAMIC_TYPES);
DataTypeObject(const SchemaFormat & schema_format_, size_t max_dynamic_paths_, size_t max_dynamic_types_);
const char * getFamilyName() const override { return "Object"; }
String doGetName() const override;
TypeIndex getTypeId() const override { return TypeIndex::Object; }
MutableColumnPtr createColumn() const override;
Field getDefault() const override { return Object(); }
void insertDefaultInto(IColumn & column) const override;
bool isParametric() const override { return true; }
bool canBeInsideNullable() const override { return true; }
bool supportsSparseSerialization() const override { return false; }
bool canBeInsideSparseColumns() const override { return false; }
bool isComparable() const override { return true; }
bool isComparableForEquality() const override { return true; }
bool haveSubtypes() const override { return false; }
bool equals(const IDataType & rhs) const override;
void updateHashImpl(SipHash & hash) const override;
void forEachChild(const ChildCallback &) const override;
bool hasDynamicSubcolumnsData() const override { return true; }
bool hasDynamicStructure() const override { return true; }
std::unique_ptr<SubstreamData> getDynamicSubcolumnData(std::string_view subcolumn_name, const SubstreamData & data, size_t initial_array_level, bool throw_if_null) const override;
SerializationPtr doGetSerialization(const SerializationInfoSettings & settings) const override;
const SchemaFormat & getSchemaFormat() const { return schema_format; }
String getSchemaFormatString() const;
const std::unordered_map<String, DataTypePtr> & getTypedPaths() const { return typed_paths; }
const std::unordered_set<String> & getPathsToSkip() const { return paths_to_skip; }
const std::vector<String> & getPathRegexpsToSkip() const { return path_regexps_to_skip; }
size_t getMaxDynamicTypes() const { return max_dynamic_types; }
size_t getMaxDynamicPaths() const { return max_dynamic_paths; }
DataTypePtr getTypeOfNestedObjects() const;
DataTypePtr getDynamicType() const;
/// Shared data has type Array(Tuple(String, String)).
static const DataTypePtr & getTypeOfSharedData();
private:
/// Don't change these constants, it can break backward compatibility.
static constexpr size_t NESTED_OBJECT_MAX_DYNAMIC_PATHS_REDUCE_FACTOR = 4;
static constexpr size_t NESTED_OBJECT_MAX_DYNAMIC_TYPES_REDUCE_FACTOR = 2;
SchemaFormat schema_format;
/// Set of paths with types that were specified in type declaration.
std::unordered_map<String, DataTypePtr> typed_paths;
/// Set of paths that should be skipped during data parsing.
std::unordered_set<String> paths_to_skip;
/// List of regular expressions that should be used to skip paths during data parsing.
std::vector<String> path_regexps_to_skip;
/// Limit on the number of paths that can be stored as subcolumn.
size_t max_dynamic_paths;
/// Limit of dynamic types that should be used for Dynamic columns.
size_t max_dynamic_types;
};
}