From bd6170c03e961191a1eb2419d5f6ba7fae015141 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 16 Dec 2024 19:47:12 +0800 Subject: [PATCH] fix:[TS-5761] error for in operator --- source/util/src/thashutil.c | 40 +++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/source/util/src/thashutil.c b/source/util/src/thashutil.c index 5499a651c1..b466e1b351 100644 --- a/source/util/src/thashutil.c +++ b/source/util/src/thashutil.c @@ -143,6 +143,38 @@ uint64_t MurmurHash3_64(const char *key, uint32_t len) { uint32_t taosIntHash_32(const char *key, uint32_t UNUSED_PARAM(len)) { return *(uint32_t *)key; } uint32_t taosIntHash_16(const char *key, uint32_t UNUSED_PARAM(len)) { return *(uint16_t *)key; } uint32_t taosIntHash_8(const char *key, uint32_t UNUSED_PARAM(len)) { return *(uint8_t *)key; } +uint32_t taosFloatHash(const char *key, uint32_t UNUSED_PARAM(len)) { + float f = GET_FLOAT_VAL(key); + if (isnan(f)) { + return 0x7fc00000; + } + + if (FLT_EQUAL(f, 0.0)) { + return 0; + } + if (fabs(f) < FLT_MAX / BASE - DLT) { + int32_t t = (int32_t)(round(BASE * (f + DLT))); + return (uint32_t)t; + } else { + return 0x7fc00000; + } +} +uint32_t taosDoubleHash(const char *key, uint32_t UNUSED_PARAM(len)) { + double f = GET_DOUBLE_VAL(key); + if (isnan(f)) { + return 0x7fc00000; + } + + if (FLT_EQUAL(f, 0.0)) { + return 0; + } + if (fabs(f) < DBL_MAX / BASE - DLT) { + int32_t t = (int32_t)(round(BASE * (f + DLT))); + return (uint32_t)t; + } else { + return 0x7fc00000; + } +} uint32_t taosIntHash_64(const char *key, uint32_t UNUSED_PARAM(len)) { uint64_t val = *(uint64_t *)key; @@ -158,7 +190,6 @@ _hash_fn_t taosGetDefaultHashFunction(int32_t type) { case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_DOUBLE: fn = taosIntHash_64; break; case TSDB_DATA_TYPE_BINARY: @@ -169,7 +200,6 @@ _hash_fn_t taosGetDefaultHashFunction(int32_t type) { break; case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_FLOAT: fn = taosIntHash_32; break; case TSDB_DATA_TYPE_SMALLINT: @@ -181,6 +211,12 @@ _hash_fn_t taosGetDefaultHashFunction(int32_t type) { case TSDB_DATA_TYPE_TINYINT: fn = taosIntHash_8; break; + case TSDB_DATA_TYPE_FLOAT: + fn = taosFloatHash; + break; + case TSDB_DATA_TYPE_DOUBLE: + fn = taosDoubleHash; + break; default: fn = taosIntHash_32; break;