Skip to content

Commit

Permalink
[fix](json-quote) fix json quote func for not find the func (#42005)
Browse files Browse the repository at this point in the history
pick #39931
  • Loading branch information
amorynan authored Oct 17, 2024
1 parent 633f531 commit 59d3326
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
10 changes: 8 additions & 2 deletions be/src/vec/functions/function_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,12 @@ class FunctionJsonAlwaysNotNullable : public IFunction {
struct FunctionJsonQuoteImpl {
static constexpr auto name = "json_quote";

static DataTypePtr get_return_type_impl(const DataTypes& arguments) {
if (!arguments.empty() && arguments[0] && arguments[0]->is_nullable()) {
return make_nullable(std::make_shared<DataTypeString>());
}
return std::make_shared<DataTypeString>();
}
static void execute(const std::vector<const ColumnString*>& data_columns,
ColumnString& result_column, size_t input_rows_count) {
rapidjson::Document document;
Expand All @@ -810,13 +816,13 @@ struct FunctionJsonQuoteImpl {
rapidjson::Value value;

rapidjson::StringBuffer buf;
rapidjson::Writer<rapidjson::StringBuffer> writer(buf);

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);

buf.Clear();
rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
value.Accept(writer);
result_column.insert_data(buf.GetString(), buf.GetSize());
}
Expand Down Expand Up @@ -893,7 +899,7 @@ class FunctionJson : public IFunction {
bool is_variadic() const override { return true; }

DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
return std::make_shared<DataTypeString>();
return Impl::get_return_type_impl(arguments);
}

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
Expand Down
Loading

0 comments on commit 59d3326

Please sign in to comment.