HappenLee commented on code in PR #24342:
URL: https://github.com/apache/doris/pull/24342#discussion_r1325543116
##########
be/src/vec/functions/function_string.h:
##########
@@ -2045,6 +2045,107 @@ class FunctionStringMd5AndSM3 : public IFunction {
}
};
+class FunctionStringDigestSHA2 : public IFunction {
+public:
+ static constexpr auto name = "sha2";
+ static FunctionPtr create() { return
std::make_shared<FunctionStringDigestSHA2>(); }
+ String get_name() const override { return name; }
+ size_t get_number_of_arguments() const override { return 2; }
+ bool is_variadic() const override { return true; }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
+ return std::make_shared<DataTypeString>();
+ }
+
+ Status execute_impl(FunctionContext* context, Block& block, const
ColumnNumbers& arguments,
+ size_t result, size_t input_rows_count) override {
+ DCHECK(!is_column_const(*block.get_by_position(arguments[0]).column));
+
+ ColumnPtr str_col = block.get_by_position(arguments[0]).column;
+ auto& data = assert_cast<const
ColumnString*>(str_col.get())->get_chars();
+ auto& offset = assert_cast<const
ColumnString*>(str_col.get())->get_offsets();
+
+ [[maybe_unused]] const auto& [right_column, right_const] =
+ unpack_if_const(block.get_by_position(arguments[1]).column);
+ auto digest_length = assert_cast<const
ColumnInt32*>(right_column.get())->get_data()[0];
+
+ auto res_col = ColumnString::create();
+ auto& res_data = res_col->get_chars();
+ auto& res_offset = res_col->get_offsets();
+ res_offset.resize(input_rows_count);
+
+ if (digest_length == 224) {
+ execute_224(data, offset, input_rows_count, res_data, res_offset);
+ } else if (digest_length == 256) {
+ execute_256(data, offset, input_rows_count, res_data, res_offset);
+ } else if (digest_length == 384) {
+ execute_384(data, offset, input_rows_count, res_data, res_offset);
+ } else if (digest_length == 512) {
+ execute_512(data, offset, input_rows_count, res_data, res_offset);
+ } else {
+ return Status::InvalidArgument(
+ "sha2's digest length only support 224/256/384/512 but
meet {}", digest_length);
+ }
+
+ block.replace_by_position(result, std::move(res_col));
+ return Status::OK();
+ }
+
+private:
+ void execute_224(const ColumnString::Chars& data, const
ColumnString::Offsets& offset,
+ int input_rows_count, ColumnString::Chars& res_data,
+ ColumnString::Offsets& res_offset) {
+ SHA224Digest digest;
Review Comment:
which can cause error
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]