瀏覽代碼

Add support for parameters in LIMIT command (#128464) (#128655)

Luigi Dell'Aquila 4 月之前
父節點
當前提交
f484c9feff

+ 5 - 0
docs/changelog/128464.yaml

@@ -0,0 +1,5 @@
+pr: 128464
+summary: Add support for parameters in LIMIT command
+area: ES|QL
+type: enhancement
+issues: []

+ 1 - 1
x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.g4

@@ -244,7 +244,7 @@ identifierOrParameter
     ;
 
 limitCommand
-    : LIMIT INTEGER_LITERAL
+    : LIMIT constant
     ;
 
 sortCommand

+ 6 - 1
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

@@ -893,7 +893,12 @@ public class EsqlCapabilities {
         /**
          * Guards a bug fix matching {@code TO_LOWER(f) == ""}.
          */
-        TO_LOWER_EMPTY_STRING;
+        TO_LOWER_EMPTY_STRING,
+
+        /**
+         * Support parameters for LiMIT command.
+         */
+        PARAMETER_FOR_LIMIT;
 
         private final boolean enabled;
 

文件差異過大導致無法顯示
+ 0 - 0
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser.interp


+ 91 - 89
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser.java

@@ -4275,7 +4275,9 @@ public class EsqlBaseParser extends ParserConfig {
   @SuppressWarnings("CheckReturnValue")
   public static class LimitCommandContext extends ParserRuleContext {
     public TerminalNode LIMIT() { return getToken(EsqlBaseParser.LIMIT, 0); }
-    public TerminalNode INTEGER_LITERAL() { return getToken(EsqlBaseParser.INTEGER_LITERAL, 0); }
+    public ConstantContext constant() {
+      return getRuleContext(ConstantContext.class,0);
+    }
     @SuppressWarnings("this-escape")
     public LimitCommandContext(ParserRuleContext parent, int invokingState) {
       super(parent, invokingState);
@@ -4305,7 +4307,7 @@ public class EsqlBaseParser extends ParserConfig {
       setState(527);
       match(LIMIT);
       setState(528);
-      match(INTEGER_LITERAL);
+      constant();
       }
     }
     catch (RecognitionException re) {
@@ -6555,93 +6557,93 @@ public class EsqlBaseParser extends ParserConfig {
     "\u0000\u0000\u020a\u020e\u0003F#\u0000\u020b\u020e\u0003L&\u0000\u020c"+
     "\u020e\u0003N\'\u0000\u020d\u020a\u0001\u0000\u0000\u0000\u020d\u020b"+
     "\u0001\u0000\u0000\u0000\u020d\u020c\u0001\u0000\u0000\u0000\u020eQ\u0001"+
-    "\u0000\u0000\u0000\u020f\u0210\u0005\t\u0000\u0000\u0210\u0211\u0005\u001f"+
-    "\u0000\u0000\u0211S\u0001\u0000\u0000\u0000\u0212\u0213\u0005\u000e\u0000"+
-    "\u0000\u0213\u0218\u0003V+\u0000\u0214\u0215\u0005\'\u0000\u0000\u0215"+
-    "\u0217\u0003V+\u0000\u0216\u0214\u0001\u0000\u0000\u0000\u0217\u021a\u0001"+
-    "\u0000\u0000\u0000\u0218\u0216\u0001\u0000\u0000\u0000\u0218\u0219\u0001"+
-    "\u0000\u0000\u0000\u0219U\u0001\u0000\u0000\u0000\u021a\u0218\u0001\u0000"+
-    "\u0000\u0000\u021b\u021d\u0003\n\u0005\u0000\u021c\u021e\u0007\u0004\u0000"+
-    "\u0000\u021d\u021c\u0001\u0000\u0000\u0000\u021d\u021e\u0001\u0000\u0000"+
-    "\u0000\u021e\u0221\u0001\u0000\u0000\u0000\u021f\u0220\u00053\u0000\u0000"+
-    "\u0220\u0222\u0007\u0005\u0000\u0000\u0221\u021f\u0001\u0000\u0000\u0000"+
-    "\u0221\u0222\u0001\u0000\u0000\u0000\u0222W\u0001\u0000\u0000\u0000\u0223"+
-    "\u0224\u0005\b\u0000\u0000\u0224\u0225\u0003D\"\u0000\u0225Y\u0001\u0000"+
-    "\u0000\u0000\u0226\u0227\u0005\u0002\u0000\u0000\u0227\u0228\u0003D\""+
-    "\u0000\u0228[\u0001\u0000\u0000\u0000\u0229\u022a\u0005\u000b\u0000\u0000"+
-    "\u022a\u022f\u0003^/\u0000\u022b\u022c\u0005\'\u0000\u0000\u022c\u022e"+
-    "\u0003^/\u0000\u022d\u022b\u0001\u0000\u0000\u0000\u022e\u0231\u0001\u0000"+
-    "\u0000\u0000\u022f\u022d\u0001\u0000\u0000\u0000\u022f\u0230\u0001\u0000"+
-    "\u0000\u0000\u0230]\u0001\u0000\u0000\u0000\u0231\u022f\u0001\u0000\u0000"+
-    "\u0000\u0232\u0233\u0003B!\u0000\u0233\u0234\u0005]\u0000\u0000\u0234"+
-    "\u0235\u0003B!\u0000\u0235_\u0001\u0000\u0000\u0000\u0236\u0237\u0005"+
-    "\u0001\u0000\u0000\u0237\u0238\u0003\u0014\n\u0000\u0238\u023a\u0003r"+
-    "9\u0000\u0239\u023b\u0003f3\u0000\u023a\u0239\u0001\u0000\u0000\u0000"+
-    "\u023a\u023b\u0001\u0000\u0000\u0000\u023ba\u0001\u0000\u0000\u0000\u023c"+
-    "\u023d\u0005\u0007\u0000\u0000\u023d\u023e\u0003\u0014\n\u0000\u023e\u023f"+
-    "\u0003r9\u0000\u023fc\u0001\u0000\u0000\u0000\u0240\u0241\u0005\n\u0000"+
-    "\u0000\u0241\u0242\u0003@ \u0000\u0242e\u0001\u0000\u0000\u0000\u0243"+
-    "\u0248\u0003h4\u0000\u0244\u0245\u0005\'\u0000\u0000\u0245\u0247\u0003"+
-    "h4\u0000\u0246\u0244\u0001\u0000\u0000\u0000\u0247\u024a\u0001\u0000\u0000"+
-    "\u0000\u0248\u0246\u0001\u0000\u0000\u0000\u0248\u0249\u0001\u0000\u0000"+
-    "\u0000\u0249g\u0001\u0000\u0000\u0000\u024a\u0248\u0001\u0000\u0000\u0000"+
-    "\u024b\u024c\u0003F#\u0000\u024c\u024d\u0005$\u0000\u0000\u024d\u024e"+
-    "\u0003J%\u0000\u024ei\u0001\u0000\u0000\u0000\u024f\u0250\u0007\u0006"+
-    "\u0000\u0000\u0250k\u0001\u0000\u0000\u0000\u0251\u0254\u0003n7\u0000"+
-    "\u0252\u0254\u0003p8\u0000\u0253\u0251\u0001\u0000\u0000\u0000\u0253\u0252"+
-    "\u0001\u0000\u0000\u0000\u0254m\u0001\u0000\u0000\u0000\u0255\u0257\u0007"+
-    "\u0000\u0000\u0000\u0256\u0255\u0001\u0000\u0000\u0000\u0256\u0257\u0001"+
-    "\u0000\u0000\u0000\u0257\u0258\u0001\u0000\u0000\u0000\u0258\u0259\u0005"+
-    " \u0000\u0000\u0259o\u0001\u0000\u0000\u0000\u025a\u025c\u0007\u0000\u0000"+
-    "\u0000\u025b\u025a\u0001\u0000\u0000\u0000\u025b\u025c\u0001\u0000\u0000"+
-    "\u0000\u025c\u025d\u0001\u0000\u0000\u0000\u025d\u025e\u0005\u001f\u0000"+
-    "\u0000\u025eq\u0001\u0000\u0000\u0000\u025f\u0260\u0005\u001e\u0000\u0000"+
-    "\u0260s\u0001\u0000\u0000\u0000\u0261\u0262\u0007\u0007\u0000\u0000\u0262"+
-    "u\u0001\u0000\u0000\u0000\u0263\u0264\u0005\u0005\u0000\u0000\u0264\u0265"+
-    "\u0003x<\u0000\u0265w\u0001\u0000\u0000\u0000\u0266\u0267\u0005J\u0000"+
-    "\u0000\u0267\u0268\u0003\u0002\u0001\u0000\u0268\u0269\u0005K\u0000\u0000"+
-    "\u0269y\u0001\u0000\u0000\u0000\u026a\u026b\u0005\r\u0000\u0000\u026b"+
-    "\u026c\u0005m\u0000\u0000\u026c{\u0001\u0000\u0000\u0000\u026d\u026e\u0005"+
-    "\u0003\u0000\u0000\u026e\u0271\u0005c\u0000\u0000\u026f\u0270\u0005a\u0000"+
-    "\u0000\u0270\u0272\u0003B!\u0000\u0271\u026f\u0001\u0000\u0000\u0000\u0271"+
-    "\u0272\u0001\u0000\u0000\u0000\u0272\u027c\u0001\u0000\u0000\u0000\u0273"+
-    "\u0274\u0005b\u0000\u0000\u0274\u0279\u0003~?\u0000\u0275\u0276\u0005"+
-    "\'\u0000\u0000\u0276\u0278\u0003~?\u0000\u0277\u0275\u0001\u0000\u0000"+
-    "\u0000\u0278\u027b\u0001\u0000\u0000\u0000\u0279\u0277\u0001\u0000\u0000"+
-    "\u0000\u0279\u027a\u0001\u0000\u0000\u0000\u027a\u027d\u0001\u0000\u0000"+
-    "\u0000\u027b\u0279\u0001\u0000\u0000\u0000\u027c\u0273\u0001\u0000\u0000"+
-    "\u0000\u027c\u027d\u0001\u0000\u0000\u0000\u027d}\u0001\u0000\u0000\u0000"+
-    "\u027e\u027f\u0003B!\u0000\u027f\u0280\u0005$\u0000\u0000\u0280\u0282"+
-    "\u0001\u0000\u0000\u0000\u0281\u027e\u0001\u0000\u0000\u0000\u0281\u0282"+
-    "\u0001\u0000\u0000\u0000\u0282\u0283\u0001\u0000\u0000\u0000\u0283\u0284"+
-    "\u0003B!\u0000\u0284\u007f\u0001\u0000\u0000\u0000\u0285\u0286\u0005\u0012"+
-    "\u0000\u0000\u0286\u0289\u0003@ \u0000\u0287\u0288\u0005a\u0000\u0000"+
-    "\u0288\u028a\u0003@ \u0000\u0289\u0287\u0001\u0000\u0000\u0000\u0289\u028a"+
-    "\u0001\u0000\u0000\u0000\u028a\u0290\u0001\u0000\u0000\u0000\u028b\u028c"+
-    "\u0005]\u0000\u0000\u028c\u028d\u0003@ \u0000\u028d\u028e\u0005\'\u0000"+
-    "\u0000\u028e\u028f\u0003@ \u0000\u028f\u0291\u0001\u0000\u0000\u0000\u0290"+
-    "\u028b\u0001\u0000\u0000\u0000\u0290\u0291\u0001\u0000\u0000\u0000\u0291"+
-    "\u0081\u0001\u0000\u0000\u0000\u0292\u0293\u0005\u0014\u0000\u0000\u0293"+
-    "\u0294\u0003(\u0014\u0000\u0294\u0295\u0005a\u0000\u0000\u0295\u0296\u0003"+
-    "D\"\u0000\u0296\u0083\u0001\u0000\u0000\u0000\u0297\u0298\u0005\u0013"+
-    "\u0000\u0000\u0298\u029b\u0003<\u001e\u0000\u0299\u029a\u0005!\u0000\u0000"+
-    "\u029a\u029c\u0003\"\u0011\u0000\u029b\u0299\u0001\u0000\u0000\u0000\u029b"+
-    "\u029c\u0001\u0000\u0000\u0000\u029c\u0085\u0001\u0000\u0000\u0000\u029d"+
-    "\u029e\u0007\b\u0000\u0000\u029e\u029f\u0005{\u0000\u0000\u029f\u02a0"+
-    "\u0003\u0088D\u0000\u02a0\u02a1\u0003\u008aE\u0000\u02a1\u0087\u0001\u0000"+
-    "\u0000\u0000\u02a2\u02a3\u0003(\u0014\u0000\u02a3\u0089\u0001\u0000\u0000"+
-    "\u0000\u02a4\u02a5\u0005a\u0000\u0000\u02a5\u02aa\u0003\u008cF\u0000\u02a6"+
-    "\u02a7\u0005\'\u0000\u0000\u02a7\u02a9\u0003\u008cF\u0000\u02a8\u02a6"+
-    "\u0001\u0000\u0000\u0000\u02a9\u02ac\u0001\u0000\u0000\u0000\u02aa\u02a8"+
-    "\u0001\u0000\u0000\u0000\u02aa\u02ab\u0001\u0000\u0000\u0000\u02ab\u008b"+
-    "\u0001\u0000\u0000\u0000\u02ac\u02aa\u0001\u0000\u0000\u0000\u02ad\u02ae"+
-    "\u0003\u0010\b\u0000\u02ae\u008d\u0001\u0000\u0000\u0000C\u0099\u00a2"+
-    "\u00b6\u00c2\u00cb\u00d3\u00d8\u00e0\u00e2\u00e7\u00ee\u00f3\u00f8\u0102"+
-    "\u0108\u0110\u0112\u011d\u0124\u012f\u0134\u0136\u0142\u0155\u015b\u0165"+
-    "\u0169\u016e\u0174\u0176\u0180\u0188\u0195\u0199\u019d\u01a4\u01a8\u01af"+
-    "\u01b5\u01bc\u01c4\u01cc\u01d4\u01e5\u01f0\u01fb\u0200\u0204\u0208\u020d"+
-    "\u0218\u021d\u0221\u022f\u023a\u0248\u0253\u0256\u025b\u0271\u0279\u027c"+
-    "\u0281\u0289\u0290\u029b\u02aa";
+    "\u0000\u0000\u0000\u020f\u0210\u0005\t\u0000\u0000\u0210\u0211\u0003J"+
+    "%\u0000\u0211S\u0001\u0000\u0000\u0000\u0212\u0213\u0005\u000e\u0000\u0000"+
+    "\u0213\u0218\u0003V+\u0000\u0214\u0215\u0005\'\u0000\u0000\u0215\u0217"+
+    "\u0003V+\u0000\u0216\u0214\u0001\u0000\u0000\u0000\u0217\u021a\u0001\u0000"+
+    "\u0000\u0000\u0218\u0216\u0001\u0000\u0000\u0000\u0218\u0219\u0001\u0000"+
+    "\u0000\u0000\u0219U\u0001\u0000\u0000\u0000\u021a\u0218\u0001\u0000\u0000"+
+    "\u0000\u021b\u021d\u0003\n\u0005\u0000\u021c\u021e\u0007\u0004\u0000\u0000"+
+    "\u021d\u021c\u0001\u0000\u0000\u0000\u021d\u021e\u0001\u0000\u0000\u0000"+
+    "\u021e\u0221\u0001\u0000\u0000\u0000\u021f\u0220\u00053\u0000\u0000\u0220"+
+    "\u0222\u0007\u0005\u0000\u0000\u0221\u021f\u0001\u0000\u0000\u0000\u0221"+
+    "\u0222\u0001\u0000\u0000\u0000\u0222W\u0001\u0000\u0000\u0000\u0223\u0224"+
+    "\u0005\b\u0000\u0000\u0224\u0225\u0003D\"\u0000\u0225Y\u0001\u0000\u0000"+
+    "\u0000\u0226\u0227\u0005\u0002\u0000\u0000\u0227\u0228\u0003D\"\u0000"+
+    "\u0228[\u0001\u0000\u0000\u0000\u0229\u022a\u0005\u000b\u0000\u0000\u022a"+
+    "\u022f\u0003^/\u0000\u022b\u022c\u0005\'\u0000\u0000\u022c\u022e\u0003"+
+    "^/\u0000\u022d\u022b\u0001\u0000\u0000\u0000\u022e\u0231\u0001\u0000\u0000"+
+    "\u0000\u022f\u022d\u0001\u0000\u0000\u0000\u022f\u0230\u0001\u0000\u0000"+
+    "\u0000\u0230]\u0001\u0000\u0000\u0000\u0231\u022f\u0001\u0000\u0000\u0000"+
+    "\u0232\u0233\u0003B!\u0000\u0233\u0234\u0005]\u0000\u0000\u0234\u0235"+
+    "\u0003B!\u0000\u0235_\u0001\u0000\u0000\u0000\u0236\u0237\u0005\u0001"+
+    "\u0000\u0000\u0237\u0238\u0003\u0014\n\u0000\u0238\u023a\u0003r9\u0000"+
+    "\u0239\u023b\u0003f3\u0000\u023a\u0239\u0001\u0000\u0000\u0000\u023a\u023b"+
+    "\u0001\u0000\u0000\u0000\u023ba\u0001\u0000\u0000\u0000\u023c\u023d\u0005"+
+    "\u0007\u0000\u0000\u023d\u023e\u0003\u0014\n\u0000\u023e\u023f\u0003r"+
+    "9\u0000\u023fc\u0001\u0000\u0000\u0000\u0240\u0241\u0005\n\u0000\u0000"+
+    "\u0241\u0242\u0003@ \u0000\u0242e\u0001\u0000\u0000\u0000\u0243\u0248"+
+    "\u0003h4\u0000\u0244\u0245\u0005\'\u0000\u0000\u0245\u0247\u0003h4\u0000"+
+    "\u0246\u0244\u0001\u0000\u0000\u0000\u0247\u024a\u0001\u0000\u0000\u0000"+
+    "\u0248\u0246\u0001\u0000\u0000\u0000\u0248\u0249\u0001\u0000\u0000\u0000"+
+    "\u0249g\u0001\u0000\u0000\u0000\u024a\u0248\u0001\u0000\u0000\u0000\u024b"+
+    "\u024c\u0003F#\u0000\u024c\u024d\u0005$\u0000\u0000\u024d\u024e\u0003"+
+    "J%\u0000\u024ei\u0001\u0000\u0000\u0000\u024f\u0250\u0007\u0006\u0000"+
+    "\u0000\u0250k\u0001\u0000\u0000\u0000\u0251\u0254\u0003n7\u0000\u0252"+
+    "\u0254\u0003p8\u0000\u0253\u0251\u0001\u0000\u0000\u0000\u0253\u0252\u0001"+
+    "\u0000\u0000\u0000\u0254m\u0001\u0000\u0000\u0000\u0255\u0257\u0007\u0000"+
+    "\u0000\u0000\u0256\u0255\u0001\u0000\u0000\u0000\u0256\u0257\u0001\u0000"+
+    "\u0000\u0000\u0257\u0258\u0001\u0000\u0000\u0000\u0258\u0259\u0005 \u0000"+
+    "\u0000\u0259o\u0001\u0000\u0000\u0000\u025a\u025c\u0007\u0000\u0000\u0000"+
+    "\u025b\u025a\u0001\u0000\u0000\u0000\u025b\u025c\u0001\u0000\u0000\u0000"+
+    "\u025c\u025d\u0001\u0000\u0000\u0000\u025d\u025e\u0005\u001f\u0000\u0000"+
+    "\u025eq\u0001\u0000\u0000\u0000\u025f\u0260\u0005\u001e\u0000\u0000\u0260"+
+    "s\u0001\u0000\u0000\u0000\u0261\u0262\u0007\u0007\u0000\u0000\u0262u\u0001"+
+    "\u0000\u0000\u0000\u0263\u0264\u0005\u0005\u0000\u0000\u0264\u0265\u0003"+
+    "x<\u0000\u0265w\u0001\u0000\u0000\u0000\u0266\u0267\u0005J\u0000\u0000"+
+    "\u0267\u0268\u0003\u0002\u0001\u0000\u0268\u0269\u0005K\u0000\u0000\u0269"+
+    "y\u0001\u0000\u0000\u0000\u026a\u026b\u0005\r\u0000\u0000\u026b\u026c"+
+    "\u0005m\u0000\u0000\u026c{\u0001\u0000\u0000\u0000\u026d\u026e\u0005\u0003"+
+    "\u0000\u0000\u026e\u0271\u0005c\u0000\u0000\u026f\u0270\u0005a\u0000\u0000"+
+    "\u0270\u0272\u0003B!\u0000\u0271\u026f\u0001\u0000\u0000\u0000\u0271\u0272"+
+    "\u0001\u0000\u0000\u0000\u0272\u027c\u0001\u0000\u0000\u0000\u0273\u0274"+
+    "\u0005b\u0000\u0000\u0274\u0279\u0003~?\u0000\u0275\u0276\u0005\'\u0000"+
+    "\u0000\u0276\u0278\u0003~?\u0000\u0277\u0275\u0001\u0000\u0000\u0000\u0278"+
+    "\u027b\u0001\u0000\u0000\u0000\u0279\u0277\u0001\u0000\u0000\u0000\u0279"+
+    "\u027a\u0001\u0000\u0000\u0000\u027a\u027d\u0001\u0000\u0000\u0000\u027b"+
+    "\u0279\u0001\u0000\u0000\u0000\u027c\u0273\u0001\u0000\u0000\u0000\u027c"+
+    "\u027d\u0001\u0000\u0000\u0000\u027d}\u0001\u0000\u0000\u0000\u027e\u027f"+
+    "\u0003B!\u0000\u027f\u0280\u0005$\u0000\u0000\u0280\u0282\u0001\u0000"+
+    "\u0000\u0000\u0281\u027e\u0001\u0000\u0000\u0000\u0281\u0282\u0001\u0000"+
+    "\u0000\u0000\u0282\u0283\u0001\u0000\u0000\u0000\u0283\u0284\u0003B!\u0000"+
+    "\u0284\u007f\u0001\u0000\u0000\u0000\u0285\u0286\u0005\u0012\u0000\u0000"+
+    "\u0286\u0289\u0003@ \u0000\u0287\u0288\u0005a\u0000\u0000\u0288\u028a"+
+    "\u0003@ \u0000\u0289\u0287\u0001\u0000\u0000\u0000\u0289\u028a\u0001\u0000"+
+    "\u0000\u0000\u028a\u0290\u0001\u0000\u0000\u0000\u028b\u028c\u0005]\u0000"+
+    "\u0000\u028c\u028d\u0003@ \u0000\u028d\u028e\u0005\'\u0000\u0000\u028e"+
+    "\u028f\u0003@ \u0000\u028f\u0291\u0001\u0000\u0000\u0000\u0290\u028b\u0001"+
+    "\u0000\u0000\u0000\u0290\u0291\u0001\u0000\u0000\u0000\u0291\u0081\u0001"+
+    "\u0000\u0000\u0000\u0292\u0293\u0005\u0014\u0000\u0000\u0293\u0294\u0003"+
+    "(\u0014\u0000\u0294\u0295\u0005a\u0000\u0000\u0295\u0296\u0003D\"\u0000"+
+    "\u0296\u0083\u0001\u0000\u0000\u0000\u0297\u0298\u0005\u0013\u0000\u0000"+
+    "\u0298\u029b\u0003<\u001e\u0000\u0299\u029a\u0005!\u0000\u0000\u029a\u029c"+
+    "\u0003\"\u0011\u0000\u029b\u0299\u0001\u0000\u0000\u0000\u029b\u029c\u0001"+
+    "\u0000\u0000\u0000\u029c\u0085\u0001\u0000\u0000\u0000\u029d\u029e\u0007"+
+    "\b\u0000\u0000\u029e\u029f\u0005{\u0000\u0000\u029f\u02a0\u0003\u0088"+
+    "D\u0000\u02a0\u02a1\u0003\u008aE\u0000\u02a1\u0087\u0001\u0000\u0000\u0000"+
+    "\u02a2\u02a3\u0003(\u0014\u0000\u02a3\u0089\u0001\u0000\u0000\u0000\u02a4"+
+    "\u02a5\u0005a\u0000\u0000\u02a5\u02aa\u0003\u008cF\u0000\u02a6\u02a7\u0005"+
+    "\'\u0000\u0000\u02a7\u02a9\u0003\u008cF\u0000\u02a8\u02a6\u0001\u0000"+
+    "\u0000\u0000\u02a9\u02ac\u0001\u0000\u0000\u0000\u02aa\u02a8\u0001\u0000"+
+    "\u0000\u0000\u02aa\u02ab\u0001\u0000\u0000\u0000\u02ab\u008b\u0001\u0000"+
+    "\u0000\u0000\u02ac\u02aa\u0001\u0000\u0000\u0000\u02ad\u02ae\u0003\u0010"+
+    "\b\u0000\u02ae\u008d\u0001\u0000\u0000\u0000C\u0099\u00a2\u00b6\u00c2"+
+    "\u00cb\u00d3\u00d8\u00e0\u00e2\u00e7\u00ee\u00f3\u00f8\u0102\u0108\u0110"+
+    "\u0112\u011d\u0124\u012f\u0134\u0136\u0142\u0155\u015b\u0165\u0169\u016e"+
+    "\u0174\u0176\u0180\u0188\u0195\u0199\u019d\u01a4\u01a8\u01af\u01b5\u01bc"+
+    "\u01c4\u01cc\u01d4\u01e5\u01f0\u01fb\u0200\u0204\u0208\u020d\u0218\u021d"+
+    "\u0221\u022f\u023a\u0248\u0253\u0256\u025b\u0271\u0279\u027c\u0281\u0289"+
+    "\u0290\u029b\u02aa";
   public static final ATN _ATN =
     new ATNDeserializer().deserialize(_serializedATN.toCharArray());
   static {

+ 12 - 4
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/LogicalPlanBuilder.java

@@ -85,12 +85,10 @@ import static org.elasticsearch.xpack.esql.parser.ParserUtils.source;
 import static org.elasticsearch.xpack.esql.parser.ParserUtils.typedParsing;
 import static org.elasticsearch.xpack.esql.parser.ParserUtils.visitList;
 import static org.elasticsearch.xpack.esql.plan.logical.Enrich.Mode;
-import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.stringToInt;
 
 /**
  * Translates what we get back from Antlr into the data structures the rest of the planner steps will act on.  Generally speaking, things
  * which change the grammar will need to make changes here as well.
- *
  */
 public class LogicalPlanBuilder extends ExpressionBuilder {
 
@@ -372,8 +370,18 @@ public class LogicalPlanBuilder extends ExpressionBuilder {
     @Override
     public PlanFactory visitLimitCommand(EsqlBaseParser.LimitCommandContext ctx) {
         Source source = source(ctx);
-        int limit = stringToInt(ctx.INTEGER_LITERAL().getText());
-        return input -> new Limit(source, new Literal(source, limit, DataType.INTEGER), input);
+        Object val = expression(ctx.constant()).fold(FoldContext.small() /* TODO remove me */);
+        if (val instanceof Integer i) {
+            if (i < 0) {
+                throw new ParsingException(source, "Invalid value for LIMIT [" + val + "], expecting a non negative integer");
+            }
+            return input -> new Limit(source, new Literal(source, i, DataType.INTEGER), input);
+        } else {
+            throw new ParsingException(
+                source,
+                "Invalid value for LIMIT [" + val + ": " + val.getClass().getSimpleName() + "], expecting a non negative integer"
+            );
+        }
     }
 
     @Override

+ 6 - 0
x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/ParsingTests.java

@@ -161,6 +161,12 @@ public class ParsingTests extends ESTestCase {
         throw new IllegalArgumentException("can't find name for " + functionCall);
     }
 
+    public void testInvalidLimit() {
+        assertEquals("1:13: Invalid value for LIMIT [foo: String], expecting a non negative integer", error("row a = 1 | limit \"foo\""));
+        assertEquals("1:13: Invalid value for LIMIT [1.2: Double], expecting a non negative integer", error("row a = 1 | limit 1.2"));
+        assertEquals("1:13: Invalid value for LIMIT [-1], expecting a non negative integer", error("row a = 1 | limit -1"));
+    }
+
     private String error(String query) {
         ParsingException e = expectThrows(ParsingException.class, () -> defaultAnalyzer.analyze(parser.createStatement(query)));
         String message = e.getMessage();

+ 2 - 2
x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java

@@ -885,7 +885,7 @@ public class StatementParserTests extends AbstractStatementParserTests {
     }
 
     public void testLimitConstraints() {
-        expectError("from text | limit -1", "line 1:19: extraneous input '-' expecting INTEGER_LITERAL");
+        expectError("from text | limit -1", "line 1:13: Invalid value for LIMIT [-1], expecting a non negative integer");
     }
 
     public void testBasicSortCommand() {
@@ -3051,7 +3051,7 @@ public class StatementParserTests extends AbstractStatementParserTests {
             Map.entry("drop {}", "line 1:18: token recognition error at: '{'"),
             Map.entry("rename a as {}", "line 1:25: token recognition error at: '{'"),
             Map.entry("mv_expand {}", "line 1:23: token recognition error at: '{'"),
-            Map.entry("limit {}", "line 1:19: mismatched input '{' expecting INTEGER_LITERAL"),
+            Map.entry("limit {}", "line 1:19: extraneous input '{' expecting {QUOTED_STRING"),
             Map.entry("enrich idx2 on f1 with f2 = {}", "line 1:41: token recognition error at: '{'"),
             Map.entry("dissect {} \"%{bar}\"", "line 1:21: extraneous input '{' expecting {QUOTED_STRING, INTEGER_LITERAL"),
             Map.entry("grok {} \"%{WORD:foo}\"", "line 1:18: extraneous input '{' expecting {QUOTED_STRING, INTEGER_LITERAL")

+ 62 - 6
x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/10_basic.yml

@@ -358,6 +358,41 @@ setup:
   - match: {values.1: ["1",2.0,null,true,123,1674835275193]}
   - match: {values.2: ["1",2.0,null,true,123,1674835275193]}
 
+---
+"Test Unnamed Input Params Also For Limit":
+  - requires:
+        test_runner_features: [ capabilities ]
+        capabilities:
+          - method: POST
+            path: /_query
+            parameters: [ ]
+            capabilities: [ parameter_for_limit ]
+        reason: "named or positional parameters"
+  - do:
+      esql.query:
+        body:
+          query: 'from test | eval x = ?, y = ?, z = ?, t = ?, u = ?, v = ? | keep x, y, z, t, u, v | limit ?'
+          params: ["1", 2.0, null, true, 123, 1674835275193, 3]
+
+  - length: {columns: 6}
+  - match: {columns.0.name: "x"}
+  - match: {columns.0.type: "keyword"}
+  - match: {columns.1.name: "y"}
+  - match: {columns.1.type: "double"}
+  - match: {columns.2.name: "z"}
+  - match: {columns.2.type: "null"}
+  - match: {columns.3.name: "t"}
+  - match: {columns.3.type: "boolean"}
+  - match: {columns.4.name: "u"}
+  - match: {columns.4.type: "integer"}
+  - match: {columns.5.name: "v"}
+  - match: {columns.5.type: "long"}
+  - length: {values: 3}
+  - match: {values.0: ["1",2.0,null,true,123,1674835275193]}
+  - match: {values.1: ["1",2.0,null,true,123,1674835275193]}
+  - match: {values.2: ["1",2.0,null,true,123,1674835275193]}
+
+
 ---
 "Test Named Input Params":
   - requires:
@@ -366,14 +401,14 @@ setup:
         - method: POST
           path: /_query
           parameters: [ ]
-          capabilities: [ named_positional_parameter ]
+          capabilities: [ parameter_for_limit ]
       reason: "named or positional parameters"
 
   - do:
       esql.query:
         body:
-          query: 'from test | eval x = ?, y = ?, z = ?, t = ?, u = ?, v = ? | keep x, y, z, t, u, v | limit 3'
-          params: [{"n1" : "1"}, {"n2" : 2.0}, {"n3" : null}, {"n4" : true}, {"n5" : 123}, {"n6": 1674835275193}]
+          query: 'from test | eval x = ?, y = ?, z = ?, t = ?, u = ?, v = ? | keep x, y, z, t, u, v | limit ?'
+          params: [{"n1" : "1"}, {"n2" : 2.0}, {"n3" : null}, {"n4" : true}, {"n5" : 123}, {"n6": 1674835275193}, {"l": 3}]
 
   - length: {columns: 6}
   - match: {columns.0.name: "x"}
@@ -430,14 +465,14 @@ setup:
         - method: POST
           path: /_query
           parameters: [ ]
-          capabilities: [ named_parameter_for_field_and_function_names_simplified_syntax ]
+          capabilities: [ parameter_for_limit ]
       reason: "named or positional parameters for field names"
 
   - do:
       esql.query:
         body:
-          query: 'from test | stats x = count(?f1), y = sum(?f2) by ?f3 | sort ?f3 | keep ?f3, x, y  | limit 3'
-          params: [{"f1" : {"identifier" : "time"}}, {"f2" : { "identifier" : "count" }}, {"f3" : { "identifier" : "color"}}]
+          query: 'from test | stats x = count(?f1), y = sum(?f2) by ?f3 | sort ?f3 | keep ?f3, x, y  | limit ?l'
+          params: [{"f1" : {"identifier" : "time"}}, {"f2" : { "identifier" : "count" }}, {"f3" : { "identifier" : "color"}}, {"l": 3}]
 
   - length: {columns: 3}
   - match: {columns.0.name: "color"}
@@ -451,6 +486,27 @@ setup:
   - match: {values.1: ["green",10,440]}
   - match: {values.2: ["red",20,860]}
 
+
+---
+"Test wrong LIMIT parameter":
+  - requires:
+      test_runner_features: [ capabilities ]
+      capabilities:
+        - method: POST
+          path: /_query
+          parameters: [ ]
+          capabilities: [ parameter_for_limit ]
+      reason: "named or positional parameters for field names"
+
+  - do:
+      catch: "/Invalid value for LIMIT \\[foo: String\\], expecting a non negative integer/"
+      esql.query:
+        body:
+          query: 'from test | limit ?l'
+          params: [{"l": "foo"}]
+
+
+
 ---
 version is not allowed:
   - requires:

部分文件因文件數量過多而無法顯示