From 2710eb3fc99d99bc64560a1bcef7a108648e88f0 Mon Sep 17 00:00:00 2001 From: Xianhui Lin <35839735+JsDove@users.noreply.github.com> Date: Wed, 19 Mar 2025 20:22:13 +0800 Subject: [PATCH] fix: [2.5] Json Stats filter the data is double but the filter expr is int (#40771) Json Stats filter the data is double but the filter is int issue: https://github.com/milvus-io/milvus/issues/40707 master-pr:https://github.com/milvus-io/milvus/pull/38039 Signed-off-by: Xianhui.Lin --- .../src/exec/expression/BinaryRangeExpr.cpp | 20 +++++++++++++------ .../core/src/exec/expression/UnaryExpr.cpp | 19 ++++++++++++------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/internal/core/src/exec/expression/BinaryRangeExpr.cpp b/internal/core/src/exec/expression/BinaryRangeExpr.cpp index 3a98d188d7..49d514cc8d 100644 --- a/internal/core/src/exec/expression/BinaryRangeExpr.cpp +++ b/internal/core/src/exec/expression/BinaryRangeExpr.cpp @@ -532,26 +532,34 @@ PhyBinaryRangeFilterExpr::ExecRangeVisitorImplForJsonForIndex() { } while (false) #define BinaryRangeJSONTypeCompare(cmp) \ do { \ - if (type == uint8_t(milvus::index::JSONType::STRING)) { \ - if constexpr (std::is_same_v) { \ + if constexpr (std::is_same_v) { \ + if (type == uint8_t(milvus::index::JSONType::STRING)) { \ auto val = json.at_string(offset, size); \ return (cmp); \ } else { \ return false; \ } \ - } else if (type == uint8_t(milvus::index::JSONType::DOUBLE)) { \ - if constexpr (std::is_same_v) { \ + } else if constexpr (std::is_same_v) { \ + if (type == uint8_t(milvus::index::JSONType::INT64)) { \ + auto val = \ + std::stoll(std::string(json.at_string(offset, size))); \ + return (cmp); \ + } else if (type == uint8_t(milvus::index::JSONType::DOUBLE)) { \ auto val = \ std::stod(std::string(json.at_string(offset, size))); \ return (cmp); \ } else { \ return false; \ } \ - } else if (type == uint8_t(milvus::index::JSONType::INT64)) { \ - if constexpr (std::is_same_v) { \ + } else if constexpr (std::is_same_v) { \ + if (type == uint8_t(milvus::index::JSONType::INT64)) { \ auto val = \ std::stoll(std::string(json.at_string(offset, size))); \ return (cmp); \ + } else if (type == uint8_t(milvus::index::JSONType::DOUBLE)) { \ + auto val = \ + std::stod(std::string(json.at_string(offset, size))); \ + return (cmp); \ } else { \ return false; \ } \ diff --git a/internal/core/src/exec/expression/UnaryExpr.cpp b/internal/core/src/exec/expression/UnaryExpr.cpp index 8044a540ff..06cf119c79 100644 --- a/internal/core/src/exec/expression/UnaryExpr.cpp +++ b/internal/core/src/exec/expression/UnaryExpr.cpp @@ -946,25 +946,32 @@ PhyUnaryRangeFilterExpr::ExecRangeVisitorImplJsonForIndex() { #define UnaryJSONTypeCompare(cmp) \ do { \ - if (type == uint8_t(milvus::index::JSONType::STRING)) { \ - if constexpr (std::is_same_v) { \ + if constexpr (std::is_same_v) { \ + if (type == uint8_t(milvus::index::JSONType::STRING)) { \ auto x = json.at_string(offset, size); \ return (cmp); \ } else { \ return false; \ } \ - } else if (type == uint8_t(milvus::index::JSONType::DOUBLE)) { \ - if constexpr (std::is_same_v) { \ + } else if constexpr (std::is_same_v) { \ + if (type == uint8_t(milvus::index::JSONType::INT64)) { \ + auto x = \ + std::stoll(std::string(json.at_string(offset, size))); \ + return (cmp); \ + } else if (type == uint8_t(milvus::index::JSONType::DOUBLE)) { \ auto x = std::stod(std::string(json.at_string(offset, size))); \ return (cmp); \ } else { \ return false; \ } \ - } else if (type == uint8_t(milvus::index::JSONType::INT64)) { \ - if constexpr (std::is_same_v) { \ + } else if constexpr (std::is_same_v) { \ + if (type == uint8_t(milvus::index::JSONType::INT64)) { \ auto x = \ std::stoll(std::string(json.at_string(offset, size))); \ return (cmp); \ + } else if (type == uint8_t(milvus::index::JSONType::DOUBLE)) { \ + auto x = std::stod(std::string(json.at_string(offset, size))); \ + return (cmp); \ } else { \ return false; \ } \