>From Suryaa Charan Shivakumar <[email protected]>:

Suryaa Charan Shivakumar has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21043?usp=email )


Change subject: [WIP][ASTERIXDB-3720] Improve error message for SELECT VALUE 
with multiple expressions
......................................................................

[WIP][ASTERIXDB-3720] Improve error message for SELECT VALUE with multiple 
expressions

SelectElement() in the SQL++ parser grammar now detects a comma immediately
after the single required expression and throws a SqlppParseException with a
clear, context-aware message instead of the generic JavaCC token-mismatch error.

The check uses a grammar-level optional production ( <COMMA> { throw } )? which
naturally fires when the user mistakenly writes SELECT VALUE a, b. The keyword
image (RAW/ELEMENT/VALUE) is preserved in the message via startToken.image.

A new negative parser test case is added under misc/ to prevent regression.

Change-Id: Ia6e37080a581292744ddc9020b216918411c11ac
---
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/select-value-multi-expr-negative/select-value-multi-expr-negative.1.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/misc/select-value-multi-expr-negative/select-value-multi-expr-negative.1.ast
M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp_parser.xml
M asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
4 files changed, 38 insertions(+), 0 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/43/21043/1

diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/select-value-multi-expr-negative/select-value-multi-expr-negative.1.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/select-value-multi-expr-negative/select-value-multi-expr-negative.1.query.sqlpp
new file mode 100644
index 0000000..152f1da
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/select-value-multi-expr-negative/select-value-multi-expr-negative.1.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * 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 : SELECT VALUE with a comma-separated list should produce a 
clear error
+ * Expected Res : Failure — ASX1001 with "SELECT VALUE requires a single 
expression"
+ */
+SELECT VALUE dist.id, dist.name
+FROM Districts AS dist;
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/misc/select-value-multi-expr-negative/select-value-multi-expr-negative.1.ast
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/misc/select-value-multi-expr-negative/select-value-multi-expr-negative.1.ast
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/misc/select-value-multi-expr-negative/select-value-multi-expr-negative.1.ast
@@ -0,0 +1 @@
+
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp_parser.xml 
b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp_parser.xml
index 94ee14a..d737e5e 100644
--- 
a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp_parser.xml
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp_parser.xml
@@ -2921,6 +2921,12 @@
         <output-dir compare="AST">prefix-search</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="misc">
+      <compilation-unit name="select-value-multi-expr-negative">
+        <output-dir compare="AST">select-value-multi-expr-negative</output-dir>
+        <expected-error>ASX1001: Syntax error: SELECT VALUE requires a single 
expression</expected-error>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="open-index-enforced">
     <test-group FilePath="open-index-enforced/error-checking">
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj 
b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index 23105fd..ccae4fb 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -5871,6 +5871,13 @@
 }
 {
   (<RAW>|<ELEMENT>|<VALUE>) { startToken = token; } expr = Expression()
+  ( <COMMA>
+    {
+      throw new SqlppParseException(getSourceLocation(token),
+        "SELECT " + startToken.image.toUpperCase() +
+        " requires a single expression; use SELECT for multiple projections");
+    }
+  )?
   {
     SelectElement selectElement = new SelectElement(expr);
     return addSourceLocation(selectElement, startToken);

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21043?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: Ia6e37080a581292744ddc9020b216918411c11ac
Gerrit-Change-Number: 21043
Gerrit-PatchSet: 1
Gerrit-Owner: Suryaa Charan Shivakumar <[email protected]>

Reply via email to