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/04/01 15:16:15 UTC

[GitHub] [incubator-doris] zenoyang commented on a change in pull request #8790: [Vectorized][Function] Support geolocation functions on vectorized engine

zenoyang commented on a change in pull request #8790:
URL: https://github.com/apache/incubator-doris/pull/8790#discussion_r840679162



##########
File path: be/src/vec/functions/functions_geo.cpp
##########
@@ -0,0 +1,242 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "vec/functions/functions_geo.h"
+
+#include "geo/geo_types.h"
+#include "gutil/strings/substitute.h"
+#include "vec/functions/simple_function_factory.h"
+
+namespace doris::vectorized {
+
+class DataTypeFloat64;
+
+struct StPoint {
+    static constexpr auto NAME = "st_point";
+    static const size_t NUM_ARGS = 2;
+    static Status execute(Block& block, const ColumnNumbers& arguments, size_t result) {
+        DCHECK_EQ(arguments.size(), 2);
+        auto return_type = block.get_data_type(result);
+        DCHECK_EQ(return_type->is_nullable(), true);
+        auto column_x = block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        auto column_y = block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
+
+        const auto size = column_x->size();
+
+        MutableColumnPtr res = nullptr;
+        auto null_type = std::reinterpret_pointer_cast<const DataTypeNullable>(return_type);
+        res = ColumnNullable::create(null_type->get_nested_type()->create_column(),
+                                     ColumnUInt8::create(size, 0));
+
+        for (int row = 0; row < size; ++row) {
+            if (column_x->is_null_at(row) || column_y->is_null_at(row)) {
+                res->insert_data(nullptr, 0);
+                continue;
+            }
+            GeoPoint point;

Review comment:
       It would be better to put the `point` outside the loop.
   Below is also.

##########
File path: be/src/vec/functions/functions_geo.cpp
##########
@@ -0,0 +1,242 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "vec/functions/functions_geo.h"
+
+#include "geo/geo_types.h"
+#include "gutil/strings/substitute.h"
+#include "vec/functions/simple_function_factory.h"
+
+namespace doris::vectorized {
+
+class DataTypeFloat64;
+
+struct StPoint {
+    static constexpr auto NAME = "st_point";
+    static const size_t NUM_ARGS = 2;
+    static Status execute(Block& block, const ColumnNumbers& arguments, size_t result) {
+        DCHECK_EQ(arguments.size(), 2);
+        auto return_type = block.get_data_type(result);
+        DCHECK_EQ(return_type->is_nullable(), true);
+        auto column_x = block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        auto column_y = block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
+
+        const auto size = column_x->size();
+
+        MutableColumnPtr res = nullptr;
+        auto null_type = std::reinterpret_pointer_cast<const DataTypeNullable>(return_type);
+        res = ColumnNullable::create(null_type->get_nested_type()->create_column(),
+                                     ColumnUInt8::create(size, 0));
+
+        for (int row = 0; row < size; ++row) {
+            if (column_x->is_null_at(row) || column_y->is_null_at(row)) {
+                res->insert_data(nullptr, 0);
+                continue;
+            }
+            GeoPoint point;
+            auto cur_res = point.from_coord(column_x->get_float64(row),
+                                            column_y->get_float64(row));
+            if (cur_res != GEO_PARSE_OK) {
+                res->insert_data(nullptr, 0);
+                continue;
+            }
+
+            std::string buf;

Review comment:
       the same as above




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