Skip to content

Commit

Permalink
[fix](compile) Enable compile checking for function_json (apache#42329)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel39 authored Oct 24, 2024
1 parent afd9c09 commit 977404e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions be/src/util/string_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class StringParser {
// In the case of overflow, the max/min value for the data type will be returned.
// Assumes s represents a decimal number.
template <typename T>
static inline T string_to_int(const char* __restrict s, int len, ParseResult* result) {
static inline T string_to_int(const char* __restrict s, size_t len, ParseResult* result) {
T ans = string_to_int_internal<T>(s, len, result);
if (LIKELY(*result == PARSE_SUCCESS)) {
return ans;
Expand Down Expand Up @@ -140,7 +140,7 @@ class StringParser {
}

template <typename T>
static inline T string_to_float(const char* __restrict s, int len, ParseResult* result) {
static inline T string_to_float(const char* __restrict s, size_t len, ParseResult* result) {
return string_to_float_internal<T>(s, len, result);
}

Expand Down
35 changes: 21 additions & 14 deletions be/src/vec/functions/function_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#else
#include "util/jsonb_parser.h"
#endif
#include "common/cast_set.h"
#include "util/string_parser.hpp"
#include "util/string_util.h"
#include "vec/aggregate_functions/aggregate_function.h"
Expand Down Expand Up @@ -76,6 +77,7 @@ class FunctionContext;
} // namespace doris

namespace doris::vectorized {
#include "common/compile_check_begin.h"
static const re2::RE2 JSON_PATTERN("^([^\\\"\\[\\]]*)(?:\\[([0-9]+|\\*)\\])?");

template <typename T, typename U>
Expand Down Expand Up @@ -257,7 +259,9 @@ rapidjson::Value* get_json_object(std::string_view json_string, std::string_view

if (UNLIKELY((*parsed_paths).size() == 1)) {
if (fntype == JSON_FUN_STRING) {
document->SetString(json_string.data(), json_string.size(), document->GetAllocator());
document->SetString(json_string.data(),
cast_set<rapidjson::SizeType>(json_string.size()),
document->GetAllocator());
} else {
return document;
}
Expand Down Expand Up @@ -375,7 +379,7 @@ struct GetJsonNumberType {
} else if (root->IsInt()) {
res = root->GetInt();
} else if (root->IsInt64()) {
res = root->GetInt64();
res = static_cast<double>(root->GetInt64());
} else if (root->IsDouble()) {
res = root->GetDouble();
} else {
Expand Down Expand Up @@ -547,7 +551,7 @@ struct JsonParser {
//string
static void update_value(StringParser::ParseResult& result, rapidjson::Value& value,
StringRef data, rapidjson::Document::AllocatorType& allocator) {
value.SetString(data.data, data.size, allocator);
value.SetString(data.data, cast_set<rapidjson::SizeType>(data.size), allocator);
}
};

Expand Down Expand Up @@ -595,7 +599,7 @@ struct JsonParser<'4'> {
static void update_value(StringParser::ParseResult& result, rapidjson::Value& value,
StringRef data, rapidjson::Document::AllocatorType& allocator) {
// remove double quotes, "xxx" -> xxx
value.SetString(data.data + 1, data.size - 2, allocator);
value.SetString(data.data + 1, cast_set<rapidjson::SizeType>(data.size - 2), allocator);
}
};

Expand Down Expand Up @@ -779,8 +783,8 @@ class FunctionJsonAlwaysNotNullable : public IFunction {
}
}

static Status check_keys_all_not_null(const std::vector<const ColumnUInt8*>& nullmaps, int size,
size_t args) {
static Status check_keys_all_not_null(const std::vector<const ColumnUInt8*>& nullmaps,
size_t size, size_t args) {
for (int i = 0; i < args; i += 2) {
const auto* null_map = nullmaps[i];
if (null_map) {
Expand Down Expand Up @@ -818,7 +822,7 @@ struct FunctionJsonQuoteImpl {

for (int i = 0; i < input_rows_count; i++) {
StringRef data = data_columns[0]->get_data_at(i);
value.SetString(data.data, data.size, allocator);
value.SetString(data.data, cast_set<rapidjson::SizeType>(data.size), allocator);

buf.Clear();
rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
Expand All @@ -832,8 +836,9 @@ struct FunctionJsonExtractImpl {
static constexpr auto name = "json_extract";

static rapidjson::Value parse_json(const ColumnString* json_col, const ColumnString* path_col,
rapidjson::Document::AllocatorType& allocator, const int row,
const int col, std::vector<bool>& column_is_consts) {
rapidjson::Document::AllocatorType& allocator,
const size_t row, const size_t col,
std::vector<bool>& column_is_consts) {
rapidjson::Value value;
rapidjson::Document document;

Expand All @@ -850,7 +855,7 @@ struct FunctionJsonExtractImpl {

static rapidjson::Value* get_document(const ColumnString* path_col,
rapidjson::Document* document,
std::vector<JsonPath>& parsed_paths, const int row,
std::vector<JsonPath>& parsed_paths, const size_t row,
bool is_const_column) {
const auto path = path_col->get_data_at(index_check_const(row, is_const_column));
std::string_view path_string(path.data, path.size);
Expand Down Expand Up @@ -886,7 +891,7 @@ struct FunctionJsonExtractImpl {
rapidjson::StringBuffer buf;
rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
const auto* json_col = data_columns[0];
auto insert_result_lambda = [&](rapidjson::Value& value, int row) {
auto insert_result_lambda = [&](rapidjson::Value& value, size_t row) {
if (value.IsNull()) {
null_map[row] = 1;
result_column.insert_default();
Expand All @@ -909,7 +914,9 @@ struct FunctionJsonExtractImpl {
const auto& obj = json_col->get_data_at(row);
std::string_view json_string(obj.data, obj.size);
if (UNLIKELY((parsed_paths).size() == 1)) {
document.SetString(json_string.data(), json_string.size(), allocator);
document.SetString(json_string.data(),
cast_set<rapidjson::SizeType>(json_string.size()),
allocator);
}
document.Parse(json_string.data(), json_string.size());
if (UNLIKELY(document.HasParseError())) {
Expand Down Expand Up @@ -938,7 +945,7 @@ struct FunctionJsonExtractImpl {
} else {
rapidjson::Value value;
value.SetArray();
value.Reserve(data_columns.size() - 1, allocator);
value.Reserve(cast_set<rapidjson::SizeType>(data_columns.size() - 1), allocator);
for (size_t row = 0; row < input_rows_count; row++) {
value.Clear();
for (size_t col = 1; col < data_columns.size(); ++col) {
Expand Down Expand Up @@ -1073,7 +1080,7 @@ class FunctionJsonValid : public IFunction {
}

const auto& val = col_from_string->get_data_at(i);
if (parser.parse(val.data, val.size)) {
if (parser.parse(val.data, cast_set<unsigned int>(val.size))) {
vec_to[i] = 1;
} else {
vec_to[i] = 0;
Expand Down

0 comments on commit 977404e

Please sign in to comment.