You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/02/08 10:58:36 UTC
[GitHub] [incubator-doris] BiteTheDDDDt opened a new pull request #7988: [Feature] [Vectorized] support locate function
BiteTheDDDDt opened a new pull request #7988:
URL: https://github.com/apache/incubator-doris/pull/7988
# Proposed changes
Issue Number: close #7987
@HappenLee
## Problem Summary:
Describe the overview of changes.
## Checklist(Required)
1. Does it affect the original behavior: (Yes/No/I Don't know)
2. Has unit tests been added: (Yes/No/No Need)
3. Has document been added or modified: (Yes/No/No Need)
4. Does it need to update dependencies: (Yes/No)
5. Are there any changes that cannot be rolled back: (Yes/No)
## Further comments
If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
--
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-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] github-actions[bot] commented on pull request #7988: [Feature] [Vectorized] support locate function
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #7988:
URL: https://github.com/apache/incubator-doris/pull/7988#issuecomment-1035837209
--
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-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] morningman merged pull request #7988: [Feature] [Vectorized] support locate function
Posted by GitBox <gi...@apache.org>.
morningman merged pull request #7988:
URL: https://github.com/apache/incubator-doris/pull/7988
--
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-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] HappenLee commented on a change in pull request #7988: [Feature] [Vectorized] support locate function
Posted by GitBox <gi...@apache.org>.
HappenLee commented on a change in pull request #7988:
URL: https://github.com/apache/incubator-doris/pull/7988#discussion_r801532798
##########
File path: be/src/vec/functions/function_string.h
##########
@@ -1142,4 +1154,88 @@ struct MoneyFormatDecimalImpl {
}
};
+class FunctionStringLocatePos : public IFunction {
+public:
+ static constexpr auto name = "locate";
+ static FunctionPtr create() { return std::make_shared<FunctionStringLocatePos>(); }
+ String get_name() const override { return name; }
+ size_t get_number_of_arguments() const override { return 3; }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
+ return std::make_shared<DataTypeInt32>();
+ }
+
+ DataTypes get_variadic_argument_types() {
+ return {std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>(),
+ std::make_shared<DataTypeInt32>()};
+ }
+
+ bool use_default_implementation_for_constants() const override { return true; }
+
+ Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
+ size_t result, size_t input_rows_count) override {
+ auto col_substr =
+ block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+ auto col_str =
+ block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
+ auto col_pos =
+ block.get_by_position(arguments[2]).column->convert_to_full_column_if_const();
+
+ ColumnInt32::MutablePtr col_res = ColumnInt32::create();
+
+ auto& vec_pos = reinterpret_cast<const ColumnInt32*>(col_pos.get())->get_data();
+ auto& vec_res = col_res->get_data();
+ vec_res.resize(input_rows_count);
+
+ for (int i = 0; i < input_rows_count; ++i) {
+ vec_res[i] = locate_pos(col_substr->get_data_at(i).to_string_val(),
+ col_str->get_data_at(i).to_string_val(), vec_pos[i]);
+ }
+
+ block.replace_by_position(result, std::move(col_res));
+ return Status::OK();
+ }
+
+private:
+ int locate_pos(StringVal substr, StringVal str, int start_pos) {
+ if (substr.len == 0) {
+ if (start_pos <= 0) {
+ return 0;
+ } else if (start_pos == 1) {
+ return 1;
+ } else if (start_pos > str.len) {
+ return 0;
+ } else {
+ return start_pos;
+ }
+ }
+ // Hive returns 0 for *start_pos <= 0,
+ // but throws an exception for *start_pos > str->len.
+ // Since returning 0 seems to be Hive's error condition, return 0.
+ std::vector<size_t> index;
+ size_t char_len = get_char_len(str, &index);
+ if (start_pos > char_len) {
+ return 0;
+ }
+ StringValue substr_sv = StringValue::from_string_val(substr);
+ StringSearch search(&substr_sv);
+ // Input start_pos starts from 1.
+ StringValue adjusted_str(reinterpret_cast<char*>(str.ptr) + index[start_pos - 1],
+ str.len - index[start_pos - 1]);
+ int32_t match_pos = search.search(&adjusted_str);
+ if (match_pos >= 0) {
+ // Hive returns the position in the original string starting from 1.
+ size_t char_len = 0;
Review comment:
abtruct the function
--
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-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org