blob: 58240fda5bd88b2103e99b060cec06d47d4f615d [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:
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -080062 after: | stmt = ChannelSpecification() | stmt = BrokerSpecification() | stmt = ProcedureSpecification())
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070063 {
64 // merge area 3
65 }
66}
67
68@merge
69Statement DropStatement() throws ParseException:
70{
71 // merge area 1
72 before:
73 after:
74}
75{
76 (
77 // merge area 2
78 before:
79 after: | "channel" pairId = QualifiedName() ifExists = IfExists()
80 {
81 stmt = new ChannelDropStatement(pairId.first, pairId.second, ifExists);
82 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -080083 | "broker" pairId = QualifiedName() ifExists = IfExists()
84 {
Dmitry Lychagin27a9a3c2019-10-03 18:10:45 -070085 stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists);
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070086 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080087 | "procedure" funcSig = FunctionSignature() ifExists = IfExists()
88 {
89 stmt = new ProcedureDropStatement(funcSig, ifExists);
90 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070091 )
92 {
93 // merge area 3
94 }
95}
96
97@new
98CreateChannelStatement ChannelSpecification() throws ParseException:
99{
100 Pair<Identifier,Identifier> nameComponents = null;
101 FunctionSignature appliedFunction = null;
102 CreateChannelStatement ccs = null;
103 String fqFunctionName = null;
104 Expression period = null;
Steven Glenn Jacobs345b0f52018-04-12 13:19:50 -0700105 boolean push = false;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700106}
107{
108 (
Steven Glenn Jacobs345b0f52018-04-12 13:19:50 -0700109 "repetitive"
110 ( "push" { push = true; } )?
111 "channel" nameComponents = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700112 <USING> appliedFunction = FunctionSignature()
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800113 "period" period = FunctionCallExpr()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700114 {
115 ccs = new CreateChannelStatement(nameComponents.first,
Steven Glenn Jacobs345b0f52018-04-12 13:19:50 -0700116 nameComponents.second, appliedFunction, period, push);
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700117 }
118 )
119 {
120 return ccs;
121 }
122}
123
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800124@new
125CreateProcedureStatement ProcedureSpecification() throws ParseException:
126{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800127 FunctionName fctName = null;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800128 FunctionSignature signature;
129 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800130 List<Integer> paramIds = new ArrayList<Integer>();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800131 String functionBody;
132 Token beginPos;
133 Token endPos;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800134 Statement functionBodyExpr;
135 Expression period = null;
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800136 String currentDataverse = defaultDataverse;
137 createNewScope();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800138}
139{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800140 "procedure" fctName = FunctionName()
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800141 {
142 defaultDataverse = fctName.dataverse;
143 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800144 paramList = ParameterList()
145 <LEFTBRACE>
146 {
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800147 for (VarIdentifier param : paramList)
148 {
149 VarIdentifier v = new VarIdentifier(param.toString());
150 getCurrentScope().addNewVarSymbolToScope(v);
151 paramIds.add(v.getId());
152 }
153 beginPos = token;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800154 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800155 functionBodyExpr = SingleStatement() <RIGHTBRACE>
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800156 {
157 endPos = token;
158 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800159 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800160 removeCurrentScope();
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800161 defaultDataverse = currentDataverse;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800162 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800163 ("period" period = FunctionCallExpr())?
164 {
Steven Glenn Jacobs0da2d002018-05-07 15:12:18 -0700165 return new CreateProcedureStatement(signature, paramList, paramIds, functionBody, period);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800166 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800167}
168
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800169@new
170ExecuteProcedureStatement ProcedureExecution() throws ParseException:
171{
172 ExecuteProcedureStatement callExpr;
173 List<Expression> argList = new ArrayList<Expression>();
174 Expression tmp;
175 int arity = 0;
176 FunctionName funcName = null;
177 String hint = null;
178}
179{
180 "execute"
181 funcName = FunctionName()
182 <LEFTPAREN> (tmp = Expression()
183 {
184 argList.add(tmp);
185 arity ++;
186 }
187 (<COMMA> tmp = Expression()
188 {
189 argList.add(tmp);
190 arity++;
191 }
192 )*)? <RIGHTPAREN>
193 {
194 String fqFunctionName = funcName.function;
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800195 return new ExecuteProcedureStatement(funcName.dataverse, fqFunctionName, arity, argList);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800196 }
197}
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800198
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700199@new
200CreateBrokerStatement BrokerSpecification() throws ParseException:
201{
202 CreateBrokerStatement cbs = null;
203 Pair<Identifier,Identifier> name = null;
204 String endPoint = null;
205}
206{
207 (
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800208 "broker" name = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700209 <AT> endPoint = StringLiteral()
210 {
211 cbs = new CreateBrokerStatement(name.first, name.second,endPoint);
212 }
213 )
214 {
215 return cbs;
216 }
217}
218
219@new
220Statement ChannelSubscriptionStatement() throws ParseException:
221{
222 Statement stmt = null;
223 Pair<Identifier,Identifier> nameComponents = null;
224 List<Expression> argList = new ArrayList<Expression>();
225 Expression tmp = null;
226 String id = null;
227 String subscriptionId = null;
228 Pair<Identifier,Identifier> brokerName = null;
229}
230{
231 (
232 "subscribe" <TO> nameComponents = QualifiedName()
233 <LEFTPAREN> (tmp = Expression()
234 {
235 argList.add(tmp);
236 }
237 (<COMMA> tmp = Expression()
238 {
239 argList.add(tmp);
240 }
241 )*)? <RIGHTPAREN> <ON> brokerName = QualifiedName()
242 {
243 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
244 }
245 | "unsubscribe" id = StringLiteral() <FROM> nameComponents = QualifiedName()
246 {
Dmitry Lychagin27a9a3c2019-10-03 18:10:45 -0700247 VariableExpr varExp = new VariableExpr(new VarIdentifier("$subscriptionPlaceholder"));
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700248 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
Steven Glenn Jacobsd6767262017-04-04 17:31:40 -0700249 stmt = new ChannelUnsubscribeStatement(varExp, nameComponents.first, nameComponents.second, id, getVarCounter());
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700250 }
251 | "change" "subscription" subscriptionId = StringLiteral() <ON> nameComponents = QualifiedName()
252 <LEFTPAREN> (tmp = Expression()
253 {
254 argList.add(tmp);
255 }
256 (<COMMA> tmp = Expression()
257 {
258 argList.add(tmp);
259 }
260 )*)? <RIGHTPAREN>
261 <TO> brokerName = QualifiedName()
262 {
263 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
264 }
265 )
266 {
267 return stmt;
268 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700269}