blob: f2b6410beabf3afba87ec4d7036354fb392ac1b5 [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;
Xikui Wang9d26e072020-08-20 21:18:04 -070025import org.apache.asterix.bad.lang.statement.AbstractCreateChannelStatement;
26import org.apache.asterix.bad.lang.statement.CreateRepetitiveChannelStatement;
27import org.apache.asterix.bad.lang.statement.CreateContinuousChannelStatement;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -080028import org.apache.asterix.bad.lang.statement.CreateProcedureStatement;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080029import org.apache.asterix.bad.lang.statement.ExecuteProcedureStatement;
30import org.apache.asterix.bad.lang.statement.ProcedureDropStatement;
Steven Glenn Jacobs55514042017-04-19 15:54:13 -070031import org.apache.asterix.lang.sqlpp.parser.ParseException;
Steven Glenn Jacobsa7c85292018-05-29 09:00:44 -070032import org.apache.asterix.lang.sqlpp.parser.SqlppParseException;
Steven Glenn Jacobs55514042017-04-19 15:54:13 -070033import org.apache.asterix.lang.sqlpp.parser.Token;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070034
Xikui Wang9d26e072020-08-20 21:18:04 -070035@new
36<DEFAULT,IN_DBL_BRACE>
37TOKEN [IGNORE_CASE]:
38{
39 <BROKER : "broker">
40 | <CHANNEL : "channel">
41 | <PROCEDURE : "procedure">
42 | <SUBSCRIBE : "subscribe">
43 | <ACTIVE : "active">
44 | <UNSUBSCRIBE : "unsubscribe">
45 | <REPETITIVE : "repetitive">
46 | <CONTINUOUS : "continuous">
47 | <PERIOD : "period">
48 | <PUSH : "push">
49}
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070050
51@merge
52Statement SingleStatement() throws ParseException:
53{
54 // merge area 1
55 before:
56 after:
57}
58{
59 (
60 // merge area 2
61 before:
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080062 after: | stmt = ChannelSubscriptionStatement() | stmt = ProcedureExecution())
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070063 {
64 // merge area 3
65 }
66}
67
68@merge
69Statement CreateStatement() throws ParseException:
70{
71 // merge area 1
72 before:
73 after:
74}
75{
76 (
77 // merge area 2
78 before:
Xikui Wang9d26e072020-08-20 21:18:04 -070079 after: | stmt = CreateChannelStatement(startToken)
80 | stmt = CreateBrokerStatement(startToken)
Dmitry Lychagined047f62019-11-26 15:03:35 -080081 | stmt = CreateProcedureStatement()
Xikui Wang9d26e072020-08-20 21:18:04 -070082 | stmt = ActiveStatementSpecification(startToken)
Dmitry Lychagined047f62019-11-26 15:03:35 -080083 )
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070084 {
85 // merge area 3
86 }
87}
88
89@merge
90Statement DropStatement() throws ParseException:
91{
92 // merge area 1
93 before:
94 after:
95}
96{
97 (
98 // merge area 2
99 before:
Dmitry Lychagined047f62019-11-26 15:03:35 -0800100 after: | stmt = DropChannelStatement(startToken)
101 | stmt = DropBrokerStatement(startToken)
102 | stmt = DropProcedureStatement(startToken)
103 )
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700104 {
105 // merge area 3
106 }
107}
108
109@new
Xikui Wang9d26e072020-08-20 21:18:04 -0700110Statement ActiveStatementSpecification(Token startStmtToken) throws ParseException:
111{
112 Statement stmt = null;
113}
114{
115 "ACTIVE"
116 stmt = ActiveDatasetSpecification(startStmtToken)
117 {
118 return stmt;
119 }
120}
121
122@new
123DatasetDecl ActiveDatasetSpecification(Token startStmtToken) throws ParseException:
124{
125 Pair<DataverseName,Identifier> nameComponents = null;
126 TypeExpression activeRecordTypeExpr = new TypeReferenceExpression(
127 new Pair<DataverseName,Identifier>(DataverseName.createBuiltinDataverseName("Metadata"), new Identifier("ActiveRecordType")));
128 TypeExpression datasetTypeExpr = null;
129 boolean ifNotExists = false;
130 Map<String,String> properties = null;
131 Pair<List<Integer>, List<List<String>>> primaryKeyFields = null;
132 String nodeGroupName = null;
133 Map<String,String> hints = new HashMap<String,String>();
134 DatasetDecl stmt = null;
135 boolean autogenerated = false;
136 RecordConstructor withRecord = null;
137
138}
139{
140 Dataset() nameComponents = QualifiedName()
141 datasetTypeExpr = DatasetTypeSpecification()
142 ifNotExists = IfNotExists()
143 primaryKeyFields = PrimaryKey()
144 (<AUTOGENERATED> { autogenerated = true; } )?
145 (<ON> nodeGroupName = Identifier() )?
146 ( <HINTS> hints = Properties() )?
147 ( <WITH> withRecord = RecordConstructor() )?
148 {
149 // TODO: add filters on meta records
150 InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
151 primaryKeyFields.first,
152 autogenerated,
153 null);
154 try{
155 stmt = new DatasetDecl(nameComponents.first,
156 nameComponents.second,
157 datasetTypeExpr,
158 activeRecordTypeExpr,
159 nodeGroupName != null ? new Identifier(nodeGroupName) : null,
160 hints,
161 DatasetType.INTERNAL,
162 idd,
163 withRecord,
164 ifNotExists);
165
166 } catch (CompilationException e){
167 throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
168 }
169 }
170 {
171 return addSourceLocation(stmt, startStmtToken);
172 }
173}
174
175
176@new
177AbstractCreateChannelStatement CreateChannelStatement(Token startStmtToken) throws ParseException:
178{
179 AbstractCreateChannelStatement ccs = null;
180}
181{
182 (
183 <REPETITIVE> { ccs = CreateRepetitiveChannel(startStmtToken); }
184 | <CONTINUOUS> { ccs = CreateContinuousChannel(startStmtToken); }
185 )
186 {
187 return ccs;
188 }
189}
190
191@new
192CreateRepetitiveChannelStatement CreateRepetitiveChannel(Token startStmtToken) throws ParseException:
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700193{
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800194 Pair<DataverseName,Identifier> nameComponents = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700195 FunctionSignature appliedFunction = null;
Xikui Wang9d26e072020-08-20 21:18:04 -0700196 CreateRepetitiveChannelStatement ccs = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700197 String fqFunctionName = null;
198 Expression period = null;
Steven Glenn Jacobs345b0f52018-04-12 13:19:50 -0700199 boolean push = false;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700200}
201{
Xikui Wang9d26e072020-08-20 21:18:04 -0700202 ( <PUSH> { push = true; } )?
203 <CHANNEL> nameComponents = QualifiedName()
204 <USING> appliedFunction = FunctionSignature()
205 <PERIOD> period = FunctionCallExpr()
206 {
207 ccs = new CreateRepetitiveChannelStatement(nameComponents.first,
208 nameComponents.second, appliedFunction, period, push);
209 }
210 {
211 return ccs;
212 }
213}
214
215
216@new
217CreateContinuousChannelStatement CreateContinuousChannel(Token startStmtToken) throws ParseException:
218{
219 // Channel related
220 CreateContinuousChannelStatement ccs = null;
221 Expression period = null;
222 boolean push = false;
223 boolean ifNotExists = false;
224 // Function related
225 FunctionSignature signature;
226 String functionBody;
227 Expression functionBodyExpr;
228 Token beginPos;
229 Token endPos;
230 FunctionName fctName = null;
231 TypeExpression returnType = null;
232 List<Pair<VarIdentifier,TypeExpression>> params = null;
233 DataverseName currentDataverse = defaultDataverse;
234}
235{
236 ( <PUSH> { push = true; } )?
237 <CHANNEL>
238 fctName = FunctionName()
239 {
240 defaultDataverse = fctName.dataverse;
241 }
242 ifNotExists = IfNotExists()
243 params = FunctionParameters()
244 <PERIOD> period = FunctionCallExpr()
245 <LEFTBRACE>
246 {
247 createNewScope();
248 beginPos = token;
249 }
250 functionBodyExpr = FunctionBody()
251 returnType = FunctionReturnType()
252 <RIGHTBRACE>
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700253 {
Xikui Wang9d26e072020-08-20 21:18:04 -0700254 endPos = token;
255 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
256 signature = new FunctionSignature(fctName.dataverse, fctName.function, params.size());
257 getCurrentScope().addFunctionDescriptor(signature, false);
258 removeCurrentScope();
259 defaultDataverse = currentDataverse;
260 ensureNoTypeDeclsInFunction(fctName.function, params, returnType, startStmtToken);
261 CreateFunctionStatement stmt = new CreateFunctionStatement(signature, params, functionBody, functionBodyExpr, false);
262 ccs = new CreateContinuousChannelStatement(fctName.dataverse, new Identifier(fctName.function), period, push, stmt);
263 return addSourceLocation(ccs, startStmtToken);
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700264 }
265}
266
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800267@new
Dmitry Lychagined047f62019-11-26 15:03:35 -0800268CreateProcedureStatement CreateProcedureStatement() throws ParseException:
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800269{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800270 FunctionName fctName = null;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800271 FunctionSignature signature;
Xikui Wang1ef04492020-07-30 09:05:34 -0700272 List<Pair<VarIdentifier,TypeExpression>> paramList = new ArrayList<Pair<VarIdentifier,TypeExpression>>();
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800273 List<Integer> paramIds = new ArrayList<Integer>();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800274 String functionBody;
275 Token beginPos;
276 Token endPos;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800277 Statement functionBodyExpr;
278 Expression period = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800279 DataverseName currentDataverse = defaultDataverse;
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800280 createNewScope();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800281}
282{
Xikui Wang9d26e072020-08-20 21:18:04 -0700283 <PROCEDURE> fctName = FunctionName()
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800284 {
285 defaultDataverse = fctName.dataverse;
286 }
Ian Maxon80ab7db2020-02-03 12:32:55 -0800287 paramList = FunctionParameters()
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800288 <LEFTBRACE>
289 {
Xikui Wang1ef04492020-07-30 09:05:34 -0700290 for (Pair<VarIdentifier,TypeExpression> param : paramList)
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800291 {
Ian Maxon80ab7db2020-02-03 12:32:55 -0800292 VarIdentifier v = new VarIdentifier(param.getFirst().toString());
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800293 getCurrentScope().addNewVarSymbolToScope(v);
294 paramIds.add(v.getId());
295 }
296 beginPos = token;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800297 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800298 functionBodyExpr = SingleStatement() <RIGHTBRACE>
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800299 {
300 endPos = token;
301 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800302 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800303 removeCurrentScope();
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800304 defaultDataverse = currentDataverse;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800305 }
Xikui Wang9d26e072020-08-20 21:18:04 -0700306 (<PERIOD> period = FunctionCallExpr())?
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800307 {
Ian Maxon80ab7db2020-02-03 12:32:55 -0800308 List<VarIdentifier> paramListVariablesOnly = new ArrayList<VarIdentifier>();
Xikui Wang1ef04492020-07-30 09:05:34 -0700309 for(Pair<VarIdentifier,TypeExpression> p: paramList){
Ian Maxon80ab7db2020-02-03 12:32:55 -0800310 paramListVariablesOnly.add(p.first);
311 }
312 return new CreateProcedureStatement(signature, paramListVariablesOnly, paramIds, functionBody, period);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800313 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800314}
315
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800316@new
317ExecuteProcedureStatement ProcedureExecution() throws ParseException:
318{
319 ExecuteProcedureStatement callExpr;
320 List<Expression> argList = new ArrayList<Expression>();
321 Expression tmp;
322 int arity = 0;
323 FunctionName funcName = null;
324 String hint = null;
325}
326{
327 "execute"
328 funcName = FunctionName()
329 <LEFTPAREN> (tmp = Expression()
330 {
331 argList.add(tmp);
332 arity ++;
333 }
334 (<COMMA> tmp = Expression()
335 {
336 argList.add(tmp);
337 arity++;
338 }
339 )*)? <RIGHTPAREN>
340 {
341 String fqFunctionName = funcName.function;
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800342 return new ExecuteProcedureStatement(funcName.dataverse, fqFunctionName, arity, argList);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800343 }
344}
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800345
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700346@new
Xikui Wang9d26e072020-08-20 21:18:04 -0700347CreateBrokerStatement CreateBrokerStatement(Token startStmtToken) throws ParseException:
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700348{
349 CreateBrokerStatement cbs = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800350 Pair<DataverseName,Identifier> name = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700351 String endPoint = null;
Xikui Wang9d26e072020-08-20 21:18:04 -0700352 RecordConstructor withRecord = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700353}
354{
355 (
Xikui Wang9d26e072020-08-20 21:18:04 -0700356 <BROKER> name = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700357 <AT> endPoint = StringLiteral()
Xikui Wang9d26e072020-08-20 21:18:04 -0700358 ( <WITH> withRecord = RecordConstructor() )?
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700359 {
Xikui Wang9d26e072020-08-20 21:18:04 -0700360 try {
361 cbs = new CreateBrokerStatement(name.first, name.second, endPoint, withRecord);
362 } catch (CompilationException e) {
363 throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
364 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700365 }
366 )
367 {
368 return cbs;
369 }
370}
371
372@new
373Statement ChannelSubscriptionStatement() throws ParseException:
374{
375 Statement stmt = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800376 Pair<DataverseName,Identifier> nameComponents = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700377 List<Expression> argList = new ArrayList<Expression>();
378 Expression tmp = null;
379 String id = null;
380 String subscriptionId = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800381 Pair<DataverseName,Identifier> brokerName = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700382}
383{
384 (
Xikui Wang9d26e072020-08-20 21:18:04 -0700385 <SUBSCRIBE> <TO> nameComponents = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700386 <LEFTPAREN> (tmp = Expression()
387 {
388 argList.add(tmp);
389 }
390 (<COMMA> tmp = Expression()
391 {
392 argList.add(tmp);
393 }
394 )*)? <RIGHTPAREN> <ON> brokerName = QualifiedName()
395 {
396 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
397 }
Xikui Wang9d26e072020-08-20 21:18:04 -0700398 | <UNSUBSCRIBE> id = StringLiteral() <FROM> nameComponents = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700399 {
Dmitry Lychagin27a9a3c2019-10-03 18:10:45 -0700400 VariableExpr varExp = new VariableExpr(new VarIdentifier("$subscriptionPlaceholder"));
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700401 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
Steven Glenn Jacobsd6767262017-04-04 17:31:40 -0700402 stmt = new ChannelUnsubscribeStatement(varExp, nameComponents.first, nameComponents.second, id, getVarCounter());
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700403 }
404 | "change" "subscription" subscriptionId = StringLiteral() <ON> nameComponents = QualifiedName()
405 <LEFTPAREN> (tmp = Expression()
406 {
407 argList.add(tmp);
408 }
409 (<COMMA> tmp = Expression()
410 {
411 argList.add(tmp);
412 }
413 )*)? <RIGHTPAREN>
414 <TO> brokerName = QualifiedName()
415 {
416 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
417 }
418 )
419 {
420 return stmt;
421 }
Dmitry Lychagined047f62019-11-26 15:03:35 -0800422}
423
424@new
425ChannelDropStatement DropChannelStatement(Token startStmtToken) throws ParseException:
426{
427 ChannelDropStatement stmt = null;
428 Pair<DataverseName,Identifier> pairId = null;
429 boolean ifExists = false;
430}
431{
Xikui Wang9d26e072020-08-20 21:18:04 -0700432 <CHANNEL> pairId = QualifiedName() ifExists = IfExists()
Dmitry Lychagined047f62019-11-26 15:03:35 -0800433 {
434 stmt = new ChannelDropStatement(pairId.first, pairId.second, ifExists);
435 return addSourceLocation(stmt, startStmtToken);
436 }
437}
438
439@new
440BrokerDropStatement DropBrokerStatement(Token startStmtToken) throws ParseException:
441{
442 BrokerDropStatement stmt = null;
443 Pair<DataverseName,Identifier> pairId = null;
444 boolean ifExists = false;
445}
446{
Xikui Wang9d26e072020-08-20 21:18:04 -0700447 <BROKER> pairId = QualifiedName() ifExists = IfExists()
Dmitry Lychagined047f62019-11-26 15:03:35 -0800448 {
449 stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists);
450 return addSourceLocation(stmt, startStmtToken);
451 }
452}
453
454@new
455ProcedureDropStatement DropProcedureStatement(Token startStmtToken) throws ParseException:
456{
457 ProcedureDropStatement stmt = null;
458 FunctionSignature funcSig = null;
459 boolean ifExists = false;
460}
461{
Xikui Wang9d26e072020-08-20 21:18:04 -0700462 <PROCEDURE> funcSig = FunctionSignature() ifExists = IfExists()
Dmitry Lychagined047f62019-11-26 15:03:35 -0800463 {
464 stmt = new ProcedureDropStatement(funcSig, ifExists);
465 return addSourceLocation(stmt, startStmtToken);
466 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700467}