blob: 4c83dc55e21557459d33d3fc1d7ad4c29c54638c [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;
30import org.apache.asterix.lang.sqlpp.parser.Token;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070031
32
33@merge
34Statement SingleStatement() throws ParseException:
35{
36 // merge area 1
37 before:
38 after:
39}
40{
41 (
42 // merge area 2
43 before:
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080044 after: | stmt = ChannelSubscriptionStatement() | stmt = ProcedureExecution())
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070045 {
46 // merge area 3
47 }
48}
49
50@merge
51Statement CreateStatement() throws ParseException:
52{
53 // merge area 1
54 before:
55 after:
56}
57{
58 (
59 // merge area 2
60 before:
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -080061 after: | stmt = ChannelSpecification() | stmt = BrokerSpecification() | stmt = ProcedureSpecification())
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070062 {
63 // merge area 3
64 }
65}
66
67@merge
68Statement DropStatement() throws ParseException:
69{
70 // merge area 1
71 before:
72 after:
73}
74{
75 (
76 // merge area 2
77 before:
78 after: | "channel" pairId = QualifiedName() ifExists = IfExists()
79 {
80 stmt = new ChannelDropStatement(pairId.first, pairId.second, ifExists);
81 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -080082 | "broker" pairId = QualifiedName() ifExists = IfExists()
83 {
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070084 stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists);
85 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080086 | "procedure" funcSig = FunctionSignature() ifExists = IfExists()
87 {
88 stmt = new ProcedureDropStatement(funcSig, ifExists);
89 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070090 )
91 {
92 // merge area 3
93 }
94}
95
96@new
97CreateChannelStatement ChannelSpecification() throws ParseException:
98{
99 Pair<Identifier,Identifier> nameComponents = null;
100 FunctionSignature appliedFunction = null;
101 CreateChannelStatement ccs = null;
102 String fqFunctionName = null;
103 Expression period = null;
Steven Glenn Jacobs345b0f52018-04-12 13:19:50 -0700104 boolean push = false;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700105}
106{
107 (
Steven Glenn Jacobs345b0f52018-04-12 13:19:50 -0700108 "repetitive"
109 ( "push" { push = true; } )?
110 "channel" nameComponents = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700111 <USING> appliedFunction = FunctionSignature()
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800112 "period" period = FunctionCallExpr()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700113 {
114 ccs = new CreateChannelStatement(nameComponents.first,
Steven Glenn Jacobs345b0f52018-04-12 13:19:50 -0700115 nameComponents.second, appliedFunction, period, push);
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700116 }
117 )
118 {
119 return ccs;
120 }
121}
122
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800123@new
124CreateProcedureStatement ProcedureSpecification() throws ParseException:
125{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800126 FunctionName fctName = null;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800127 FunctionSignature signature;
128 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800129 List<Integer> paramIds = new ArrayList<Integer>();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800130 String functionBody;
131 Token beginPos;
132 Token endPos;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800133 Statement functionBodyExpr;
134 Expression period = null;
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800135 String currentDataverse = defaultDataverse;
136 createNewScope();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800137}
138{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800139 "procedure" fctName = FunctionName()
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800140 {
141 defaultDataverse = fctName.dataverse;
142 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800143 paramList = ParameterList()
144 <LEFTBRACE>
145 {
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800146 for (VarIdentifier param : paramList)
147 {
148 VarIdentifier v = new VarIdentifier(param.toString());
149 getCurrentScope().addNewVarSymbolToScope(v);
150 paramIds.add(v.getId());
151 }
152 beginPos = token;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800153 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800154 functionBodyExpr = SingleStatement() <RIGHTBRACE>
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800155 {
156 endPos = token;
157 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800158 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800159 removeCurrentScope();
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800160 defaultDataverse = currentDataverse;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800161 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800162 ("period" period = FunctionCallExpr())?
163 {
Steven Glenn Jacobs0da2d002018-05-07 15:12:18 -0700164 return new CreateProcedureStatement(signature, paramList, paramIds, functionBody, period);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800165 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800166}
167
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800168@new
169ExecuteProcedureStatement ProcedureExecution() throws ParseException:
170{
171 ExecuteProcedureStatement callExpr;
172 List<Expression> argList = new ArrayList<Expression>();
173 Expression tmp;
174 int arity = 0;
175 FunctionName funcName = null;
176 String hint = null;
177}
178{
179 "execute"
180 funcName = FunctionName()
181 <LEFTPAREN> (tmp = Expression()
182 {
183 argList.add(tmp);
184 arity ++;
185 }
186 (<COMMA> tmp = Expression()
187 {
188 argList.add(tmp);
189 arity++;
190 }
191 )*)? <RIGHTPAREN>
192 {
193 String fqFunctionName = funcName.function;
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800194 return new ExecuteProcedureStatement(funcName.dataverse, fqFunctionName, arity, argList);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800195 }
196}
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800197
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700198@new
199CreateBrokerStatement BrokerSpecification() throws ParseException:
200{
201 CreateBrokerStatement cbs = null;
202 Pair<Identifier,Identifier> name = null;
203 String endPoint = null;
204}
205{
206 (
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800207 "broker" name = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700208 <AT> endPoint = StringLiteral()
209 {
210 cbs = new CreateBrokerStatement(name.first, name.second,endPoint);
211 }
212 )
213 {
214 return cbs;
215 }
216}
217
218@new
219Statement ChannelSubscriptionStatement() throws ParseException:
220{
221 Statement stmt = null;
222 Pair<Identifier,Identifier> nameComponents = null;
223 List<Expression> argList = new ArrayList<Expression>();
224 Expression tmp = null;
225 String id = null;
226 String subscriptionId = null;
227 Pair<Identifier,Identifier> brokerName = null;
228}
229{
230 (
231 "subscribe" <TO> nameComponents = QualifiedName()
232 <LEFTPAREN> (tmp = Expression()
233 {
234 argList.add(tmp);
235 }
236 (<COMMA> tmp = Expression()
237 {
238 argList.add(tmp);
239 }
240 )*)? <RIGHTPAREN> <ON> brokerName = QualifiedName()
241 {
242 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
243 }
244 | "unsubscribe" id = StringLiteral() <FROM> nameComponents = QualifiedName()
245 {
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700246 VariableExpr varExp = new VariableExpr();
247 VarIdentifier var = new VarIdentifier();
248 varExp.setVar(var);
249 var.setValue("$subscriptionPlaceholder");
250 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
Steven Glenn Jacobsd6767262017-04-04 17:31:40 -0700251 stmt = new ChannelUnsubscribeStatement(varExp, nameComponents.first, nameComponents.second, id, getVarCounter());
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700252 }
253 | "change" "subscription" subscriptionId = StringLiteral() <ON> nameComponents = QualifiedName()
254 <LEFTPAREN> (tmp = Expression()
255 {
256 argList.add(tmp);
257 }
258 (<COMMA> tmp = Expression()
259 {
260 argList.add(tmp);
261 }
262 )*)? <RIGHTPAREN>
263 <TO> brokerName = QualifiedName()
264 {
265 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
266 }
267 )
268 {
269 return stmt;
270 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700271}