Repository navigation
Expand file tree
/
Copy pathJSONExtractTree.h
More file actions
58 lines (50 loc) · 2.99 KB
/
Copy pathJSONExtractTree.h
File metadata and controls
58 lines (50 loc) · 2.99 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
#pragma once
#include <DataTypes/IDataType.h>
#include <Columns/IColumn_fwd.h>
namespace DB
{
struct FormatSettings;
struct JSONExtractInsertSettings
{
/// If true, when complex type like Array/Map has both valid and invalid elements,
/// the default value will be inserted on invalid elements.
/// For example, if we have [1, "hello", 2] and type Array(UInt32),
/// we will insert [1, 0, 2] in the column. Used in all JSONExtract functions.
bool insert_default_on_invalid_elements_in_complex_types = false;
/// If false, JSON value will be inserted into column only if type of the value is
/// the same as column type (no conversions like Integer -> String, Integer -> Float, etc).
bool allow_type_conversion = true;
/// If true, during insert into Dynamic column we first try to insert value into existing variants
/// and only if failed we try to infer the new variant type.
bool try_existing_variants_in_dynamic_first = true;
/// If true, during constructing the JSON path dots in keys will be escaped.
bool escape_dots_in_json_keys = false;
/// If true, skip typed paths where type coercion fails instead of throwing error.
/// Skipped fields are treated as missing and use default/null values.
/// Only applies to JSON type columns with typed paths, not general JSON parsing.
bool skip_invalid_typed_paths = false;
/// Use partial match instead of full to skip paths using regular expressions specified
/// in JSON data type using SKIP REGEXP.
bool use_partial_match_to_skip_paths_by_regexp = true;
/// If true, fractional JSON DOUBLE values (e.g. `3.14`) and STRING values that parse
/// as non-integral floats (e.g. `"3.14"`) are not silently truncated to integer types.
/// Used inside `VariantNode` so that `Variant(IntT, FloatT)` picks the float member
/// for fractional values instead of silently dropping the fractional part.
bool no_int_truncation_from_double = false;
};
template <typename JSONParser>
class JSONExtractTreeNode
{
public:
JSONExtractTreeNode() = default;
virtual ~JSONExtractTreeNode() = default;
virtual bool insertResultToColumn(IColumn &, const typename JSONParser::Element &, const JSONExtractInsertSettings & insert_setting, const FormatSettings & format_settings, String & error) const = 0;
};
/// Build a tree for insertion JSON element into a column with provided data type.
template <typename JSONParser>
std::unique_ptr<JSONExtractTreeNode<JSONParser>> buildJSONExtractTree(const DataTypePtr & type, const char * source_for_exception_message);
template <typename JSONParser>
void jsonElementToString(const typename JSONParser::Element & element, WriteBuffer & buf, const FormatSettings & format_settings);
template <typename JSONParser, typename NumberType>
bool tryGetNumericValueFromJSONElement(NumberType & value, const typename JSONParser::Element & element, bool convert_bool_to_number, bool allow_type_conversion, bool no_int_truncation_from_double, bool precise_float_parsing, String & error);
}