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
95 lines (78 loc) · 3.44 KB
/
Copy pathdata_type_jsonb.cpp
File metadata and controls
95 lines (78 loc) · 3.44 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
// 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 "data_type_jsonb.h"
#include <typeinfo>
#include <utility>
#include "common/cast_set.h"
#include "util/jsonb_utils.h"
#include "vec/columns/column_const.h"
#include "vec/common/assert_cast.h"
#include "vec/common/string_buffer.hpp"
#include "vec/common/string_ref.h"
#include "vec/core/types.h"
#include "vec/io/reader_buffer.h"
namespace doris {
namespace vectorized {
class IColumn;
} // namespace vectorized
} // namespace doris
namespace doris::vectorized {
#include "common/compile_check_begin.h"
std::string DataTypeJsonb::to_string(const IColumn& column, size_t row_num) const {
auto result = check_column_const_set_readability(column, row_num);
ColumnPtr ptr = result.first;
row_num = result.second;
const StringRef& s = assert_cast<const ColumnString&>(*ptr).get_data_at(row_num);
return s.size > 0 ? JsonbToJson::jsonb_to_json_string(s.data, s.size) : "";
}
void DataTypeJsonb::to_string(const class doris::vectorized::IColumn& column, size_t row_num,
class doris::vectorized::BufferWritable& ostr) const {
auto result = check_column_const_set_readability(column, row_num);
ColumnPtr ptr = result.first;
row_num = result.second;
const StringRef& s = assert_cast<const ColumnString&>(*ptr).get_data_at(row_num);
if (s.size > 0) {
std::string str = JsonbToJson::jsonb_to_json_string(s.data, s.size);
ostr.write(str.c_str(), str.size());
}
}
Status DataTypeJsonb::from_string(ReadBuffer& rb, IColumn* column) const {
JsonBinaryValue value;
// Throw exception if rb.count is large than INT32_MAX
RETURN_IF_ERROR(value.from_json_string(rb.position(), cast_set<Int32>(rb.count())));
auto* column_string = static_cast<ColumnString*>(column);
column_string->insert_data(value.value(), value.size());
return Status::OK();
}
MutableColumnPtr DataTypeJsonb::create_column() const {
return ColumnString::create();
}
bool DataTypeJsonb::equals(const IDataType& rhs) const {
return typeid(rhs) == typeid(*this);
}
int64_t DataTypeJsonb::get_uncompressed_serialized_bytes(const IColumn& column,
int data_version) const {
return data_type_string.get_uncompressed_serialized_bytes(column, data_version);
}
char* DataTypeJsonb::serialize(const IColumn& column, char* buf, int data_version) const {
return data_type_string.serialize(column, buf, data_version);
}
const char* DataTypeJsonb::deserialize(const char* buf, MutableColumnPtr* column,
int data_version) const {
return data_type_string.deserialize(buf, column, data_version);
}
} // namespace doris::vectorized