This is an automated email from the ASF dual-hosted git repository.

mhubail pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 775d7d6012 [ASTERIXDB-3590]: Fix parse-only to consider all statements
775d7d6012 is described below

commit 775d7d6012e8021c9e8a4b9157fd722f924cae5b
Author: Janhavi Tripurwar <[email protected]>
AuthorDate: Wed Apr 2 20:39:50 2025 +0530

    [ASTERIXDB-3590]: Fix parse-only to consider all statements
    
    - user model changes: yes
    - storage format changes: no
    - interface changes: no
    
    details:
    - Currently, parse-only parameter only collects external variables
    from the last statement.
    - For example, "select $p1, $p2; select $p3, $p4;" only returns ["p3", 
"p4"] instead of
    ["p1", "p2", "p3", "p4"].
    - The fix processes all statements
    - Test cases added.
    
    Ext-ref: MB-62708
    Change-Id: Ia28d5b504f7eee0837647118422fed2b6101fbed
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19607
    Reviewed-by: Ali Alsuliman <[email protected]>
    Reviewed-by: Janhavi Tripurwar <[email protected]>
    Tested-by: Jenkins <[email protected]>
    Integration-Tests: Jenkins <[email protected]>
---
 .../api/http/server/QueryServiceServlet.java       | 14 +++++++----
 .../parseonly/001/parseonly_01.6.query.sqlpp       | 28 ++++++++++++++++++++++
 .../results/parseonly/001/parseonly_01.6.adm       |  1 +
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
index 12859fb14a..2b78498123 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
@@ -27,6 +27,7 @@ import java.net.UnknownHostException;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -389,10 +390,15 @@ public class QueryServiceServlet extends 
AbstractQueryApiServlet {
         IParser parser = factory.createParser(statementsText);
         List<Statement> stmts = parser.parse();
         QueryTranslator.validateStatements(stmts, true, 
RequestParameters.NO_CATEGORY_RESTRICTION_MASK);
-        Query query = (Query) stmts.get(stmts.size() - 1);
-        Set<VariableExpr> extVars =
-                
compilationProvider.getRewriterFactory().createQueryRewriter().getExternalVariables(query.getBody());
-        return new ResultUtil.ParseOnlyResult(extVars);
+
+        Set<VariableExpr> allExtVars = new HashSet<>();
+        for (Statement stmt : stmts) {
+            Query query = (Query) stmt;
+            Set<VariableExpr> stmtExtVars = 
compilationProvider.getRewriterFactory().createQueryRewriter()
+                    .getExternalVariables(query.getBody());
+            allExtVars.addAll(stmtExtVars);
+        }
+        return new ResultUtil.ParseOnlyResult(allExtVars);
     }
 
     protected void executeStatement(IServletRequest request, IRequestReference 
requestReference, String statementsText,
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/parseonly/001/parseonly_01.6.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/parseonly/001/parseonly_01.6.query.sqlpp
new file mode 100644
index 0000000000..03649408d6
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/parseonly/001/parseonly_01.6.query.sqlpp
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Description  : Test named statement parameters with json encoded request
+ * Expected Res : Success
+ * Date         : April 2025
+ */
+
+-- param parse-only:string=true
+
+select $p1, $p2; select 1; select $p3, $p1;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/parseonly/001/parseonly_01.6.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/parseonly/001/parseonly_01.6.adm
new file mode 100644
index 0000000000..8071244be5
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/parseonly/001/parseonly_01.6.adm
@@ -0,0 +1 @@
+{ "statement-parameters": [ "p1", "p2", "p3" ] }
\ No newline at end of file

Reply via email to