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


##########
be/src/core/column/column_spatial.cpp:
##########
@@ -0,0 +1,322 @@
+// 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 "core/column/column_spatial.h"
+
+#include <crc32c/crc32c.h>
+
+#include <algorithm>
+#include <cstring>
+
+#include "common/exception.h"
+#include "core/column/columns_common.h"
+#include "exec/common/sip_hash.h"
+#include "exec/sort/sort_block.h"
+#include "util/hash_util.hpp"
+
+namespace doris {
+
+namespace {
+
+template <typename HashValue>
+void for_each_spatial_value(const ColumnSpatial& column, size_t start, size_t 
end,
+                            const uint8_t* null_map, HashValue&& hash_value) {
+    for (size_t row = start; row < end; ++row) {
+        if (null_map == nullptr || null_map[row] == 0) {
+            hash_value(row, column.get_data_at(row));
+        }
+    }
+}
+
+} // namespace
+
+void ColumnSpatial::update_hash_with_value(size_t n, SipHash& hash) const {
+    const auto value = get_data_at(n);
+    hash.update(reinterpret_cast<const char*>(&value.size), 
sizeof(value.size));
+    hash.update(value.data, value.size);
+}
+
+void ColumnSpatial::update_hashes_with_value(uint64_t* __restrict hashes,
+                                             const uint8_t* __restrict 
null_data) const {
+    for_each_spatial_value(*this, 0, size(), null_data, [&](size_t row, 
StringRef value) {
+        hashes[row] = HashUtil::xxHash64WithSeed(value.data, value.size, 
hashes[row]);
+    });
+}
+
+void ColumnSpatial::update_xxHash_with_value(size_t start, size_t end, 
uint64_t& hash,
+                                             const uint8_t* __restrict 
null_data) const {
+    for_each_spatial_value(*this, start, end, null_data, [&](size_t, StringRef 
value) {
+        hash = HashUtil::xxHash64WithSeed(value.data, value.size, hash);
+    });
+}
+
+void ColumnSpatial::update_crcs_with_value(uint32_t* __restrict hashes, 
PrimitiveType /* type */,
+                                           uint32_t rows, uint32_t /* offset 
*/,
+                                           const uint8_t* __restrict 
null_data) const {
+    DCHECK_EQ(rows, size());
+    for_each_spatial_value(*this, 0, rows, null_data, [&](size_t row, 
StringRef value) {
+        hashes[row] =
+                HashUtil::zlib_crc_hash(value.data, 
cast_set<uint32_t>(value.size), hashes[row]);
+    });
+}
+
+void ColumnSpatial::update_crc_with_value(size_t start, size_t end, uint32_t& 
hash,
+                                          const uint8_t* __restrict null_data) 
const {
+    for_each_spatial_value(*this, start, end, null_data, [&](size_t, StringRef 
value) {
+        hash = HashUtil::zlib_crc_hash(value.data, 
cast_set<uint32_t>(value.size), hash);
+    });
+}
+
+void ColumnSpatial::update_crc32c_batch(uint32_t* __restrict hashes,
+                                        const uint8_t* __restrict null_map) 
const {
+    for_each_spatial_value(*this, 0, size(), null_map, [&](size_t row, 
StringRef value) {
+        hashes[row] = crc32c_extend(hashes[row], reinterpret_cast<const 
uint8_t*>(value.data),
+                                    value.size);
+    });
+}
+
+void ColumnSpatial::update_crc32c_single(size_t start, size_t end, uint32_t& 
hash,
+                                         const uint8_t* __restrict null_map) 
const {
+    for_each_spatial_value(*this, start, end, null_map, [&](size_t, StringRef 
value) {
+        hash = crc32c_extend(hash, reinterpret_cast<const 
uint8_t*>(value.data), value.size);
+    });
+}
+
+void ColumnSpatial::insert_data(const char* pos, size_t length) {
+    if (length <= StringView::kInlineSize) {
+        _data.emplace_back(pos, cast_set<uint32_t>(length));
+    } else {
+        _data.emplace_back(_arena->insert(pos, length), 
cast_set<uint32_t>(length));
+    }
+}
+
+int ColumnSpatial::compare_at(size_t n, size_t m, const IColumn& rhs,
+                              int /* nan_direction_hint */) const {
+    const auto& spatial = assert_cast<const ColumnSpatial&>(rhs);
+    DCHECK_EQ(_primitive_type, spatial._primitive_type);
+    return _data[n].compare(spatial._data[m]);

Review Comment:
   I don't think this PR should enable `GROUP BY`, `DISTINCT`, or `MIN/MAX` 
directly on `GEOMETRY/GEOGRAPHY` using raw WKB byte semantics.
   
   For example, little-endian and big-endian WKB can represent exactly the same 
`POINT(1 2)`, yet the serialized grouping keys treat them as different values. 
`GROUP BY geog` therefore produces two groups and `SELECT DISTINCT geog` 
retains both, even though `ST_AsText` displays the same point. Likewise, the 
byte ordering here makes `MIN/MAX` depend on the encoding rather than a defined 
spatial ordering.
   
   Please reject these operations on native spatial types during FE analysis 
for now, with regression tests for both Geometry and Geography. Users who 
intentionally want byte-level grouping, deduplication, or ordering can express 
that explicitly through `ST_AsBinary(...)`, subject to the supported VARBINARY 
operations. Spatial equality and ordering should be designed separately instead 
of becoming an implicit contract of this read/write feature.



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