From 59d26b53a05d15dc63a764b0f8bdcf481fdc67bd Mon Sep 17 00:00:00 2001 From: obdev Date: Sat, 28 Jan 2023 18:26:43 +0800 Subject: [PATCH] fix gis hash --- deps/oblib/src/common/object/ob_obj_funcs.h | 62 ++++++++++++++++++- src/share/datum/ob_datum_funcs.cpp | 1 + .../resolver/expr/ob_shared_expr_resolver.cpp | 6 +- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/deps/oblib/src/common/object/ob_obj_funcs.h b/deps/oblib/src/common/object/ob_obj_funcs.h index 535976a530..3079c8f28b 100644 --- a/deps/oblib/src/common/object/ob_obj_funcs.h +++ b/deps/oblib/src/common/object/ob_obj_funcs.h @@ -1489,7 +1489,67 @@ DEF_TEXT_FUNCS(ObTinyTextType, string, ObString); DEF_TEXT_FUNCS(ObTextType, string, ObString); DEF_TEXT_FUNCS(ObMediumTextType, string, ObString); DEF_TEXT_FUNCS(ObLongTextType, string, ObString); -DEF_TEXT_FUNCS(ObGeometryType, string, ObString); //todo: not implement + + +#define DEF_GEO_CS_FUNCS(OBJTYPE) \ + template <> \ + inline int64_t obj_crc64(const ObObj &obj, const int64_t current) \ + { \ + int type = obj.get_type(); \ + int cs = obj.get_collation_type(); \ + int64_t ret = ob_crc64_sse42(current, &type, sizeof(type)); \ + ret = ob_crc64_sse42(ret, &cs, sizeof(cs)); \ + return ob_crc64_sse42(ret, obj.get_string_ptr(), obj.get_string_len()); \ + } \ + template <> \ + inline int64_t obj_crc64_v2(const ObObj &obj, const int64_t current) \ + { \ + int cs = obj.get_collation_type(); \ + int64_t ret = ob_crc64_sse42(current, &cs, sizeof(cs)); \ + return ob_crc64_sse42(ret, obj.get_string_ptr(), obj.get_string_len()); \ + } \ + template <> \ + inline void obj_batch_checksum(const ObObj &obj, ObBatchChecksum &bc) \ + { \ + int type = obj.get_type(); \ + int cs = obj.get_collation_type(); \ + bc.fill(&type, sizeof(type)); \ + bc.fill(&cs, sizeof(cs)); \ + bc.fill(obj.get_string_ptr(), obj.get_string_len()); \ + } \ + template <> \ + inline uint64_t obj_murmurhash(const ObObj &obj, const uint64_t hash) \ + { \ + return varchar_murmurhash(obj, obj.get_collation_type(), hash); \ + } \ + template \ + struct ObjHashCalculator \ + { \ + static uint64_t calc_hash_value(const ObObj ¶m, const uint64_t hash) { \ + common::ObString wkb = param.get_string(); \ + uint64_t hash_res = hash; \ + if (wkb.length() > 0 && !param.is_null()) { \ + hash_res = ObCharset::hash(param.get_collation_type(), param.get_string_ptr(), \ + param.get_string_len(), hash, \ + false, T::is_varchar_hash ? T::hash : NULL); \ + } \ + return hash_res; \ + } \ + }; \ + template <> \ + inline uint64_t obj_crc64_v3(const ObObj &obj, const uint64_t current) \ + { \ + int cs = obj.get_collation_type(); \ + uint64_t ret = ob_crc64_sse42(current, &cs, sizeof(cs)); \ + return ob_crc64_sse42(ret, obj.get_string_ptr(), obj.get_string_len()); \ + } \ + +#define DEF_GEO_FUNCS(OBJTYPE, TYPE, VTYPE) \ + DEF_TEXT_PRINT_FUNCS(OBJTYPE); \ + DEF_GEO_CS_FUNCS(OBJTYPE); \ + DEF_TEXT_SERIALIZE_FUNCS(OBJTYPE, TYPE, VTYPE) + +DEF_GEO_FUNCS(ObGeometryType, string, ObString); #define DEF_JSON_CS_FUNCS(OBJTYPE) \ template <> \ diff --git a/src/share/datum/ob_datum_funcs.cpp b/src/share/datum/ob_datum_funcs.cpp index d4ccc385bb..bf9cd18461 100644 --- a/src/share/datum/ob_datum_funcs.cpp +++ b/src/share/datum/ob_datum_funcs.cpp @@ -295,6 +295,7 @@ DEF_DATUM_SPECIAL_HASH_FUNCS(ObUFloatType); DEF_DATUM_SPECIAL_HASH_FUNCS(ObDoubleType); DEF_DATUM_SPECIAL_HASH_FUNCS(ObUDoubleType); DEF_DATUM_SPECIAL_HASH_FUNCS(ObJsonType); +DEF_DATUM_SPECIAL_HASH_FUNCS(ObGeometryType); OB_INLINE static uint64_t datum_varchar_hash(const ObDatum &datum, const ObCollationType cs_type, diff --git a/src/sql/resolver/expr/ob_shared_expr_resolver.cpp b/src/sql/resolver/expr/ob_shared_expr_resolver.cpp index 35adb167d9..6bbc32eee7 100644 --- a/src/sql/resolver/expr/ob_shared_expr_resolver.cpp +++ b/src/sql/resolver/expr/ob_shared_expr_resolver.cpp @@ -61,10 +61,8 @@ uint64_t ObSharedExprResolver::hash_expr_tree(ObRawExpr *expr, uint64_t hash_cod if (expr->get_expr_type() == T_QUESTIONMARK) { // do nothing } else if (expr->is_const_raw_expr()) { - if (expr->get_expr_type() != T_GEOMETRY) { // GIS does not support hash func - hash_code = common::do_hash(static_cast(expr)->get_value(), - hash_code); - } + hash_code = common::do_hash(static_cast(expr)->get_value(), + hash_code); } else if (expr->get_expr_type() == T_FUN_SYS_CAST) { hash_code = hash_expr_tree(expr->get_param_expr(0), hash_code, false); } else if (!is_root) {