amorynan commented on code in PR #21413: URL: https://github.com/apache/doris/pull/21413#discussion_r1249090823
########## be/src/vec/functions/function_json.cpp: ########## @@ -1128,6 +1129,95 @@ class FunctionJsonUnquote : public IFunction { } }; +class FunctionJsonDepth : public IFunction { +public: + static constexpr auto name = "json_depth"; + static FunctionPtr create() { return std::make_shared<FunctionJsonDepth>(); } + + String get_name() const override { return name; } + + size_t get_number_of_arguments() const override { return 1; } + + bool use_default_implementation_for_nulls() const override { return false; } + + bool use_default_implementation_for_constants() const override { return false; } + + DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { + return make_nullable(std::make_shared<DataTypeInt32>()); + } + + Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) override { + auto result_col = ColumnInt32::create(input_rows_count, 0); + auto result_null_map = ColumnUInt8::create(input_rows_count, 0); + + // since I've overriden the function `use_default_implementation_for_constants` to return false, + // I have to deal with const columns specifically. + ColumnPtr input_col = block.get_by_position(arguments[0]).column; + const auto& [nullable_input_col, _] = unpack_if_const(input_col); + + // TODO(niebayes): call `reserve` to avoid potential reallocations. + SimdJSONParser parser; + + // Doris processes the input data in batch, aka. a block. + // a block consists of several cells where each cell is indexed by a row and a column numbers. + // for instance, the json string passed into this function is stored in a cell. + for (size_t i = 0; i < input_rows_count; ++i) { + if (nullable_input_col->is_null_at(i)) { + result_null_map->get_data()[i] = 1; + continue; + } + + const ColumnString* col_str = check_and_get_column<ColumnString>(nullable_input_col); Review Comment: make check_and_get_column<ColumnString>() out of forloop -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org