From f23ec9416596b61268d44ae1413fc93bfaf11803 Mon Sep 17 00:00:00 2001 From: Bernie Chen Date: Wed, 17 Sep 2025 16:29:49 -0400 Subject: [PATCH 1/4] support RangeLiteral params as expressions --- scripts/antlr4/Cypher.g4 | 6 +- scripts/antlr4/hash.md5 | 2 +- src/antlr4/Cypher.g4 | 6 +- src/binder/bind/bind_graph_pattern.cpp | 22 ++- src/binder/expression/expression_util.cpp | 16 ++ .../binder/expression/expression_util.h | 1 + src/include/common/types/types.h | 1 + .../parser/query/graph_pattern/rel_pattern.h | 4 +- .../transform/transform_graph_pattern.cpp | 19 +-- third_party/antlr4_cypher/cypher_parser.cpp | 152 +++++++++--------- .../antlr4_cypher/include/cypher_parser.h | 6 +- 11 files changed, 135 insertions(+), 100 deletions(-) diff --git a/scripts/antlr4/Cypher.g4 b/scripts/antlr4/Cypher.g4 index 283815cc751..f43a4b8d85a 100644 --- a/scripts/antlr4/Cypher.g4 +++ b/scripts/antlr4/Cypher.g4 @@ -684,7 +684,7 @@ kU_RecursiveType oC_RangeLiteral : oC_LowerBound? SP? DOTDOT SP? oC_UpperBound? - | oC_IntegerLiteral ; + | oC_Expression ; kU_RecursiveComprehension : '(' SP? oC_Variable SP? ',' SP? oC_Variable ( SP? '|' SP? oC_Where SP? )? ( SP? '|' SP? kU_RecursiveProjectionItems SP? ',' SP? kU_RecursiveProjectionItems SP? )? ')' ; @@ -693,10 +693,10 @@ kU_RecursiveProjectionItems : '{' SP? oC_ProjectionItems? SP? '}' ; oC_LowerBound - : DecimalInteger ; + : oC_Expression ; oC_UpperBound - : DecimalInteger ; + : oC_Expression ; oC_LabelName : oC_SchemaName ; diff --git a/scripts/antlr4/hash.md5 b/scripts/antlr4/hash.md5 index f6d1ec11e7d..51a2825bff2 100644 --- a/scripts/antlr4/hash.md5 +++ b/scripts/antlr4/hash.md5 @@ -1 +1 @@ -8334a684be17e562250acf07ae2bbca0 +c39017591a40317e1e5aabb586c04e45 diff --git a/src/antlr4/Cypher.g4 b/src/antlr4/Cypher.g4 index e409515c72e..12b47b0e72b 100644 --- a/src/antlr4/Cypher.g4 +++ b/src/antlr4/Cypher.g4 @@ -437,7 +437,7 @@ kU_RecursiveType oC_RangeLiteral : oC_LowerBound? SP? DOTDOT SP? oC_UpperBound? - | oC_IntegerLiteral ; + | oC_Expression ; kU_RecursiveComprehension : '(' SP? oC_Variable SP? ',' SP? oC_Variable ( SP? '|' SP? oC_Where SP? )? ( SP? '|' SP? kU_RecursiveProjectionItems SP? ',' SP? kU_RecursiveProjectionItems SP? )? ')' ; @@ -446,10 +446,10 @@ kU_RecursiveProjectionItems : '{' SP? oC_ProjectionItems? SP? '}' ; oC_LowerBound - : DecimalInteger ; + : oC_Expression ; oC_UpperBound - : DecimalInteger ; + : oC_Expression ; oC_LabelName : oC_SchemaName ; diff --git a/src/binder/bind/bind_graph_pattern.cpp b/src/binder/bind/bind_graph_pattern.cpp index ab89139ac0e..501b57b6de4 100644 --- a/src/binder/bind/bind_graph_pattern.cpp +++ b/src/binder/bind/bind_graph_pattern.cpp @@ -526,15 +526,23 @@ expression_vector Binder::bindRecursivePatternRelProjectionList(const RecursiveR std::pair Binder::bindVariableLengthRelBound(const RelPattern& relPattern) { auto recursiveInfo = relPattern.getRecursiveInfo(); uint32_t lowerBound = 0; - function::CastString::operation( - ku_string_t{recursiveInfo->lowerBound.c_str(), recursiveInfo->lowerBound.length()}, - lowerBound); + auto boundLowerExpression = expressionBinder.bindExpression(*recursiveInfo->lowerBound); + if (boundLowerExpression->expressionType != ExpressionType::LITERAL && + boundLowerExpression->expressionType != ExpressionType::PARAMETER) { + throw BinderException( + "Rel range lower bound must be a parameter/literal expression."); + } + lowerBound = ExpressionUtil::evaluateAsVariableLengthRelBound(*boundLowerExpression); auto maxDepth = clientContext->getClientConfig()->varLengthMaxDepth; auto upperBound = maxDepth; - if (!recursiveInfo->upperBound.empty()) { - function::CastString::operation( - ku_string_t{recursiveInfo->upperBound.c_str(), recursiveInfo->upperBound.length()}, - upperBound); + if (recursiveInfo->upperBound.get()) { + auto boundUpperExpression = expressionBinder.bindExpression(*recursiveInfo->upperBound); + if (boundUpperExpression->expressionType != ExpressionType::LITERAL && + boundUpperExpression->expressionType != ExpressionType::PARAMETER) { + throw BinderException( + "Rel range upper bound must be a parameter/literal expression."); + } + upperBound = ExpressionUtil::evaluateAsVariableLengthRelBound(*boundUpperExpression); } if (lowerBound > upperBound) { throw BinderException(stringFormat("Lower bound of rel {} is greater than upperBound.", diff --git a/src/binder/expression/expression_util.cpp b/src/binder/expression/expression_util.cpp index a11e2acd37f..d229546f327 100644 --- a/src/binder/expression/expression_util.cpp +++ b/src/binder/expression/expression_util.cpp @@ -471,6 +471,22 @@ uint64_t ExpressionUtil::evaluateAsSkipLimit(const Expression& expr) { return number; } +uint64_t ExpressionUtil::evaluateAsVariableLengthRelBound(const Expression& expr) { + auto value = evaluateAsLiteralValue(expr); + auto errorMsg = "Rel range upper/lower bound must be a non-negative integer."; + uint64_t number = INVALID_RELBOUND; + TypeUtils::visit( + value.getDataType(), + [&](T) { + if (value.getValue() < 0) { + throw RuntimeException{errorMsg}; + } + number = (uint64_t)value.getValue(); + }, + [&](auto) { throw RuntimeException{errorMsg}; }); + return number; +} + template T ExpressionUtil::getExpressionVal(const Expression& expr, const Value& value, const LogicalType& targetType, validate_param_func validateParamFunc) { diff --git a/src/include/binder/expression/expression_util.h b/src/include/binder/expression/expression_util.h index 687f1fc4e17..7b268042aae 100644 --- a/src/include/binder/expression/expression_util.h +++ b/src/include/binder/expression/expression_util.h @@ -64,6 +64,7 @@ struct KUZU_API ExpressionUtil { static bool canEvaluateAsLiteral(const Expression& expr); static common::Value evaluateAsLiteralValue(const Expression& expr); static uint64_t evaluateAsSkipLimit(const Expression& expr); + static uint64_t evaluateAsVariableLengthRelBound(const Expression& expr); template using validate_param_func = void (*)(T); diff --git a/src/include/common/types/types.h b/src/include/common/types/types.h index a74ebd57fe8..019c073ed0a 100644 --- a/src/include/common/types/types.h +++ b/src/include/common/types/types.h @@ -85,6 +85,7 @@ using relID_t = internalID_t; using cardinality_t = uint64_t; constexpr offset_t INVALID_LIMIT = UINT64_MAX; +constexpr offset_t INVALID_RELBOUND = UINT32_MAX; using offset_vec_t = std::vector; // System representation for internalID. struct KUZU_API internalID_t { diff --git a/src/include/parser/query/graph_pattern/rel_pattern.h b/src/include/parser/query/graph_pattern/rel_pattern.h index 498f529a645..ecc30ffea66 100644 --- a/src/include/parser/query/graph_pattern/rel_pattern.h +++ b/src/include/parser/query/graph_pattern/rel_pattern.h @@ -10,8 +10,8 @@ namespace parser { enum class ArrowDirection : uint8_t { LEFT = 0, RIGHT = 1, BOTH = 2 }; struct RecursiveRelPatternInfo { - std::string lowerBound; - std::string upperBound; + std::unique_ptr lowerBound = nullptr; + std::unique_ptr upperBound = nullptr; std::string weightPropertyName; std::string relName; std::string nodeName; diff --git a/src/parser/transform/transform_graph_pattern.cpp b/src/parser/transform/transform_graph_pattern.cpp index b3cab20b0b7..3164b1208f0 100644 --- a/src/parser/transform/transform_graph_pattern.cpp +++ b/src/parser/transform/transform_graph_pattern.cpp @@ -1,5 +1,6 @@ #include "common/assert.h" #include "parser/query/graph_pattern/pattern_element.h" +#include "parser/expression/parsed_literal_expression.h" #include "parser/transformer.h" using namespace kuzu::common; @@ -126,23 +127,23 @@ RelPattern Transformer::transformRelationshipPattern( relType = QueryRelType::VARIABLE_LENGTH_WALK; } // Parse lower, upper bound - auto lowerBound = std::string("1"); - auto upperBound = std::string(""); + std::unique_ptr lowerBound = std::make_unique(Value(1), "1"); + std::unique_ptr upperBound = nullptr; auto range = recursiveDetail->oC_RangeLiteral(); if (range) { - if (range->oC_IntegerLiteral()) { - lowerBound = range->oC_IntegerLiteral()->getText(); - upperBound = lowerBound; + if (range->oC_Expression()) { + lowerBound = transformExpression(*range->oC_Expression()); + upperBound = lowerBound->copy(); } if (range->oC_LowerBound()) { - lowerBound = range->oC_LowerBound()->getText(); + lowerBound = transformExpression(*range->oC_LowerBound()->oC_Expression()); } if (range->oC_UpperBound()) { - upperBound = range->oC_UpperBound()->getText(); + upperBound = transformExpression(*range->oC_UpperBound()->oC_Expression()); } } - recursiveInfo.lowerBound = lowerBound; - recursiveInfo.upperBound = upperBound; + recursiveInfo.lowerBound = std::move(lowerBound); + recursiveInfo.upperBound = std::move(upperBound); // Parse recursive comprehension auto comprehension = recursiveDetail->kU_RecursiveComprehension(); if (comprehension) { diff --git a/third_party/antlr4_cypher/cypher_parser.cpp b/third_party/antlr4_cypher/cypher_parser.cpp index 1bff0da7470..3b08fe38dcc 100644 --- a/third_party/antlr4_cypher/cypher_parser.cpp +++ b/third_party/antlr4_cypher/cypher_parser.cpp @@ -1013,7 +1013,7 @@ void cypherParserInitialize() { 0,0,2109,2108,1,0,0,0,2109,2110,1,0,0,0,2110,2111,1,0,0,0,2111,2113,5, 165,0,0,2112,2114,5,183,0,0,2113,2112,1,0,0,0,2113,2114,1,0,0,0,2114, 2116,1,0,0,0,2115,2117,3,238,119,0,2116,2115,1,0,0,0,2116,2117,1,0,0, - 0,2117,2120,1,0,0,0,2118,2120,3,342,171,0,2119,2106,1,0,0,0,2119,2118, + 0,2117,2120,1,0,0,0,2118,2120,3,244,122,0,2119,2106,1,0,0,0,2119,2118, 1,0,0,0,2120,231,1,0,0,0,2121,2123,5,2,0,0,2122,2124,5,183,0,0,2123,2122, 1,0,0,0,2123,2124,1,0,0,0,2124,2125,1,0,0,0,2125,2127,3,332,166,0,2126, 2128,5,183,0,0,2127,2126,1,0,0,0,2127,2128,1,0,0,0,2128,2129,1,0,0,0, @@ -1034,65 +1034,65 @@ void cypherParserInitialize() { 5,9,0,0,2171,2173,5,183,0,0,2172,2171,1,0,0,0,2172,2173,1,0,0,0,2173, 2175,1,0,0,0,2174,2176,3,190,95,0,2175,2174,1,0,0,0,2175,2176,1,0,0,0, 2176,2178,1,0,0,0,2177,2179,5,183,0,0,2178,2177,1,0,0,0,2178,2179,1,0, - 0,0,2179,2180,1,0,0,0,2180,2181,5,10,0,0,2181,235,1,0,0,0,2182,2183,5, - 170,0,0,2183,237,1,0,0,0,2184,2185,5,170,0,0,2185,239,1,0,0,0,2186,2187, - 3,346,173,0,2187,241,1,0,0,0,2188,2189,3,346,173,0,2189,243,1,0,0,0,2190, - 2191,3,246,123,0,2191,245,1,0,0,0,2192,2199,3,248,124,0,2193,2194,5,183, - 0,0,2194,2195,5,119,0,0,2195,2196,5,183,0,0,2196,2198,3,248,124,0,2197, - 2193,1,0,0,0,2198,2201,1,0,0,0,2199,2197,1,0,0,0,2199,2200,1,0,0,0,2200, - 247,1,0,0,0,2201,2199,1,0,0,0,2202,2209,3,250,125,0,2203,2204,5,183,0, - 0,2204,2205,5,153,0,0,2205,2206,5,183,0,0,2206,2208,3,250,125,0,2207, - 2203,1,0,0,0,2208,2211,1,0,0,0,2209,2207,1,0,0,0,2209,2210,1,0,0,0,2210, - 249,1,0,0,0,2211,2209,1,0,0,0,2212,2219,3,252,126,0,2213,2214,5,183,0, - 0,2214,2215,5,50,0,0,2215,2216,5,183,0,0,2216,2218,3,252,126,0,2217,2213, - 1,0,0,0,2218,2221,1,0,0,0,2219,2217,1,0,0,0,2219,2220,1,0,0,0,2220,251, - 1,0,0,0,2221,2219,1,0,0,0,2222,2224,5,113,0,0,2223,2225,5,183,0,0,2224, - 2223,1,0,0,0,2224,2225,1,0,0,0,2225,2227,1,0,0,0,2226,2222,1,0,0,0,2227, - 2230,1,0,0,0,2228,2226,1,0,0,0,2228,2229,1,0,0,0,2229,2231,1,0,0,0,2230, - 2228,1,0,0,0,2231,2232,3,254,127,0,2232,253,1,0,0,0,2233,2243,3,258,129, - 0,2234,2236,5,183,0,0,2235,2234,1,0,0,0,2235,2236,1,0,0,0,2236,2237,1, - 0,0,0,2237,2239,3,256,128,0,2238,2240,5,183,0,0,2239,2238,1,0,0,0,2239, - 2240,1,0,0,0,2240,2241,1,0,0,0,2241,2242,3,258,129,0,2242,2244,1,0,0, - 0,2243,2235,1,0,0,0,2243,2244,1,0,0,0,2244,2282,1,0,0,0,2245,2247,3,258, - 129,0,2246,2248,5,183,0,0,2247,2246,1,0,0,0,2247,2248,1,0,0,0,2248,2249, - 1,0,0,0,2249,2251,5,163,0,0,2250,2252,5,183,0,0,2251,2250,1,0,0,0,2251, - 2252,1,0,0,0,2252,2253,1,0,0,0,2253,2254,3,258,129,0,2254,2255,1,0,0, - 0,2255,2256,6,127,-1,0,2256,2282,1,0,0,0,2257,2259,3,258,129,0,2258,2260, - 5,183,0,0,2259,2258,1,0,0,0,2259,2260,1,0,0,0,2260,2261,1,0,0,0,2261, - 2263,3,256,128,0,2262,2264,5,183,0,0,2263,2262,1,0,0,0,2263,2264,1,0, - 0,0,2264,2265,1,0,0,0,2265,2275,3,258,129,0,2266,2268,5,183,0,0,2267, - 2266,1,0,0,0,2267,2268,1,0,0,0,2268,2269,1,0,0,0,2269,2271,3,256,128, - 0,2270,2272,5,183,0,0,2271,2270,1,0,0,0,2271,2272,1,0,0,0,2272,2273,1, - 0,0,0,2273,2274,3,258,129,0,2274,2276,1,0,0,0,2275,2267,1,0,0,0,2276, - 2277,1,0,0,0,2277,2275,1,0,0,0,2277,2278,1,0,0,0,2278,2279,1,0,0,0,2279, - 2280,6,127,-1,0,2280,2282,1,0,0,0,2281,2233,1,0,0,0,2281,2245,1,0,0,0, - 2281,2257,1,0,0,0,2282,255,1,0,0,0,2283,2284,7,2,0,0,2284,257,1,0,0,0, - 2285,2296,3,260,130,0,2286,2288,5,183,0,0,2287,2286,1,0,0,0,2287,2288, - 1,0,0,0,2288,2289,1,0,0,0,2289,2291,5,11,0,0,2290,2292,5,183,0,0,2291, - 2290,1,0,0,0,2291,2292,1,0,0,0,2292,2293,1,0,0,0,2293,2295,3,260,130, - 0,2294,2287,1,0,0,0,2295,2298,1,0,0,0,2296,2294,1,0,0,0,2296,2297,1,0, - 0,0,2297,259,1,0,0,0,2298,2296,1,0,0,0,2299,2310,3,262,131,0,2300,2302, - 5,183,0,0,2301,2300,1,0,0,0,2301,2302,1,0,0,0,2302,2303,1,0,0,0,2303, - 2305,5,17,0,0,2304,2306,5,183,0,0,2305,2304,1,0,0,0,2305,2306,1,0,0,0, - 2306,2307,1,0,0,0,2307,2309,3,262,131,0,2308,2301,1,0,0,0,2309,2312,1, - 0,0,0,2310,2308,1,0,0,0,2310,2311,1,0,0,0,2311,261,1,0,0,0,2312,2310, - 1,0,0,0,2313,2325,3,266,133,0,2314,2316,5,183,0,0,2315,2314,1,0,0,0,2315, - 2316,1,0,0,0,2316,2317,1,0,0,0,2317,2319,3,264,132,0,2318,2320,5,183, - 0,0,2319,2318,1,0,0,0,2319,2320,1,0,0,0,2320,2321,1,0,0,0,2321,2322,3, - 266,133,0,2322,2324,1,0,0,0,2323,2315,1,0,0,0,2324,2327,1,0,0,0,2325, - 2323,1,0,0,0,2325,2326,1,0,0,0,2326,263,1,0,0,0,2327,2325,1,0,0,0,2328, - 2329,7,3,0,0,2329,265,1,0,0,0,2330,2342,3,270,135,0,2331,2333,5,183,0, - 0,2332,2331,1,0,0,0,2332,2333,1,0,0,0,2333,2334,1,0,0,0,2334,2336,3,268, - 134,0,2335,2337,5,183,0,0,2336,2335,1,0,0,0,2336,2337,1,0,0,0,2337,2338, - 1,0,0,0,2338,2339,3,270,135,0,2339,2341,1,0,0,0,2340,2332,1,0,0,0,2341, - 2344,1,0,0,0,2342,2340,1,0,0,0,2342,2343,1,0,0,0,2343,267,1,0,0,0,2344, - 2342,1,0,0,0,2345,2346,7,4,0,0,2346,269,1,0,0,0,2347,2359,3,274,137,0, - 2348,2350,5,183,0,0,2349,2348,1,0,0,0,2349,2350,1,0,0,0,2350,2351,1,0, - 0,0,2351,2353,3,272,136,0,2352,2354,5,183,0,0,2353,2352,1,0,0,0,2353, - 2354,1,0,0,0,2354,2355,1,0,0,0,2355,2356,3,274,137,0,2356,2358,1,0,0, - 0,2357,2349,1,0,0,0,2358,2361,1,0,0,0,2359,2357,1,0,0,0,2359,2360,1,0, - 0,0,2360,271,1,0,0,0,2361,2359,1,0,0,0,2362,2363,7,5,0,0,2363,273,1,0, - 0,0,2364,2375,3,276,138,0,2365,2367,5,183,0,0,2366,2365,1,0,0,0,2366, + 0,0,2179,2180,1,0,0,0,2180,2181,5,10,0,0,2181,235,1,0,0,0,2182,2183,3, + 244,122,0,2183,237,1,0,0,0,2184,2185,3,244,122,0,2185,239,1,0,0,0,2186, + 2187,3,346,173,0,2187,241,1,0,0,0,2188,2189,3,346,173,0,2189,243,1,0, + 0,0,2190,2191,3,246,123,0,2191,245,1,0,0,0,2192,2199,3,248,124,0,2193, + 2194,5,183,0,0,2194,2195,5,119,0,0,2195,2196,5,183,0,0,2196,2198,3,248, + 124,0,2197,2193,1,0,0,0,2198,2201,1,0,0,0,2199,2197,1,0,0,0,2199,2200, + 1,0,0,0,2200,247,1,0,0,0,2201,2199,1,0,0,0,2202,2209,3,250,125,0,2203, + 2204,5,183,0,0,2204,2205,5,153,0,0,2205,2206,5,183,0,0,2206,2208,3,250, + 125,0,2207,2203,1,0,0,0,2208,2211,1,0,0,0,2209,2207,1,0,0,0,2209,2210, + 1,0,0,0,2210,249,1,0,0,0,2211,2209,1,0,0,0,2212,2219,3,252,126,0,2213, + 2214,5,183,0,0,2214,2215,5,50,0,0,2215,2216,5,183,0,0,2216,2218,3,252, + 126,0,2217,2213,1,0,0,0,2218,2221,1,0,0,0,2219,2217,1,0,0,0,2219,2220, + 1,0,0,0,2220,251,1,0,0,0,2221,2219,1,0,0,0,2222,2224,5,113,0,0,2223,2225, + 5,183,0,0,2224,2223,1,0,0,0,2224,2225,1,0,0,0,2225,2227,1,0,0,0,2226, + 2222,1,0,0,0,2227,2230,1,0,0,0,2228,2226,1,0,0,0,2228,2229,1,0,0,0,2229, + 2231,1,0,0,0,2230,2228,1,0,0,0,2231,2232,3,254,127,0,2232,253,1,0,0,0, + 2233,2243,3,258,129,0,2234,2236,5,183,0,0,2235,2234,1,0,0,0,2235,2236, + 1,0,0,0,2236,2237,1,0,0,0,2237,2239,3,256,128,0,2238,2240,5,183,0,0,2239, + 2238,1,0,0,0,2239,2240,1,0,0,0,2240,2241,1,0,0,0,2241,2242,3,258,129, + 0,2242,2244,1,0,0,0,2243,2235,1,0,0,0,2243,2244,1,0,0,0,2244,2282,1,0, + 0,0,2245,2247,3,258,129,0,2246,2248,5,183,0,0,2247,2246,1,0,0,0,2247, + 2248,1,0,0,0,2248,2249,1,0,0,0,2249,2251,5,163,0,0,2250,2252,5,183,0, + 0,2251,2250,1,0,0,0,2251,2252,1,0,0,0,2252,2253,1,0,0,0,2253,2254,3,258, + 129,0,2254,2255,1,0,0,0,2255,2256,6,127,-1,0,2256,2282,1,0,0,0,2257,2259, + 3,258,129,0,2258,2260,5,183,0,0,2259,2258,1,0,0,0,2259,2260,1,0,0,0,2260, + 2261,1,0,0,0,2261,2263,3,256,128,0,2262,2264,5,183,0,0,2263,2262,1,0, + 0,0,2263,2264,1,0,0,0,2264,2265,1,0,0,0,2265,2275,3,258,129,0,2266,2268, + 5,183,0,0,2267,2266,1,0,0,0,2267,2268,1,0,0,0,2268,2269,1,0,0,0,2269, + 2271,3,256,128,0,2270,2272,5,183,0,0,2271,2270,1,0,0,0,2271,2272,1,0, + 0,0,2272,2273,1,0,0,0,2273,2274,3,258,129,0,2274,2276,1,0,0,0,2275,2267, + 1,0,0,0,2276,2277,1,0,0,0,2277,2275,1,0,0,0,2277,2278,1,0,0,0,2278,2279, + 1,0,0,0,2279,2280,6,127,-1,0,2280,2282,1,0,0,0,2281,2233,1,0,0,0,2281, + 2245,1,0,0,0,2281,2257,1,0,0,0,2282,255,1,0,0,0,2283,2284,7,2,0,0,2284, + 257,1,0,0,0,2285,2296,3,260,130,0,2286,2288,5,183,0,0,2287,2286,1,0,0, + 0,2287,2288,1,0,0,0,2288,2289,1,0,0,0,2289,2291,5,11,0,0,2290,2292,5, + 183,0,0,2291,2290,1,0,0,0,2291,2292,1,0,0,0,2292,2293,1,0,0,0,2293,2295, + 3,260,130,0,2294,2287,1,0,0,0,2295,2298,1,0,0,0,2296,2294,1,0,0,0,2296, + 2297,1,0,0,0,2297,259,1,0,0,0,2298,2296,1,0,0,0,2299,2310,3,262,131,0, + 2300,2302,5,183,0,0,2301,2300,1,0,0,0,2301,2302,1,0,0,0,2302,2303,1,0, + 0,0,2303,2305,5,17,0,0,2304,2306,5,183,0,0,2305,2304,1,0,0,0,2305,2306, + 1,0,0,0,2306,2307,1,0,0,0,2307,2309,3,262,131,0,2308,2301,1,0,0,0,2309, + 2312,1,0,0,0,2310,2308,1,0,0,0,2310,2311,1,0,0,0,2311,261,1,0,0,0,2312, + 2310,1,0,0,0,2313,2325,3,266,133,0,2314,2316,5,183,0,0,2315,2314,1,0, + 0,0,2315,2316,1,0,0,0,2316,2317,1,0,0,0,2317,2319,3,264,132,0,2318,2320, + 5,183,0,0,2319,2318,1,0,0,0,2319,2320,1,0,0,0,2320,2321,1,0,0,0,2321, + 2322,3,266,133,0,2322,2324,1,0,0,0,2323,2315,1,0,0,0,2324,2327,1,0,0, + 0,2325,2323,1,0,0,0,2325,2326,1,0,0,0,2326,263,1,0,0,0,2327,2325,1,0, + 0,0,2328,2329,7,3,0,0,2329,265,1,0,0,0,2330,2342,3,270,135,0,2331,2333, + 5,183,0,0,2332,2331,1,0,0,0,2332,2333,1,0,0,0,2333,2334,1,0,0,0,2334, + 2336,3,268,134,0,2335,2337,5,183,0,0,2336,2335,1,0,0,0,2336,2337,1,0, + 0,0,2337,2338,1,0,0,0,2338,2339,3,270,135,0,2339,2341,1,0,0,0,2340,2332, + 1,0,0,0,2341,2344,1,0,0,0,2342,2340,1,0,0,0,2342,2343,1,0,0,0,2343,267, + 1,0,0,0,2344,2342,1,0,0,0,2345,2346,7,4,0,0,2346,269,1,0,0,0,2347,2359, + 3,274,137,0,2348,2350,5,183,0,0,2349,2348,1,0,0,0,2349,2350,1,0,0,0,2350, + 2351,1,0,0,0,2351,2353,3,272,136,0,2352,2354,5,183,0,0,2353,2352,1,0, + 0,0,2353,2354,1,0,0,0,2354,2355,1,0,0,0,2355,2356,3,274,137,0,2356,2358, + 1,0,0,0,2357,2349,1,0,0,0,2358,2361,1,0,0,0,2359,2357,1,0,0,0,2359,2360, + 1,0,0,0,2360,271,1,0,0,0,2361,2359,1,0,0,0,2362,2363,7,5,0,0,2363,273, + 1,0,0,0,2364,2375,3,276,138,0,2365,2367,5,183,0,0,2366,2365,1,0,0,0,2366, 2367,1,0,0,0,2367,2368,1,0,0,0,2368,2370,5,23,0,0,2369,2371,5,183,0,0, 2370,2369,1,0,0,0,2370,2371,1,0,0,0,2371,2372,1,0,0,0,2372,2374,3,276, 138,0,2373,2366,1,0,0,0,2374,2377,1,0,0,0,2375,2373,1,0,0,0,2375,2376, @@ -13202,8 +13202,8 @@ CypherParser::OC_UpperBoundContext* CypherParser::OC_RangeLiteralContext::oC_Upp return getRuleContext(0); } -CypherParser::OC_IntegerLiteralContext* CypherParser::OC_RangeLiteralContext::oC_IntegerLiteral() { - return getRuleContext(0); +CypherParser::OC_ExpressionContext* CypherParser::OC_RangeLiteralContext::oC_Expression() { + return getRuleContext(0); } @@ -13234,7 +13234,10 @@ CypherParser::OC_RangeLiteralContext* CypherParser::oC_RangeLiteral() { _errHandler->sync(this); _la = _input->LA(1); - if (_la == CypherParser::DecimalInteger) { + if ((((_la & ~ 0x3fULL) == 0) && + ((1ULL << _la) & -2320550076713270652) != 0) || ((((_la - 65) & ~ 0x3fULL) == 0) && + ((1ULL << (_la - 65)) & -286014905805559497) != 0) || ((((_la - 130) & ~ 0x3fULL) == 0) && + ((1ULL << (_la - 130)) & 5492410606132523) != 0)) { setState(2105); oC_LowerBound(); } @@ -13264,10 +13267,15 @@ CypherParser::OC_RangeLiteralContext* CypherParser::oC_RangeLiteral() { setState(2116); _errHandler->sync(this); - _la = _input->LA(1); - if (_la == CypherParser::DecimalInteger) { + switch (getInterpreter()->adaptivePredict(_input, 333, _ctx)) { + case 1: { setState(2115); oC_UpperBound(); + break; + } + + default: + break; } break; } @@ -13275,7 +13283,7 @@ CypherParser::OC_RangeLiteralContext* CypherParser::oC_RangeLiteral() { case 2: { enterOuterAlt(_localctx, 2); setState(2118); - oC_IntegerLiteral(); + oC_Expression(); break; } @@ -13581,8 +13589,8 @@ CypherParser::OC_LowerBoundContext::OC_LowerBoundContext(ParserRuleContext *pare : ParserRuleContext(parent, invokingState) { } -tree::TerminalNode* CypherParser::OC_LowerBoundContext::DecimalInteger() { - return getToken(CypherParser::DecimalInteger, 0); +CypherParser::OC_ExpressionContext* CypherParser::OC_LowerBoundContext::oC_Expression() { + return getRuleContext(0); } @@ -13605,7 +13613,7 @@ CypherParser::OC_LowerBoundContext* CypherParser::oC_LowerBound() { try { enterOuterAlt(_localctx, 1); setState(2182); - match(CypherParser::DecimalInteger); + oC_Expression(); } catch (RecognitionException &e) { @@ -13623,8 +13631,8 @@ CypherParser::OC_UpperBoundContext::OC_UpperBoundContext(ParserRuleContext *pare : ParserRuleContext(parent, invokingState) { } -tree::TerminalNode* CypherParser::OC_UpperBoundContext::DecimalInteger() { - return getToken(CypherParser::DecimalInteger, 0); +CypherParser::OC_ExpressionContext* CypherParser::OC_UpperBoundContext::oC_Expression() { + return getRuleContext(0); } @@ -13647,7 +13655,7 @@ CypherParser::OC_UpperBoundContext* CypherParser::oC_UpperBound() { try { enterOuterAlt(_localctx, 1); setState(2184); - match(CypherParser::DecimalInteger); + oC_Expression(); } catch (RecognitionException &e) { diff --git a/third_party/antlr4_cypher/include/cypher_parser.h b/third_party/antlr4_cypher/include/cypher_parser.h index 7cfd61bda7b..38232973454 100644 --- a/third_party/antlr4_cypher/include/cypher_parser.h +++ b/third_party/antlr4_cypher/include/cypher_parser.h @@ -2097,7 +2097,7 @@ class CypherParser : public antlr4::Parser { std::vector SP(); antlr4::tree::TerminalNode* SP(size_t i); OC_UpperBoundContext *oC_UpperBound(); - OC_IntegerLiteralContext *oC_IntegerLiteral(); + OC_ExpressionContext *oC_Expression(); }; @@ -2138,7 +2138,7 @@ class CypherParser : public antlr4::Parser { public: OC_LowerBoundContext(antlr4::ParserRuleContext *parent, size_t invokingState); virtual size_t getRuleIndex() const override; - antlr4::tree::TerminalNode *DecimalInteger(); + OC_ExpressionContext *oC_Expression(); }; @@ -2149,7 +2149,7 @@ class CypherParser : public antlr4::Parser { public: OC_UpperBoundContext(antlr4::ParserRuleContext *parent, size_t invokingState); virtual size_t getRuleIndex() const override; - antlr4::tree::TerminalNode *DecimalInteger(); + OC_ExpressionContext *oC_Expression(); }; From 904a47b272896343f1606a128936017718e3a63c Mon Sep 17 00:00:00 2001 From: CI Bot Date: Wed, 17 Sep 2025 20:33:54 +0000 Subject: [PATCH 2/4] ci: auto code format --- src/binder/bind/bind_graph_pattern.cpp | 6 ++---- src/parser/transform/transform_graph_pattern.cpp | 5 +++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/binder/bind/bind_graph_pattern.cpp b/src/binder/bind/bind_graph_pattern.cpp index 501b57b6de4..a3a732f66b8 100644 --- a/src/binder/bind/bind_graph_pattern.cpp +++ b/src/binder/bind/bind_graph_pattern.cpp @@ -529,8 +529,7 @@ std::pair Binder::bindVariableLengthRelBound(const RelPatter auto boundLowerExpression = expressionBinder.bindExpression(*recursiveInfo->lowerBound); if (boundLowerExpression->expressionType != ExpressionType::LITERAL && boundLowerExpression->expressionType != ExpressionType::PARAMETER) { - throw BinderException( - "Rel range lower bound must be a parameter/literal expression."); + throw BinderException("Rel range lower bound must be a parameter/literal expression."); } lowerBound = ExpressionUtil::evaluateAsVariableLengthRelBound(*boundLowerExpression); auto maxDepth = clientContext->getClientConfig()->varLengthMaxDepth; @@ -539,8 +538,7 @@ std::pair Binder::bindVariableLengthRelBound(const RelPatter auto boundUpperExpression = expressionBinder.bindExpression(*recursiveInfo->upperBound); if (boundUpperExpression->expressionType != ExpressionType::LITERAL && boundUpperExpression->expressionType != ExpressionType::PARAMETER) { - throw BinderException( - "Rel range upper bound must be a parameter/literal expression."); + throw BinderException("Rel range upper bound must be a parameter/literal expression."); } upperBound = ExpressionUtil::evaluateAsVariableLengthRelBound(*boundUpperExpression); } diff --git a/src/parser/transform/transform_graph_pattern.cpp b/src/parser/transform/transform_graph_pattern.cpp index 3164b1208f0..bcc026313c1 100644 --- a/src/parser/transform/transform_graph_pattern.cpp +++ b/src/parser/transform/transform_graph_pattern.cpp @@ -1,6 +1,6 @@ #include "common/assert.h" -#include "parser/query/graph_pattern/pattern_element.h" #include "parser/expression/parsed_literal_expression.h" +#include "parser/query/graph_pattern/pattern_element.h" #include "parser/transformer.h" using namespace kuzu::common; @@ -127,7 +127,8 @@ RelPattern Transformer::transformRelationshipPattern( relType = QueryRelType::VARIABLE_LENGTH_WALK; } // Parse lower, upper bound - std::unique_ptr lowerBound = std::make_unique(Value(1), "1"); + std::unique_ptr lowerBound = + std::make_unique(Value(1), "1"); std::unique_ptr upperBound = nullptr; auto range = recursiveDetail->oC_RangeLiteral(); if (range) { From 0dbb3336715f920f147e60fa3a01f84475ebc767 Mon Sep 17 00:00:00 2001 From: Bernie Chen Date: Wed, 17 Sep 2025 16:42:43 -0400 Subject: [PATCH 3/4] tidy: remove redundant include --- src/binder/bind/bind_graph_pattern.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/binder/bind/bind_graph_pattern.cpp b/src/binder/bind/bind_graph_pattern.cpp index a3a732f66b8..765282b8d72 100644 --- a/src/binder/bind/bind_graph_pattern.cpp +++ b/src/binder/bind/bind_graph_pattern.cpp @@ -10,7 +10,6 @@ #include "common/exception/binder.h" #include "common/string_format.h" #include "common/utils.h" -#include "function/cast/functions/cast_from_string_functions.h" #include "function/gds/rec_joins.h" #include "function/rewrite_function.h" #include "function/schema/vector_node_rel_functions.h" From f86f04449693c0ebbc56ae86a24a7fa15c1d053c Mon Sep 17 00:00:00 2001 From: Bernie Chen Date: Wed, 17 Sep 2025 17:21:58 -0400 Subject: [PATCH 4/4] fix test --- src/binder/expression/expression_util.cpp | 4 ++-- test/test_files/tck/match/match4.test | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/binder/expression/expression_util.cpp b/src/binder/expression/expression_util.cpp index d229546f327..55fbd57ecdc 100644 --- a/src/binder/expression/expression_util.cpp +++ b/src/binder/expression/expression_util.cpp @@ -479,11 +479,11 @@ uint64_t ExpressionUtil::evaluateAsVariableLengthRelBound(const Expression& expr value.getDataType(), [&](T) { if (value.getValue() < 0) { - throw RuntimeException{errorMsg}; + throw BinderException{errorMsg}; } number = (uint64_t)value.getValue(); }, - [&](auto) { throw RuntimeException{errorMsg}; }); + [&](auto) { throw BinderException{errorMsg}; }); return number; } diff --git a/test/test_files/tck/match/match4.test b/test/test_files/tck/match/match4.test index ffe164addcc..aa33ed331b6 100644 --- a/test/test_files/tck/match/match4.test +++ b/test/test_files/tck/match/match4.test @@ -215,6 +215,5 @@ Parser exception: Invalid input : ex MATCH (a)-[:LIKES*-2]->(c) RETURN c.name; ---- error -Parser exception: Invalid input : expected rule oC_SingleQuery (line: 1, offset: 40) -"MATCH (a:A) MATCH (a)-[:LIKES*-2]->(c) RETURN c.name;" - ^ +Binder exception: Rel range upper/lower bound must be a non-negative integer. +