[ASTERIXDB-2401][SQLPP] Support parameterized queries
- user model changes: yes
- storage format changes: no
- interface changes: yes
Details:
- Support statement parameters: named ($name) and positional ($1 or ?)
- Enhance query service API to accept these parameters in the request
- Remove [?] index accessor from SQL++ grammar because it conflicts
with positional parameters ([0] can be used instead)
- Add testcases for parameterized queries
Change-Id: Ia612f731cd2370fccd54c4796bd9787fbea16766
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2707
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index 6d9976a..e2a8759 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -209,6 +209,8 @@
// error configuration
protected static final boolean REPORT_EXPECTED_TOKENS = false;
+ private int externalVarCounter;
+
private static class IndexParams {
public IndexType type;
public int gramLength;
@@ -2325,9 +2327,6 @@
}
}
}
-
- | <QUES> // ANY
-
)
<RIGHTBRACKET>
@@ -2347,6 +2346,7 @@
| expr = CaseExpr()
| expr = Literal()
| expr = VariableRef()
+ | expr = ExternalVariableRef()
| expr = ListConstructor()
| expr = RecordConstructor()
| expr = ParenthesizedExpression()
@@ -2458,6 +2458,33 @@
}
}
+VariableExpr ExternalVariableRef() throws ParseException:
+{
+ String name = null;
+}
+{
+ (
+ (
+ <DOLLAR>
+ (
+ <INTEGER_LITERAL> { name = token.image; } |
+ <IDENTIFIER> { name = token.image; } |
+ name = QuotedString()
+ )
+ )
+ |
+ (
+ <QUES> { name = String.valueOf(++externalVarCounter); }
+ )
+ )
+ {
+ String idName = SqlppVariableUtil.toExternalVariableName(name);
+ VarIdentifier id = new VarIdentifier(idName);
+ VariableExpr varExp = new VariableExpr(id);
+ return addSourceLocation(varExp, token);
+ }
+}
+
Expression ListConstructor() throws ParseException:
{
Expression expr = null;
@@ -3410,6 +3437,7 @@
| <ATT : "@">
| <COLON : ":">
| <COMMA : ",">
+ | <DOLLAR: "$">
| <DOT : ".">
| <PERCENT: "%">
| <QUES : "?">
@@ -3459,8 +3487,8 @@
<DEFAULT,IN_DBL_BRACE>
TOKEN [IGNORE_CASE]:
{
- <MISSING : "missing">
- | <NULL : "null">
+ <MISSING : "missing">
+ | <NULL : "null">
| <TRUE : "true">
| <FALSE : "false">
}