HappenLee commented on code in PR #48695:
URL: https://github.com/apache/doris/pull/48695#discussion_r1986588628


##########
be/src/vec/functions/functions_geo.cpp:
##########
@@ -721,6 +721,291 @@ struct StContains {
     }
 }; // namespace doris::vectorized
 
+struct StIntersects {
+    static constexpr auto NEED_CONTEXT = true;
+    static constexpr auto NAME = "st_intersects";
+    static const size_t NUM_ARGS = 2;
+    using Type = DataTypeUInt8;
+    static Status execute(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                          size_t result) {
+        DCHECK_EQ(arguments.size(), 2);
+        auto return_type = block.get_data_type(result);
+        const auto& [left_column, left_const] =
+                unpack_if_const(block.get_by_position(arguments[0]).column);
+        const auto& [right_column, right_const] =
+                unpack_if_const(block.get_by_position(arguments[1]).column);
+
+        const auto size = std::max(left_column->size(), right_column->size());
+
+        auto res = ColumnUInt8::create();
+        res->reserve(size);
+        auto null_map = ColumnUInt8::create(size, 0);
+        auto& null_map_data = null_map->get_data();
+
+        if (left_const) {
+            const_vector(left_column, right_column, res, null_map_data, size);
+        } else if (right_const) {
+            vector_const(left_column, right_column, res, null_map_data, size);
+        } else {
+            vector_vector(left_column, right_column, res, null_map_data, size);
+        }
+        block.replace_by_position(result,
+                                  ColumnNullable::create(std::move(res), 
std::move(null_map)));
+        return Status::OK();
+    }
+
+    static void loop_do(StringRef& lhs_value, StringRef& rhs_value,
+                        std::vector<std::shared_ptr<GeoShape>>& shapes, int& i,
+                        ColumnUInt8::MutablePtr& res, NullMap& null_map, int 
row) {
+        StringRef* strs[2] = {&lhs_value, &rhs_value};
+        for (i = 0; i < 2; ++i) {
+            shapes[i] =
+                    
std::shared_ptr<GeoShape>(GeoShape::from_encoded(strs[i]->data, strs[i]->size));
+            if (shapes[i] == nullptr) {
+                null_map[row] = 1;
+                res->insert_default();
+                break;
+            }
+        }
+
+        if (i == 2) {
+            auto contains_value = shapes[0]->intersects(shapes[1].get());
+            res->insert_data(const_cast<const char*>((char*)&contains_value), 
0);
+        }
+    }
+
+    static void const_vector(const ColumnPtr& left_column, const ColumnPtr& 
right_column,
+                             ColumnUInt8::MutablePtr& res, NullMap& null_map, 
const size_t size) {
+        int i;
+        auto lhs_value = left_column->get_data_at(0);
+        std::vector<std::shared_ptr<GeoShape>> shapes = {nullptr, nullptr};
+        for (int row = 0; row < size; ++row) {
+            auto rhs_value = right_column->get_data_at(row);
+            loop_do(lhs_value, rhs_value, shapes, i, res, null_map, row);
+        }
+    }
+
+    static void vector_const(const ColumnPtr& left_column, const ColumnPtr& 
right_column,
+                             ColumnUInt8::MutablePtr& res, NullMap& null_map, 
const size_t size) {
+        int i;
+        auto rhs_value = right_column->get_data_at(0);
+        std::vector<std::shared_ptr<GeoShape>> shapes = {nullptr, nullptr};
+        for (int row = 0; row < size; ++row) {
+            auto lhs_value = left_column->get_data_at(row);
+            loop_do(lhs_value, rhs_value, shapes, i, res, null_map, row);
+        }
+    }
+
+    static void vector_vector(const ColumnPtr& left_column, const ColumnPtr& 
right_column,
+                              ColumnUInt8::MutablePtr& res, NullMap& null_map, 
const size_t size) {
+        int i;
+        std::vector<std::shared_ptr<GeoShape>> shapes = {nullptr, nullptr};
+        for (int row = 0; row < size; ++row) {
+            auto lhs_value = left_column->get_data_at(row);
+            auto rhs_value = right_column->get_data_at(row);
+            loop_do(lhs_value, rhs_value, shapes, i, res, null_map, row);
+        }
+    }
+
+    static Status open(FunctionContext* context, 
FunctionContext::FunctionStateScope scope) {

Review Comment:
   shold impl all of the unless func in parent class



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

Reply via email to