blob: 2001988e65b8b3666679f248ccb9578ec920d639 [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 Jacobs409c3e72016-09-14 11:32:13 -070029
30
31@merge
32Statement SingleStatement() throws ParseException:
33{
34 // merge area 1
35 before:
36 after:
37}
38{
39 (
40 // merge area 2
41 before:
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080042 after: | stmt = ChannelSubscriptionStatement() | stmt = ProcedureExecution())
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070043 {
44 // merge area 3
45 }
46}
47
48@merge
49Statement CreateStatement() throws ParseException:
50{
51 // merge area 1
52 before:
53 after:
54}
55{
56 (
57 // merge area 2
58 before:
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -080059 after: | stmt = ChannelSpecification() | stmt = BrokerSpecification() | stmt = ProcedureSpecification())
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070060 {
61 // merge area 3
62 }
63}
64
65@merge
66Statement DropStatement() throws ParseException:
67{
68 // merge area 1
69 before:
70 after:
71}
72{
73 (
74 // merge area 2
75 before:
76 after: | "channel" pairId = QualifiedName() ifExists = IfExists()
77 {
78 stmt = new ChannelDropStatement(pairId.first, pairId.second, ifExists);
79 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -080080 | "broker" pairId = QualifiedName() ifExists = IfExists()
81 {
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070082 stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists);
83 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080084 | "procedure" funcSig = FunctionSignature() ifExists = IfExists()
85 {
86 stmt = new ProcedureDropStatement(funcSig, ifExists);
87 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070088 )
89 {
90 // merge area 3
91 }
92}
93
94@new
95CreateChannelStatement ChannelSpecification() throws ParseException:
96{
97 Pair<Identifier,Identifier> nameComponents = null;
98 FunctionSignature appliedFunction = null;
99 CreateChannelStatement ccs = null;
100 String fqFunctionName = null;
101 Expression period = null;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800102 boolean distributed = true;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700103}
104{
105 (
106 "repetitive" "channel" nameComponents = QualifiedName()
107 <USING> appliedFunction = FunctionSignature()
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800108 "period" period = FunctionCallExpr() ("nondistributed" { distributed = false; })?
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700109 {
110 ccs = new CreateChannelStatement(nameComponents.first,
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800111 nameComponents.second, appliedFunction, period, distributed);
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700112 }
113 )
114 {
115 return ccs;
116 }
117}
118
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800119@new
120CreateProcedureStatement ProcedureSpecification() throws ParseException:
121{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800122 FunctionName fctName = null;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800123 FunctionSignature signature;
124 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
125 String functionBody;
126 Token beginPos;
127 Token endPos;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800128 Statement functionBodyExpr;
129 Expression period = null;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800130}
131{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800132 "procedure" fctName = FunctionName()
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800133 paramList = ParameterList()
134 <LEFTBRACE>
135 {
136 beginPos = token;
137 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800138 functionBodyExpr = SingleStatement() <RIGHTBRACE>
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800139 {
140 endPos = token;
141 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800142 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800143 removeCurrentScope();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800144 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800145 ("period" period = FunctionCallExpr())?
146 {
147 return new CreateProcedureStatement(signature, paramList, functionBody, period);
148 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800149}
150
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800151@new
152ExecuteProcedureStatement ProcedureExecution() throws ParseException:
153{
154 ExecuteProcedureStatement callExpr;
155 List<Expression> argList = new ArrayList<Expression>();
156 Expression tmp;
157 int arity = 0;
158 FunctionName funcName = null;
159 String hint = null;
160}
161{
162 "execute"
163 funcName = FunctionName()
164 <LEFTPAREN> (tmp = Expression()
165 {
166 argList.add(tmp);
167 arity ++;
168 }
169 (<COMMA> tmp = Expression()
170 {
171 argList.add(tmp);
172 arity++;
173 }
174 )*)? <RIGHTPAREN>
175 {
176 String fqFunctionName = funcName.function;
177 return new ExecuteProcedureStatement(funcName.dataverse, fqFunctionName, arity);
178 }
179}
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800180
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700181@new
182CreateBrokerStatement BrokerSpecification() throws ParseException:
183{
184 CreateBrokerStatement cbs = null;
185 Pair<Identifier,Identifier> name = null;
186 String endPoint = null;
187}
188{
189 (
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800190 "broker" name = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700191 <AT> endPoint = StringLiteral()
192 {
193 cbs = new CreateBrokerStatement(name.first, name.second,endPoint);
194 }
195 )
196 {
197 return cbs;
198 }
199}
200
201@new
202Statement ChannelSubscriptionStatement() throws ParseException:
203{
204 Statement stmt = null;
205 Pair<Identifier,Identifier> nameComponents = null;
206 List<Expression> argList = new ArrayList<Expression>();
207 Expression tmp = null;
208 String id = null;
209 String subscriptionId = null;
210 Pair<Identifier,Identifier> brokerName = null;
211}
212{
213 (
214 "subscribe" <TO> nameComponents = QualifiedName()
215 <LEFTPAREN> (tmp = Expression()
216 {
217 argList.add(tmp);
218 }
219 (<COMMA> tmp = Expression()
220 {
221 argList.add(tmp);
222 }
223 )*)? <RIGHTPAREN> <ON> brokerName = QualifiedName()
224 {
225 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
226 }
227 | "unsubscribe" id = StringLiteral() <FROM> nameComponents = QualifiedName()
228 {
229 setDataverses(new ArrayList<String>());
230 setDatasets(new ArrayList<String>());
231 VariableExpr varExp = new VariableExpr();
232 VarIdentifier var = new VarIdentifier();
233 varExp.setVar(var);
234 var.setValue("$subscriptionPlaceholder");
235 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
236 List<String> dataverses = getDataverses();
237 List<String> datasets = getDatasets();
238 // we remove the pointer to the dataverses and datasets
239 setDataverses(null);
240 setDatasets(null);
241 stmt = new ChannelUnsubscribeStatement(varExp, nameComponents.first, nameComponents.second, id, getVarCounter(), dataverses, datasets);
242 }
243 | "change" "subscription" subscriptionId = StringLiteral() <ON> nameComponents = QualifiedName()
244 <LEFTPAREN> (tmp = Expression()
245 {
246 argList.add(tmp);
247 }
248 (<COMMA> tmp = Expression()
249 {
250 argList.add(tmp);
251 }
252 )*)? <RIGHTPAREN>
253 <TO> brokerName = QualifiedName()
254 {
255 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
256 }
257 )
258 {
259 return stmt;
260 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700261}