[feature](jsonb type)refactor JSONB type using column and add testcase (#13778)
1. Refactor JSONB type using ColumnString instead making a copy. 2. Add regression testcase for JSONB load and functions.
This commit is contained in:
@ -21,7 +21,6 @@
|
||||
#include "util/string_parser.hpp"
|
||||
#include "util/string_util.h"
|
||||
#include "vec/columns/column.h"
|
||||
#include "vec/columns/column_jsonb.h"
|
||||
#include "vec/columns/column_nullable.h"
|
||||
#include "vec/columns/column_string.h"
|
||||
#include "vec/columns/column_vector.h"
|
||||
@ -188,7 +187,7 @@ public:
|
||||
col_from.get_name());
|
||||
}
|
||||
|
||||
auto col_to = ColumnJsonb::create();
|
||||
auto col_to = ColumnString::create();
|
||||
|
||||
//IColumn & col_to = *res;
|
||||
size_t size = col_from.size();
|
||||
@ -323,7 +322,7 @@ public:
|
||||
|
||||
auto res = Impl::ColumnType::create();
|
||||
|
||||
auto jsonb_data_column = assert_cast<const ColumnJsonb*>(argument_columns[0].get());
|
||||
auto jsonb_data_column = assert_cast<const ColumnString*>(argument_columns[0].get());
|
||||
auto jsonb_path_column = assert_cast<const ColumnString*>(argument_columns[1].get());
|
||||
|
||||
auto& ldata = jsonb_data_column->get_chars();
|
||||
@ -370,7 +369,7 @@ struct JsonbExtractStringImpl {
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < input_rows_count; ++i) {
|
||||
int l_size = loffsets[i] - loffsets[i - 1] - 1;
|
||||
int l_size = loffsets[i] - loffsets[i - 1];
|
||||
const auto l_raw = reinterpret_cast<const char*>(&ldata[loffsets[i - 1]]);
|
||||
|
||||
int r_size = roffsets[i] - roffsets[i - 1];
|
||||
@ -405,13 +404,9 @@ struct JsonbExtractStringImpl {
|
||||
if constexpr (std::is_same_v<DataTypeJsonb, ReturnType>) {
|
||||
writer->reset();
|
||||
writer->writeValue(value);
|
||||
// StringOP::push_value_string(
|
||||
// std::string_view(writer->getOutput()->getBuffer(), writer->getOutput()->getSize()),
|
||||
// i, res_data, res_offsets);
|
||||
res_data.insert(writer->getOutput()->getBuffer(),
|
||||
writer->getOutput()->getBuffer() + writer->getOutput()->getSize());
|
||||
res_data.push_back('\0');
|
||||
res_offsets[i] = res_data.size();
|
||||
StringOP::push_value_string(std::string_view(writer->getOutput()->getBuffer(),
|
||||
writer->getOutput()->getSize()),
|
||||
i, res_data, res_offsets);
|
||||
} else {
|
||||
if (LIKELY(value->isString())) {
|
||||
auto str_value = (JsonbStringVal*)value;
|
||||
@ -449,7 +444,7 @@ struct JsonbExtractImpl {
|
||||
}
|
||||
|
||||
const char* l_raw_str = reinterpret_cast<const char*>(&ldata[loffsets[i - 1]]);
|
||||
int l_str_size = loffsets[i] - loffsets[i - 1] - 1;
|
||||
int l_str_size = loffsets[i] - loffsets[i - 1];
|
||||
|
||||
const char* r_raw_str = reinterpret_cast<const char*>(&rdata[roffsets[i - 1]]);
|
||||
int r_str_size = roffsets[i] - roffsets[i - 1];
|
||||
@ -470,7 +465,9 @@ struct JsonbExtractImpl {
|
||||
// value is NOT necessary to be deleted since JsonbValue will not allocate memory
|
||||
JsonbValue* value = doc->getValue()->findPath(r_raw_str, r_str_size, ".", nullptr);
|
||||
if (UNLIKELY(!value)) {
|
||||
null_map[i] = 1;
|
||||
if constexpr (!only_check_exists) {
|
||||
null_map[i] = 1;
|
||||
}
|
||||
res[i] = 0;
|
||||
continue;
|
||||
}
|
||||
@ -580,7 +577,7 @@ struct JsonbTypeString {
|
||||
struct JsonbTypeJson {
|
||||
using T = std::string;
|
||||
using ReturnType = DataTypeJsonb;
|
||||
using ColumnType = ColumnJsonb;
|
||||
using ColumnType = ColumnString;
|
||||
static const bool only_check_exists = false;
|
||||
static const bool only_get_type = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user