blob: 1c729a7f8e99b745340486753ae2a6106afe852e [file] [log] [blame]
Steven Glenn Jacobs39826042017-03-28 20:28:27 -07001//
2// Licensed to the Apache Software Foundation (ASF) under one
3// or more contributor license agreements. See the NOTICE file
4// distributed with this work for additional information
5// regarding copyright ownership. The ASF licenses this file
6// to you under the Apache License, Version 2.0 (the
7// "License"); you may not use this file except in compliance
8// with the License. You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing,
13// software distributed under the License is distributed on an
14// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15// KIND, either express or implied. See the License for the
16// specific language governing permissions and limitations
17// under the License.
18//
19
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070020import org.apache.asterix.bad.lang.statement.BrokerDropStatement;
21import org.apache.asterix.bad.lang.statement.ChannelDropStatement;
22import org.apache.asterix.bad.lang.statement.ChannelSubscribeStatement;
23import org.apache.asterix.bad.lang.statement.ChannelUnsubscribeStatement;
24import org.apache.asterix.bad.lang.statement.CreateBrokerStatement;
25import org.apache.asterix.bad.lang.statement.CreateChannelStatement;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -080026import org.apache.asterix.bad.lang.statement.CreateProcedureStatement;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080027import org.apache.asterix.bad.lang.statement.ExecuteProcedureStatement;
28import org.apache.asterix.bad.lang.statement.ProcedureDropStatement;
Steven Glenn Jacobs55514042017-04-19 15:54:13 -070029import org.apache.asterix.lang.sqlpp.parser.ParseException;
Steven Glenn Jacobsa7c85292018-05-29 09:00:44 -070030import org.apache.asterix.lang.sqlpp.parser.SqlppParseException;
Steven Glenn Jacobs55514042017-04-19 15:54:13 -070031import org.apache.asterix.lang.sqlpp.parser.Token;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070032
33
34@merge
35Statement SingleStatement() throws ParseException:
36{
37 // merge area 1
38 before:
39 after:
40}
41{
42 (
43 // merge area 2
44 before:
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080045 after: | stmt = ChannelSubscriptionStatement() | stmt = ProcedureExecution())
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070046 {
47 // merge area 3
48 }
49}
50
51@merge
52Statement CreateStatement() throws ParseException:
53{
54 // merge area 1
55 before:
56 after:
57}
58{
59 (
60 // merge area 2
61 before:
Dmitry Lychagined047f62019-11-26 15:03:35 -080062 after: | stmt = CreateChannelStatement()
63 | stmt = CreateBrokerStatement()
64 | stmt = CreateProcedureStatement()
65 )
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070066 {
67 // merge area 3
68 }
69}
70
71@merge
72Statement DropStatement() throws ParseException:
73{
74 // merge area 1
75 before:
76 after:
77}
78{
79 (
80 // merge area 2
81 before:
Dmitry Lychagined047f62019-11-26 15:03:35 -080082 after: | stmt = DropChannelStatement(startToken)
83 | stmt = DropBrokerStatement(startToken)
84 | stmt = DropProcedureStatement(startToken)
85 )
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070086 {
87 // merge area 3
88 }
89}
90
91@new
Dmitry Lychagined047f62019-11-26 15:03:35 -080092CreateChannelStatement CreateChannelStatement() throws ParseException:
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070093{
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -080094 Pair<DataverseName,Identifier> nameComponents = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070095 FunctionSignature appliedFunction = null;
96 CreateChannelStatement ccs = null;
97 String fqFunctionName = null;
98 Expression period = null;
Steven Glenn Jacobs345b0f52018-04-12 13:19:50 -070099 boolean push = false;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700100}
101{
102 (
Steven Glenn Jacobs345b0f52018-04-12 13:19:50 -0700103 "repetitive"
104 ( "push" { push = true; } )?
105 "channel" nameComponents = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700106 <USING> appliedFunction = FunctionSignature()
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800107 "period" period = FunctionCallExpr()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700108 {
109 ccs = new CreateChannelStatement(nameComponents.first,
Steven Glenn Jacobs345b0f52018-04-12 13:19:50 -0700110 nameComponents.second, appliedFunction, period, push);
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700111 }
112 )
113 {
114 return ccs;
115 }
116}
117
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800118@new
Dmitry Lychagined047f62019-11-26 15:03:35 -0800119CreateProcedureStatement CreateProcedureStatement() throws ParseException:
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800120{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800121 FunctionName fctName = null;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800122 FunctionSignature signature;
123 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800124 List<Integer> paramIds = new ArrayList<Integer>();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800125 String functionBody;
126 Token beginPos;
127 Token endPos;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800128 Statement functionBodyExpr;
129 Expression period = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800130 DataverseName currentDataverse = defaultDataverse;
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800131 createNewScope();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800132}
133{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800134 "procedure" fctName = FunctionName()
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800135 {
136 defaultDataverse = fctName.dataverse;
137 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800138 paramList = ParameterList()
139 <LEFTBRACE>
140 {
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800141 for (VarIdentifier param : paramList)
142 {
143 VarIdentifier v = new VarIdentifier(param.toString());
144 getCurrentScope().addNewVarSymbolToScope(v);
145 paramIds.add(v.getId());
146 }
147 beginPos = token;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800148 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800149 functionBodyExpr = SingleStatement() <RIGHTBRACE>
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800150 {
151 endPos = token;
152 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800153 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800154 removeCurrentScope();
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800155 defaultDataverse = currentDataverse;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800156 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800157 ("period" period = FunctionCallExpr())?
158 {
Steven Glenn Jacobs0da2d002018-05-07 15:12:18 -0700159 return new CreateProcedureStatement(signature, paramList, paramIds, functionBody, period);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800160 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800161}
162
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800163@new
164ExecuteProcedureStatement ProcedureExecution() throws ParseException:
165{
166 ExecuteProcedureStatement callExpr;
167 List<Expression> argList = new ArrayList<Expression>();
168 Expression tmp;
169 int arity = 0;
170 FunctionName funcName = null;
171 String hint = null;
172}
173{
174 "execute"
175 funcName = FunctionName()
176 <LEFTPAREN> (tmp = Expression()
177 {
178 argList.add(tmp);
179 arity ++;
180 }
181 (<COMMA> tmp = Expression()
182 {
183 argList.add(tmp);
184 arity++;
185 }
186 )*)? <RIGHTPAREN>
187 {
188 String fqFunctionName = funcName.function;
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800189 return new ExecuteProcedureStatement(funcName.dataverse, fqFunctionName, arity, argList);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800190 }
191}
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800192
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700193@new
Dmitry Lychagined047f62019-11-26 15:03:35 -0800194CreateBrokerStatement CreateBrokerStatement() throws ParseException:
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700195{
196 CreateBrokerStatement cbs = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800197 Pair<DataverseName,Identifier> name = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700198 String endPoint = null;
199}
200{
201 (
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800202 "broker" name = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700203 <AT> endPoint = StringLiteral()
204 {
205 cbs = new CreateBrokerStatement(name.first, name.second,endPoint);
206 }
207 )
208 {
209 return cbs;
210 }
211}
212
213@new
214Statement ChannelSubscriptionStatement() throws ParseException:
215{
216 Statement stmt = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800217 Pair<DataverseName,Identifier> nameComponents = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700218 List<Expression> argList = new ArrayList<Expression>();
219 Expression tmp = null;
220 String id = null;
221 String subscriptionId = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800222 Pair<DataverseName,Identifier> brokerName = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700223}
224{
225 (
226 "subscribe" <TO> nameComponents = QualifiedName()
227 <LEFTPAREN> (tmp = Expression()
228 {
229 argList.add(tmp);
230 }
231 (<COMMA> tmp = Expression()
232 {
233 argList.add(tmp);
234 }
235 )*)? <RIGHTPAREN> <ON> brokerName = QualifiedName()
236 {
237 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
238 }
239 | "unsubscribe" id = StringLiteral() <FROM> nameComponents = QualifiedName()
240 {
Dmitry Lychagin27a9a3c2019-10-03 18:10:45 -0700241 VariableExpr varExp = new VariableExpr(new VarIdentifier("$subscriptionPlaceholder"));
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700242 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
Steven Glenn Jacobsd6767262017-04-04 17:31:40 -0700243 stmt = new ChannelUnsubscribeStatement(varExp, nameComponents.first, nameComponents.second, id, getVarCounter());
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700244 }
245 | "change" "subscription" subscriptionId = StringLiteral() <ON> nameComponents = QualifiedName()
246 <LEFTPAREN> (tmp = Expression()
247 {
248 argList.add(tmp);
249 }
250 (<COMMA> tmp = Expression()
251 {
252 argList.add(tmp);
253 }
254 )*)? <RIGHTPAREN>
255 <TO> brokerName = QualifiedName()
256 {
257 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
258 }
259 )
260 {
261 return stmt;
262 }
Dmitry Lychagined047f62019-11-26 15:03:35 -0800263}
264
265@new
266ChannelDropStatement DropChannelStatement(Token startStmtToken) throws ParseException:
267{
268 ChannelDropStatement stmt = null;
269 Pair<DataverseName,Identifier> pairId = null;
270 boolean ifExists = false;
271}
272{
273 "channel" pairId = QualifiedName() ifExists = IfExists()
274 {
275 stmt = new ChannelDropStatement(pairId.first, pairId.second, ifExists);
276 return addSourceLocation(stmt, startStmtToken);
277 }
278}
279
280@new
281BrokerDropStatement DropBrokerStatement(Token startStmtToken) throws ParseException:
282{
283 BrokerDropStatement stmt = null;
284 Pair<DataverseName,Identifier> pairId = null;
285 boolean ifExists = false;
286}
287{
288 "broker" pairId = QualifiedName() ifExists = IfExists()
289 {
290 stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists);
291 return addSourceLocation(stmt, startStmtToken);
292 }
293}
294
295@new
296ProcedureDropStatement DropProcedureStatement(Token startStmtToken) throws ParseException:
297{
298 ProcedureDropStatement stmt = null;
299 FunctionSignature funcSig = null;
300 boolean ifExists = false;
301}
302{
303 "procedure" funcSig = FunctionSignature() ifExists = IfExists()
304 {
305 stmt = new ProcedureDropStatement(funcSig, ifExists);
306 return addSourceLocation(stmt, startStmtToken);
307 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700308}