blob: 3cc4b7b10eb21a50250e53459ecb8b728604662b [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;
Ian Maxon80ab7db2020-02-03 12:32:55 -0800123 List<Pair<VarIdentifier,IndexedTypeExpression>> paramList = new ArrayList<Pair<VarIdentifier,IndexedTypeExpression>>();
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 }
Ian Maxon80ab7db2020-02-03 12:32:55 -0800138 paramList = FunctionParameters()
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800139 <LEFTBRACE>
140 {
Ian Maxon80ab7db2020-02-03 12:32:55 -0800141 for (Pair<VarIdentifier,IndexedTypeExpression> param : paramList)
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800142 {
Ian Maxon80ab7db2020-02-03 12:32:55 -0800143 VarIdentifier v = new VarIdentifier(param.getFirst().toString());
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800144 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 {
Ian Maxon80ab7db2020-02-03 12:32:55 -0800159 List<VarIdentifier> paramListVariablesOnly = new ArrayList<VarIdentifier>();
160 for(Pair<VarIdentifier,IndexedTypeExpression> p: paramList){
161 paramListVariablesOnly.add(p.first);
162 }
163 return new CreateProcedureStatement(signature, paramListVariablesOnly, paramIds, functionBody, period);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800164 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800165}
166
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800167@new
168ExecuteProcedureStatement ProcedureExecution() throws ParseException:
169{
170 ExecuteProcedureStatement callExpr;
171 List<Expression> argList = new ArrayList<Expression>();
172 Expression tmp;
173 int arity = 0;
174 FunctionName funcName = null;
175 String hint = null;
176}
177{
178 "execute"
179 funcName = FunctionName()
180 <LEFTPAREN> (tmp = Expression()
181 {
182 argList.add(tmp);
183 arity ++;
184 }
185 (<COMMA> tmp = Expression()
186 {
187 argList.add(tmp);
188 arity++;
189 }
190 )*)? <RIGHTPAREN>
191 {
192 String fqFunctionName = funcName.function;
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800193 return new ExecuteProcedureStatement(funcName.dataverse, fqFunctionName, arity, argList);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800194 }
195}
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800196
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700197@new
Dmitry Lychagined047f62019-11-26 15:03:35 -0800198CreateBrokerStatement CreateBrokerStatement() throws ParseException:
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700199{
200 CreateBrokerStatement cbs = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800201 Pair<DataverseName,Identifier> name = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700202 String endPoint = null;
203}
204{
205 (
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800206 "broker" name = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700207 <AT> endPoint = StringLiteral()
208 {
209 cbs = new CreateBrokerStatement(name.first, name.second,endPoint);
210 }
211 )
212 {
213 return cbs;
214 }
215}
216
217@new
218Statement ChannelSubscriptionStatement() throws ParseException:
219{
220 Statement stmt = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800221 Pair<DataverseName,Identifier> nameComponents = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700222 List<Expression> argList = new ArrayList<Expression>();
223 Expression tmp = null;
224 String id = null;
225 String subscriptionId = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800226 Pair<DataverseName,Identifier> brokerName = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700227}
228{
229 (
230 "subscribe" <TO> nameComponents = QualifiedName()
231 <LEFTPAREN> (tmp = Expression()
232 {
233 argList.add(tmp);
234 }
235 (<COMMA> tmp = Expression()
236 {
237 argList.add(tmp);
238 }
239 )*)? <RIGHTPAREN> <ON> brokerName = QualifiedName()
240 {
241 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
242 }
243 | "unsubscribe" id = StringLiteral() <FROM> nameComponents = QualifiedName()
244 {
Dmitry Lychagin27a9a3c2019-10-03 18:10:45 -0700245 VariableExpr varExp = new VariableExpr(new VarIdentifier("$subscriptionPlaceholder"));
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700246 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
Steven Glenn Jacobsd6767262017-04-04 17:31:40 -0700247 stmt = new ChannelUnsubscribeStatement(varExp, nameComponents.first, nameComponents.second, id, getVarCounter());
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700248 }
249 | "change" "subscription" subscriptionId = StringLiteral() <ON> nameComponents = QualifiedName()
250 <LEFTPAREN> (tmp = Expression()
251 {
252 argList.add(tmp);
253 }
254 (<COMMA> tmp = Expression()
255 {
256 argList.add(tmp);
257 }
258 )*)? <RIGHTPAREN>
259 <TO> brokerName = QualifiedName()
260 {
261 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
262 }
263 )
264 {
265 return stmt;
266 }
Dmitry Lychagined047f62019-11-26 15:03:35 -0800267}
268
269@new
270ChannelDropStatement DropChannelStatement(Token startStmtToken) throws ParseException:
271{
272 ChannelDropStatement stmt = null;
273 Pair<DataverseName,Identifier> pairId = null;
274 boolean ifExists = false;
275}
276{
277 "channel" pairId = QualifiedName() ifExists = IfExists()
278 {
279 stmt = new ChannelDropStatement(pairId.first, pairId.second, ifExists);
280 return addSourceLocation(stmt, startStmtToken);
281 }
282}
283
284@new
285BrokerDropStatement DropBrokerStatement(Token startStmtToken) throws ParseException:
286{
287 BrokerDropStatement stmt = null;
288 Pair<DataverseName,Identifier> pairId = null;
289 boolean ifExists = false;
290}
291{
292 "broker" pairId = QualifiedName() ifExists = IfExists()
293 {
294 stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists);
295 return addSourceLocation(stmt, startStmtToken);
296 }
297}
298
299@new
300ProcedureDropStatement DropProcedureStatement(Token startStmtToken) throws ParseException:
301{
302 ProcedureDropStatement stmt = null;
303 FunctionSignature funcSig = null;
304 boolean ifExists = false;
305}
306{
307 "procedure" funcSig = FunctionSignature() ifExists = IfExists()
308 {
309 stmt = new ProcedureDropStatement(funcSig, ifExists);
310 return addSourceLocation(stmt, startStmtToken);
311 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700312}