forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_type_jsonb.cpp
More file actions
81 lines (68 loc) · 3.07 KB
/
Copy pathdata_type_jsonb.cpp
File metadata and controls
81 lines (68 loc) · 3.07 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
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "core/data_type/data_type_jsonb.h"
#include <typeinfo>
#include <utility>
#include "common/cast_set.h"
#include "core/assert_cast.h"
#include "core/column/column_const.h"
#include "core/string_buffer.hpp"
#include "core/string_ref.h"
#include "core/types.h"
#include "core/value/jsonb_value.h"
#include "util/jsonb_utils.h"
namespace doris {
class IColumn;
} // namespace doris
namespace doris {
Field DataTypeJsonb::get_field(const TExprNode& node) const {
DCHECK_EQ(node.node_type, TExprNodeType::JSON_LITERAL);
DCHECK(node.__isset.json_literal);
JsonBinaryValue jsonb_value;
THROW_IF_ERROR(jsonb_value.from_json_string(node.json_literal.value));
return Field::create_field<TYPE_JSONB>(
JsonbField(jsonb_value.value(), cast_set<Int32>(jsonb_value.size())));
}
MutableColumnPtr DataTypeJsonb::create_column() const {
return ColumnString::create();
}
Status DataTypeJsonb::check_column(const IColumn& column) const {
return data_type_string.check_column(column);
}
bool DataTypeJsonb::equals(const IDataType& rhs) const {
return typeid(rhs) == typeid(*this);
}
int64_t DataTypeJsonb::get_uncompressed_serialized_bytes(const IColumn& column,
int be_exec_version) const {
return data_type_string.get_uncompressed_serialized_bytes(column, be_exec_version);
}
char* DataTypeJsonb::serialize(const IColumn& column, char* buf, int be_exec_version) const {
return data_type_string.serialize(column, buf, be_exec_version);
}
const char* DataTypeJsonb::deserialize(const char* buf, MutableColumnPtr* column,
int be_exec_version) const {
return data_type_string.deserialize(buf, column, be_exec_version);
}
FieldWithDataType DataTypeJsonb::get_field_with_data_type(const IColumn& column,
size_t row_num) const {
const auto& column_data = assert_cast<const ColumnString&, TypeCheckOnRelease::DISABLE>(column);
Field field = Field::create_field<TYPE_JSONB>(JsonbField(
column_data.get_data_at(row_num).data, column_data.get_data_at(row_num).size));
return FieldWithDataType {.field = std::move(field),
.base_scalar_type_id = get_primitive_type()};
}
} // namespace doris