linrrzqqq commented on code in PR #63049:
URL: https://github.com/apache/doris/pull/63049#discussion_r3296709617


##########
be/src/exprs/function/geo/functions_geo.cpp:
##########
@@ -917,6 +919,174 @@ struct StDistance {
     }
 };
 
+struct StNumGeometries {
+    static constexpr auto NAME = "st_numgeometries";
+    static const size_t NUM_ARGS = 1;
+    using Type = DataTypeInt64;
+
+    static Status execute(Block& block, const ColumnNumbers& arguments, size_t 
result) {
+        DCHECK_EQ(arguments.size(), 1);
+
+        auto col = 
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        const auto size = col->size();
+
+        auto res = ColumnInt64::create();
+        res->reserve(size);
+
+        auto null_map = ColumnUInt8::create(size, 0);
+        auto& null_map_data = null_map->get_data();
+
+        for (int row = 0; row < size; ++row) {
+            auto value = col->get_data_at(row);
+            auto shape = GeoShape::from_encoded(value.data, value.size);
+            if (!shape) {
+                null_map_data[row] = 1;
+                res->insert_default();
+                continue;
+            }
+
+            res->insert_value(shape->num_geometries());
+        }
+
+        block.replace_by_position(result,
+                                  ColumnNullable::create(std::move(res), 
std::move(null_map)));
+        return Status::OK();
+    }
+};
+
+struct StGeometries {
+    static constexpr auto NAME = "st_geometries";
+    static const size_t NUM_ARGS = 1;
+
+    static Status execute(Block& block, const ColumnNumbers& arguments, size_t 
result) {
+        DCHECK_EQ(arguments.size(), 1);
+
+        auto col = 
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        const auto size = col->size();
+
+        auto nested_data = ColumnString::create();
+        auto offsets_col = ColumnArray::ColumnOffsets::create();
+        auto& offsets = offsets_col->get_data();
+        offsets.reserve(size);
+
+        auto null_map = ColumnUInt8::create(size, 0);
+        auto& null_map_data = null_map->get_data();
+
+        size_t current_offset = 0;
+        std::string buf;
+
+        for (size_t row = 0; row < size; ++row) {
+            auto shape_value = col->get_data_at(row);
+            auto shape = GeoShape::from_encoded(shape_value.data, 
shape_value.size);
+
+            if (!shape) {
+                null_map_data[row] = 1;
+                offsets.push_back(current_offset);
+                continue;
+            }
+
+            if (shape->type() == GEO_SHAPE_MULTI_POLYGON) {
+                auto* multi_polygon = 
static_cast<GeoMultiPolygon*>(shape.get());
+                const auto& polygons = multi_polygon->polygons();
+
+                if (polygons.empty()) {
+                    null_map_data[row] = 1;
+                    offsets.push_back(current_offset);
+                    continue;
+                }
+
+                for (const auto& polygon : polygons) {
+                    DCHECK(polygon != nullptr);
+                    buf.clear();
+                    polygon->encode_to(&buf);
+                    nested_data->insert_data(buf.data(), buf.size());
+                    ++current_offset;
+                }
+            } else {
+                nested_data->insert_data(shape_value.data, shape_value.size);
+                ++current_offset;
+            }
+
+            offsets.push_back(current_offset);
+        }
+
+        auto nested_null_map = ColumnUInt8::create(nested_data->size(), 0);
+        auto nested_nullable =
+                ColumnNullable::create(std::move(nested_data), 
std::move(nested_null_map));
+        auto array_col = ColumnArray::create(std::move(nested_nullable), 
std::move(offsets_col));
+
+        block.replace_by_position(
+                result, ColumnNullable::create(std::move(array_col), 
std::move(null_map)));
+
+        return Status::OK();
+    }
+};
+
+class FunctionStGeometries final : public IFunction {
+public:
+    static constexpr auto name = StGeometries::NAME;
+
+    static FunctionPtr create() { return 
std::make_shared<FunctionStGeometries>(); }
+
+    String get_name() const override { return name; }
+
+    size_t get_number_of_arguments() const override { return 
StGeometries::NUM_ARGS; }
+
+    bool is_variadic() const override { return false; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return make_nullable(
+                
std::make_shared<DataTypeArray>(make_nullable(std::make_shared<DataTypeString>())));
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        uint32_t result, size_t input_rows_count) const 
override {
+        return StGeometries::execute(block, arguments, result);
+    }
+};
+
+struct StNumPoints {
+    static constexpr auto NAME = "st_numpoints";
+    static const size_t NUM_ARGS = 1;
+    using Type = DataTypeInt64;
+
+    static Status execute(Block& block, const ColumnNumbers& arguments, size_t 
result) {
+        DCHECK_EQ(arguments.size(), 1);
+
+        auto col = 
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();

Review Comment:
   `ColumnView`



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

Reply via email to