[ASTERIXDB-2247][SQLPP] Allow "_" as the first character in a variable name
- user model changes: yes
- storage format changes: no
- interface changes: no
Details:
- Allow "_" as the first character in a variable name and
other identifiers
Change-Id: Ic530ccfd2a7d3f1e893fd2292b8605feb6241675
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2283
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-app/src/test/resources/parserts/queries_sqlpp/variables.sqlpp b/asterixdb/asterix-app/src/test/resources/parserts/queries_sqlpp/variables.sqlpp
index 7611e3e..417bea8 100644
--- a/asterixdb/asterix-app/src/test/resources/parserts/queries_sqlpp/variables.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/parserts/queries_sqlpp/variables.sqlpp
@@ -18,6 +18,7 @@
*/
with a as 1,
- b as 1
-select element (b - a)
+ b as 1,
+ _c as 0
+select element (b - a - _c)
;
diff --git a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/variables.ast b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/variables.ast
index 698f469..9f6906c 100644
--- a/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/variables.ast
+++ b/asterixdb/asterix-app/src/test/resources/parserts/results_parser_sqlpp/variables.ast
@@ -5,10 +5,15 @@
Let Variable [ Name=$b ]
:=
LiteralExpr [LONG] [1]
+Let Variable [ Name=$_c ]
+ :=
+ LiteralExpr [LONG] [0]
SELECT ELEMENT [
OperatorExpr [
Variable [ Name=$b ]
-
Variable [ Name=$a ]
+ -
+ Variable [ Name=$_c ]
]
]
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/identifier_01/identifier_01.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/identifier_01/identifier_01.1.query.sqlpp
new file mode 100644
index 0000000..17ad534
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/identifier_01/identifier_01.1.query.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+WITH _x as 1
+
+SELECT _x AS _y
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/identifier_01/identifier_01.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/identifier_01/identifier_01.1.adm
new file mode 100644
index 0000000..864e169
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/identifier_01/identifier_01.1.adm
@@ -0,0 +1 @@
+{ "_y": 1 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 14784d6..0b8fd8c 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -3518,6 +3518,11 @@
</compilation-unit>
</test-case>
<test-case FilePath="misc">
+ <compilation-unit name="identifier_01">
+ <output-dir compare="Text">identifier_01</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="misc">
<compilation-unit name="ifthenelse_01">
<output-dir compare="Text">ifthenelse_01</output-dir>
</compilation-unit>
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index a11aaf4..fd5de86 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -3399,7 +3399,8 @@
TOKEN :
{
<#LETTER : ["A" - "Z", "a" - "z"]>
- | <SPECIALCHARS : ["$", "_"]>
+ | <#IDENTIFIER_SPECIALCHARS_START : ["_"]>
+ | <#IDENTIFIER_SPECIALCHARS_REST : ["$"]>
}
<DEFAULT,IN_DBL_BRACE>
@@ -3450,7 +3451,8 @@
<DEFAULT,IN_DBL_BRACE>
TOKEN :
{
- <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
+ <IDENTIFIER : ( <LETTER> | <IDENTIFIER_SPECIALCHARS_START> )
+ ( <LETTER> | <DIGIT> | <IDENTIFIER_SPECIALCHARS_START> | <IDENTIFIER_SPECIALCHARS_REST> )*>
}
<DEFAULT,IN_DBL_BRACE>