This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new d7ee542dd4 [refactor](function) refine function geo #17289
d7ee542dd4 is described below

commit d7ee542dd4c20b7181fde90484ed21fc97a18143
Author: Gabriel <gabrielleeb...@gmail.com>
AuthorDate: Thu Mar 2 08:42:16 2023 +0800

    [refactor](function) refine function geo #17289
    
    remove unused constant args
---
 be/src/udf/udf.cpp                     |  15 ---
 be/src/udf/udf.h                       |   4 -
 be/src/udf/udf_internal.h              |   2 -
 be/src/vec/functions/functions_geo.cpp | 176 ++++++---------------------------
 4 files changed, 31 insertions(+), 166 deletions(-)

diff --git a/be/src/udf/udf.cpp b/be/src/udf/udf.cpp
index 785b2c7db0..0d31c42ceb 100644
--- a/be/src/udf/udf.cpp
+++ b/be/src/udf/udf.cpp
@@ -194,7 +194,6 @@ FunctionContext* FunctionContextImpl::clone(MemPool* pool) {
     doris_udf::FunctionContext* new_context =
             create_context(_state, pool, _intermediate_type, _return_type, 
_arg_types,
                            _varargs_buffer_size, _debug);
-    new_context->_impl->_constant_args = _constant_args;
     new_context->_impl->_constant_cols = _constant_cols;
     new_context->_impl->_fragment_local_fn_state = _fragment_local_fn_state;
     return new_context;
@@ -435,13 +434,6 @@ const FunctionContext::TypeDesc* 
FunctionContext::get_arg_type(int arg_idx) cons
     return &_impl->_arg_types[arg_idx];
 }
 
-bool FunctionContext::is_arg_constant(int i) const {
-    if (i < 0 || i >= _impl->_constant_args.size()) {
-        return false;
-    }
-    return _impl->_constant_args[i] != nullptr;
-}
-
 bool FunctionContext::is_col_constant(int i) const {
     if (i < 0 || i >= _impl->_constant_cols.size()) {
         return false;
@@ -449,13 +441,6 @@ bool FunctionContext::is_col_constant(int i) const {
     return _impl->_constant_cols[i] != nullptr;
 }
 
-AnyVal* FunctionContext::get_constant_arg(int i) const {
-    if (i < 0 || i >= _impl->_constant_args.size()) {
-        return nullptr;
-    }
-    return _impl->_constant_args[i];
-}
-
 doris::ColumnPtrWrapper* FunctionContext::get_constant_col(int i) const {
     if (i < 0 || i >= _impl->_constant_cols.size()) {
         return nullptr;
diff --git a/be/src/udf/udf.h b/be/src/udf/udf.h
index b57e930e36..4b3c2115ac 100644
--- a/be/src/udf/udf.h
+++ b/be/src/udf/udf.h
@@ -238,16 +238,12 @@ public:
 
     // Returns true if the arg_idx-th input argument (0 indexed, not including 
the
     // FunctionContext* argument) is a constant (e.g. 5, "string", 1 + 1).
-    bool is_arg_constant(int arg_idx) const;
-
     bool is_col_constant(int arg_idx) const;
 
     // Returns a pointer to the value of the arg_idx-th input argument (0 
indexed, not
     // including the FunctionContext* argument). Returns nullptr if the 
argument is not
     // constant. This function can be used to obtain user-specified constants 
in a UDF's
     // Init() or Close() functions.
-    AnyVal* get_constant_arg(int arg_idx) const;
-
     doris::ColumnPtrWrapper* get_constant_col(int arg_idx) const;
 
     ~FunctionContext();
diff --git a/be/src/udf/udf_internal.h b/be/src/udf/udf_internal.h
index ab786a6954..91676cc0ea 100644
--- a/be/src/udf/udf_internal.h
+++ b/be/src/udf/udf_internal.h
@@ -173,8 +173,6 @@ private:
     // Contains an AnyVal* for each argument of the function. If the AnyVal* 
is nullptr,
     // indicates that the corresponding argument is non-constant. Otherwise 
contains the
     // value of the argument.
-    std::vector<doris_udf::AnyVal*> _constant_args;
-
     std::vector<doris::ColumnPtrWrapper*> _constant_cols;
 
     bool _check_overflow_for_decimal = false;
diff --git a/be/src/vec/functions/functions_geo.cpp 
b/be/src/vec/functions/functions_geo.cpp
index f51715c19d..21e68537de 100644
--- a/be/src/vec/functions/functions_geo.cpp
+++ b/be/src/vec/functions/functions_geo.cpp
@@ -231,66 +231,27 @@ struct StCircle {
         auto null_type = std::reinterpret_pointer_cast<const 
DataTypeNullable>(return_type);
         res = ColumnNullable::create(return_type->create_column(), 
ColumnUInt8::create());
 
-        StConstructState* state =
-                
(StConstructState*)context->get_function_state(FunctionContext::FRAGMENT_LOCAL);
-        if (state == nullptr) {
-            GeoCircle circle;
-            std::string buf;
-            for (int row = 0; row < size; ++row) {
-                auto lng_value = center_lng->get_float64(row);
-                auto lat_value = center_lat->get_float64(row);
-                auto radius_value = radius->get_float64(row);
-
-                auto value = circle.init(lng_value, lat_value, radius_value);
-                if (value != GEO_PARSE_OK) {
-                    res->insert_data(nullptr, 0);
-                    continue;
-                }
-                buf.clear();
-                circle.encode_to(&buf);
-                res->insert_data(buf.data(), buf.size());
-            }
-            block.replace_by_position(result, std::move(res));
-        } else {
-            if (state->is_null) {
+        GeoCircle circle;
+        std::string buf;
+        for (int row = 0; row < size; ++row) {
+            auto lng_value = center_lng->get_float64(row);
+            auto lat_value = center_lat->get_float64(row);
+            auto radius_value = radius->get_float64(row);
+
+            auto value = circle.init(lng_value, lat_value, radius_value);
+            if (value != GEO_PARSE_OK) {
                 res->insert_data(nullptr, 0);
-                block.replace_by_position(result, 
ColumnConst::create(std::move(res), size));
-            } else {
-                res->insert_data(state->encoded_buf.data(), 
state->encoded_buf.size());
-                block.replace_by_position(result, 
ColumnConst::create(std::move(res), size));
+                continue;
             }
+            buf.clear();
+            circle.encode_to(&buf);
+            res->insert_data(buf.data(), buf.size());
         }
+        block.replace_by_position(result, std::move(res));
         return Status::OK();
     }
 
     static Status prepare(FunctionContext* context, 
FunctionContext::FunctionStateScope scope) {
-        if (scope != FunctionContext::FRAGMENT_LOCAL) {
-            return Status::OK();
-        }
-
-        if (!context->is_arg_constant(0) || !context->is_arg_constant(1) ||
-            !context->is_arg_constant(2)) {
-            return Status::OK();
-        }
-
-        std::shared_ptr<StConstructState> state = 
std::make_shared<StConstructState>();
-        DoubleVal* lng = 
reinterpret_cast<DoubleVal*>(context->get_constant_arg(0));
-        DoubleVal* lat = 
reinterpret_cast<DoubleVal*>(context->get_constant_arg(1));
-        DoubleVal* radius = 
reinterpret_cast<DoubleVal*>(context->get_constant_arg(2));
-        if (lng->is_null || lat->is_null || radius->is_null) {
-            state->is_null = true;
-        } else {
-            std::unique_ptr<GeoCircle> circle(new GeoCircle());
-
-            auto res = circle->init(lng->val, lat->val, radius->val);
-            if (res != GEO_PARSE_OK) {
-                state->is_null = true;
-            } else {
-                circle->encode_to(&state->encoded_buf);
-            }
-        }
-        context->set_function_state(scope, state);
-
         return Status::OK();
     }
 
@@ -314,14 +275,6 @@ struct StContains {
         auto null_type = std::reinterpret_pointer_cast<const 
DataTypeNullable>(return_type);
         auto res = ColumnNullable::create(return_type->create_column(), 
ColumnUInt8::create());
 
-        StContainsState* state =
-                
(StContainsState*)context->get_function_state(FunctionContext::FRAGMENT_LOCAL);
-        if (state != nullptr && state->is_null) {
-            res->insert_data(nullptr, 0);
-            block.replace_by_position(result, 
ColumnConst::create(std::move(res), size));
-            return Status::OK();
-        }
-
         int i;
         std::vector<std::shared_ptr<GeoShape>> shapes = {nullptr, nullptr};
         for (int row = 0; row < size; ++row) {
@@ -329,15 +282,11 @@ struct StContains {
             auto rhs_value = shape2->get_data_at(row);
             StringRef* strs[2] = {&lhs_value, &rhs_value};
             for (i = 0; i < 2; ++i) {
-                if (state != nullptr && state->shapes[i] != nullptr) {
-                    shapes[i] = state->shapes[i];
-                } else {
-                    shapes[i] = std::shared_ptr<GeoShape>(
-                            GeoShape::from_encoded(strs[i]->data, 
strs[i]->size));
-                    if (shapes[i] == nullptr) {
-                        res->insert_data(nullptr, 0);
-                        break;
-                    }
+                shapes[i] = std::shared_ptr<GeoShape>(
+                        GeoShape::from_encoded(strs[i]->data, strs[i]->size));
+                if (shapes[i] == nullptr) {
+                    res->insert_data(nullptr, 0);
+                    break;
                 }
             }
 
@@ -351,31 +300,6 @@ struct StContains {
     }
 
     static Status prepare(FunctionContext* context, 
FunctionContext::FunctionStateScope scope) {
-        if (scope != FunctionContext::FRAGMENT_LOCAL) {
-            return Status::OK();
-        }
-
-        if (!context->is_arg_constant(0) && !context->is_arg_constant(1)) {
-            return Status::OK();
-        }
-
-        std::shared_ptr<StContainsState> contains_ctx = 
std::make_shared<StContainsState>();
-        for (int i = 0; !contains_ctx->is_null && i < 2; ++i) {
-            if (context->is_arg_constant(i)) {
-                StringVal* str = 
reinterpret_cast<StringVal*>(context->get_constant_arg(i));
-                if (str->is_null) {
-                    contains_ctx->is_null = true;
-                } else {
-                    contains_ctx->shapes[i] =
-                            
std::shared_ptr<GeoShape>(GeoShape::from_encoded(str->ptr, str->len));
-                    if (contains_ctx->shapes[i] == nullptr) {
-                        contains_ctx->is_null = true;
-                    }
-                }
-            }
-        }
-
-        context->set_function_state(scope, contains_ctx);
         return Status::OK();
     }
 
@@ -434,63 +358,25 @@ struct StGeoFromText {
         auto null_type = std::reinterpret_pointer_cast<const 
DataTypeNullable>(return_type);
         auto res = ColumnNullable::create(return_type->create_column(), 
ColumnUInt8::create());
 
-        StConstructState* state =
-                
(StConstructState*)context->get_function_state(FunctionContext::FRAGMENT_LOCAL);
-        if (state == nullptr) {
-            GeoParseStatus status;
-            std::string buf;
-            for (int row = 0; row < size; ++row) {
-                auto value = geo->get_data_at(row);
-                std::unique_ptr<GeoShape> shape(
-                        GeoShape::from_wkt(value.data, value.size, &status));
-                if (shape == nullptr || status != GEO_PARSE_OK ||
-                    (Impl::shape_type != GEO_SHAPE_ANY && shape->type() != 
Impl::shape_type)) {
-                    res->insert_data(nullptr, 0);
-                    continue;
-                }
-                buf.clear();
-                shape->encode_to(&buf);
-                res->insert_data(buf.data(), buf.size());
-            }
-            block.replace_by_position(result, std::move(res));
-        } else {
-            if (state->is_null) {
+        GeoParseStatus status;
+        std::string buf;
+        for (int row = 0; row < size; ++row) {
+            auto value = geo->get_data_at(row);
+            std::unique_ptr<GeoShape> shape(GeoShape::from_wkt(value.data, 
value.size, &status));
+            if (shape == nullptr || status != GEO_PARSE_OK ||
+                (Impl::shape_type != GEO_SHAPE_ANY && shape->type() != 
Impl::shape_type)) {
                 res->insert_data(nullptr, 0);
-                block.replace_by_position(result, 
ColumnConst::create(std::move(res), size));
-            } else {
-                res->insert_data(state->encoded_buf.data(), 
state->encoded_buf.size());
-                block.replace_by_position(result, 
ColumnConst::create(std::move(res), size));
+                continue;
             }
+            buf.clear();
+            shape->encode_to(&buf);
+            res->insert_data(buf.data(), buf.size());
         }
+        block.replace_by_position(result, std::move(res));
         return Status::OK();
     }
 
     static Status prepare(FunctionContext* context, 
FunctionContext::FunctionStateScope scope) {
-        if (scope != FunctionContext::FRAGMENT_LOCAL) {
-            return Status::OK();
-        }
-
-        if (!context->is_arg_constant(0)) {
-            return Status::OK();
-        }
-
-        std::shared_ptr<StConstructState> state = 
std::make_shared<StConstructState>();
-        auto str_value = 
reinterpret_cast<StringVal*>(context->get_constant_arg(0));
-        if (str_value->is_null) {
-            state->is_null = true;
-        } else {
-            GeoParseStatus status;
-            std::unique_ptr<GeoShape> shape(GeoShape::from_wkt(
-                    const_cast<const char*>((char*)str_value->ptr), 
str_value->len, &status));
-            if (shape == nullptr ||
-                (Impl::shape_type != GEO_SHAPE_ANY && shape->type() != 
Impl::shape_type)) {
-                state->is_null = true;
-            } else {
-                shape->encode_to(&state->encoded_buf);
-            }
-        }
-
-        context->set_function_state(scope, state);
         return Status::OK();
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to