diff --git a/src/binder/bind_expression/bind_comparison_expression.cpp b/src/binder/bind_expression/bind_comparison_expression.cpp index 05d69c5d99..d7697e8948 100644 --- a/src/binder/bind_expression/bind_comparison_expression.cpp +++ b/src/binder/bind_expression/bind_comparison_expression.cpp @@ -5,6 +5,7 @@ #include "catalog/catalog.h" #include "common/exception/binder.h" #include "function/built_in_function_utils.h" +#include "function/struct/vector_struct_functions.h" #include "transaction/transaction.h" #include @@ -42,8 +43,19 @@ std::shared_ptr ExpressionBinder::bindComparisonExpression( DASSERT(children.size() == 2); if (isNodeOrRel(*children[0]) && isNodeOrRel(*children[1])) { expression_vector newChildren; - newChildren.push_back(children[0]->constCast().getInternalID()); - newChildren.push_back(children[1]->constCast().getInternalID()); + // For pattern expressions (NODE/REL), use getInternalID() directly + // For non-pattern expressions (VARIABLE, FUNCTION, etc.), extract the _ID field + for (const auto& child : children) { + if (child->expressionType == ExpressionType::PATTERN) { + newChildren.push_back(child->constCast().getInternalID()); + } else { + expression_vector extractChildren; + extractChildren.push_back(child); + extractChildren.push_back(createLiteralExpression(InternalKeyword::ID)); + newChildren.push_back( + bindScalarFunctionExpression(extractChildren, StructExtractFunctions::name)); + } + } return bindComparisonExpression(expressionType, newChildren); } diff --git a/src/function/pattern/label_function.cpp b/src/function/pattern/label_function.cpp index cb8f2f9910..ec22e1fd0a 100644 --- a/src/function/pattern/label_function.cpp +++ b/src/function/pattern/label_function.cpp @@ -88,7 +88,8 @@ std::shared_ptr LabelFunction::rewriteFunc(const RewriteFunctionBind return expressionBinder->createNullLiteralExpression(); } expression_vector children; - if (argument->expressionType == ExpressionType::VARIABLE) { + // For non-pattern expressions (VARIABLE, FUNCTION, etc.), extract the _LABEL field + if (argument->expressionType != ExpressionType::PATTERN) { children.push_back(input.arguments[0]); children.push_back(expressionBinder->createLiteralExpression(InternalKeyword::LABEL)); return expressionBinder->bindScalarFunctionExpression(children, diff --git a/test/test_files/function/comparison.test b/test/test_files/function/comparison.test index 948d77053b..060fe088ae 100644 --- a/test/test_files/function/comparison.test +++ b/test/test_files/function/comparison.test @@ -377,3 +377,24 @@ False -STATEMENT MATCH (a:person), (b:person) WHERE a.fName = "Alice" AND b.fName = "Bob" RETURN ID(a) >= ID(b); ---- 1 False + +-LOG EqualityInPatternExpressions +-STATEMENT MATCH p = (n)-[:knows]->(m:person {ID: 2}) WITH nodes(p) AS ns RETURN ns[1] = ns[1]; +---- 3 +True +True +True + +-LOG InequalityInPatternExpressions +-STATEMENT MATCH p = (n)-[:knows]->(m:person {ID: 2}) WITH nodes(p) AS ns RETURN ns[1] <> ns[2]; +---- 3 +True +True +True + +-LOG FalseEqualityInPatternExpressions +-STATEMENT MATCH p = (n)-[:knows]->(m:person {ID: 2}) WITH nodes(p) AS ns RETURN ns[1] = ns[2]; +---- 3 +False +False +False diff --git a/test/test_files/function/label.test b/test/test_files/function/label.test index 6ddf3e4ac3..2e817b3bf9 100644 --- a/test/test_files/function/label.test +++ b/test/test_files/function/label.test @@ -41,3 +41,9 @@ workAt -STATEMENT RETURN labels(null); ---- 1 +-LOG LabelOnPathNodeExtract +-STATEMENT MATCH p = (n)-[:knows]->(m:person {ID: 2}) WITH nodes(p) AS ns RETURN label(ns[1]); +---- 3 +person +person +person