blob: f7eba703ccc9ac4e52ed5fe9b53fe7d02a36c3bb [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;
Xikui Wang9d26e072020-08-20 21:18:04 -0700132 Map<String,String> hints = new HashMap<String,String>();
133 DatasetDecl stmt = null;
134 boolean autogenerated = false;
135 RecordConstructor withRecord = null;
136
137}
138{
139 Dataset() nameComponents = QualifiedName()
140 datasetTypeExpr = DatasetTypeSpecification()
141 ifNotExists = IfNotExists()
142 primaryKeyFields = PrimaryKey()
143 (<AUTOGENERATED> { autogenerated = true; } )?
Xikui Wang9d26e072020-08-20 21:18:04 -0700144 ( <HINTS> hints = Properties() )?
145 ( <WITH> withRecord = RecordConstructor() )?
146 {
Xikui Wang9ffb0122020-09-19 11:25:23 -0700147 try{
Xikui Wang9d26e072020-08-20 21:18:04 -0700148 InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
149 primaryKeyFields.first,
150 autogenerated,
Xikui Wang9ffb0122020-09-19 11:25:23 -0700151 1,
152 Collections.singletonList("_active_timestamp"));
Xikui Wang9d26e072020-08-20 21:18:04 -0700153 stmt = new DatasetDecl(nameComponents.first,
154 nameComponents.second,
155 datasetTypeExpr,
156 activeRecordTypeExpr,
Xikui Wang9d26e072020-08-20 21:18:04 -0700157 hints,
158 DatasetType.INTERNAL,
159 idd,
160 withRecord,
161 ifNotExists);
162
163 } catch (CompilationException e){
164 throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
165 }
166 }
167 {
168 return addSourceLocation(stmt, startStmtToken);
169 }
170}
171
172
173@new
174AbstractCreateChannelStatement CreateChannelStatement(Token startStmtToken) throws ParseException:
175{
176 AbstractCreateChannelStatement ccs = null;
177}
178{
179 (
180 <REPETITIVE> { ccs = CreateRepetitiveChannel(startStmtToken); }
181 | <CONTINUOUS> { ccs = CreateContinuousChannel(startStmtToken); }
182 )
183 {
184 return ccs;
185 }
186}
187
188@new
189CreateRepetitiveChannelStatement CreateRepetitiveChannel(Token startStmtToken) throws ParseException:
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700190{
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800191 Pair<DataverseName,Identifier> nameComponents = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700192 FunctionSignature appliedFunction = null;
Xikui Wang9d26e072020-08-20 21:18:04 -0700193 CreateRepetitiveChannelStatement ccs = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700194 String fqFunctionName = null;
195 Expression period = null;
Steven Glenn Jacobs345b0f52018-04-12 13:19:50 -0700196 boolean push = false;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700197}
198{
Xikui Wang9d26e072020-08-20 21:18:04 -0700199 ( <PUSH> { push = true; } )?
200 <CHANNEL> nameComponents = QualifiedName()
201 <USING> appliedFunction = FunctionSignature()
202 <PERIOD> period = FunctionCallExpr()
203 {
204 ccs = new CreateRepetitiveChannelStatement(nameComponents.first,
205 nameComponents.second, appliedFunction, period, push);
206 }
207 {
208 return ccs;
209 }
210}
211
212
213@new
214CreateContinuousChannelStatement CreateContinuousChannel(Token startStmtToken) throws ParseException:
215{
216 // Channel related
217 CreateContinuousChannelStatement ccs = null;
218 Expression period = null;
219 boolean push = false;
220 boolean ifNotExists = false;
221 // Function related
222 FunctionSignature signature;
223 String functionBody;
224 Expression functionBodyExpr;
225 Token beginPos;
226 Token endPos;
227 FunctionName fctName = null;
228 TypeExpression returnType = null;
229 List<Pair<VarIdentifier,TypeExpression>> params = null;
230 DataverseName currentDataverse = defaultDataverse;
231}
232{
233 ( <PUSH> { push = true; } )?
234 <CHANNEL>
235 fctName = FunctionName()
236 {
237 defaultDataverse = fctName.dataverse;
238 }
239 ifNotExists = IfNotExists()
240 params = FunctionParameters()
241 <PERIOD> period = FunctionCallExpr()
242 <LEFTBRACE>
243 {
244 createNewScope();
245 beginPos = token;
246 }
247 functionBodyExpr = FunctionBody()
248 returnType = FunctionReturnType()
249 <RIGHTBRACE>
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700250 {
Xikui Wang9d26e072020-08-20 21:18:04 -0700251 endPos = token;
252 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
253 signature = new FunctionSignature(fctName.dataverse, fctName.function, params.size());
254 getCurrentScope().addFunctionDescriptor(signature, false);
255 removeCurrentScope();
256 defaultDataverse = currentDataverse;
257 ensureNoTypeDeclsInFunction(fctName.function, params, returnType, startStmtToken);
Xikui Wang0bc1dfd2020-08-27 21:15:57 -0700258 CreateFunctionStatement stmt = new CreateFunctionStatement(signature, params, functionBody, functionBodyExpr, true, false);
Xikui Wang9d26e072020-08-20 21:18:04 -0700259 ccs = new CreateContinuousChannelStatement(fctName.dataverse, new Identifier(fctName.function), period, push, stmt);
260 return addSourceLocation(ccs, startStmtToken);
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700261 }
262}
263
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800264@new
Dmitry Lychagined047f62019-11-26 15:03:35 -0800265CreateProcedureStatement CreateProcedureStatement() throws ParseException:
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800266{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800267 FunctionName fctName = null;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800268 FunctionSignature signature;
Xikui Wang1ef04492020-07-30 09:05:34 -0700269 List<Pair<VarIdentifier,TypeExpression>> paramList = new ArrayList<Pair<VarIdentifier,TypeExpression>>();
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800270 List<Integer> paramIds = new ArrayList<Integer>();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800271 String functionBody;
272 Token beginPos;
273 Token endPos;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800274 Statement functionBodyExpr;
275 Expression period = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800276 DataverseName currentDataverse = defaultDataverse;
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800277 createNewScope();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800278}
279{
Xikui Wang9d26e072020-08-20 21:18:04 -0700280 <PROCEDURE> fctName = FunctionName()
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800281 {
282 defaultDataverse = fctName.dataverse;
283 }
Ian Maxon80ab7db2020-02-03 12:32:55 -0800284 paramList = FunctionParameters()
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800285 <LEFTBRACE>
286 {
Xikui Wang1ef04492020-07-30 09:05:34 -0700287 for (Pair<VarIdentifier,TypeExpression> param : paramList)
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800288 {
Ian Maxon80ab7db2020-02-03 12:32:55 -0800289 VarIdentifier v = new VarIdentifier(param.getFirst().toString());
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800290 getCurrentScope().addNewVarSymbolToScope(v);
291 paramIds.add(v.getId());
292 }
293 beginPos = token;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800294 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800295 functionBodyExpr = SingleStatement() <RIGHTBRACE>
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800296 {
297 endPos = token;
298 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800299 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800300 removeCurrentScope();
Steven Glenn Jacobs5b870652018-01-19 19:52:51 -0800301 defaultDataverse = currentDataverse;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800302 }
Xikui Wang9d26e072020-08-20 21:18:04 -0700303 (<PERIOD> period = FunctionCallExpr())?
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800304 {
Ian Maxon80ab7db2020-02-03 12:32:55 -0800305 List<VarIdentifier> paramListVariablesOnly = new ArrayList<VarIdentifier>();
Xikui Wang1ef04492020-07-30 09:05:34 -0700306 for(Pair<VarIdentifier,TypeExpression> p: paramList){
Ian Maxon80ab7db2020-02-03 12:32:55 -0800307 paramListVariablesOnly.add(p.first);
308 }
309 return new CreateProcedureStatement(signature, paramListVariablesOnly, paramIds, functionBody, period);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800310 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800311}
312
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800313@new
314ExecuteProcedureStatement ProcedureExecution() throws ParseException:
315{
316 ExecuteProcedureStatement callExpr;
317 List<Expression> argList = new ArrayList<Expression>();
318 Expression tmp;
319 int arity = 0;
320 FunctionName funcName = null;
321 String hint = null;
322}
323{
324 "execute"
325 funcName = FunctionName()
326 <LEFTPAREN> (tmp = Expression()
327 {
328 argList.add(tmp);
329 arity ++;
330 }
331 (<COMMA> tmp = Expression()
332 {
333 argList.add(tmp);
334 arity++;
335 }
336 )*)? <RIGHTPAREN>
337 {
338 String fqFunctionName = funcName.function;
Steven Glenn Jacobs8b53ce52017-11-14 10:21:43 -0800339 return new ExecuteProcedureStatement(funcName.dataverse, fqFunctionName, arity, argList);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800340 }
341}
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800342
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700343@new
Xikui Wang9d26e072020-08-20 21:18:04 -0700344CreateBrokerStatement CreateBrokerStatement(Token startStmtToken) throws ParseException:
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700345{
346 CreateBrokerStatement cbs = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800347 Pair<DataverseName,Identifier> name = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700348 String endPoint = null;
Xikui Wang9d26e072020-08-20 21:18:04 -0700349 RecordConstructor withRecord = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700350}
351{
352 (
Xikui Wang9d26e072020-08-20 21:18:04 -0700353 <BROKER> name = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700354 <AT> endPoint = StringLiteral()
Xikui Wang9d26e072020-08-20 21:18:04 -0700355 ( <WITH> withRecord = RecordConstructor() )?
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700356 {
Xikui Wang9d26e072020-08-20 21:18:04 -0700357 try {
358 cbs = new CreateBrokerStatement(name.first, name.second, endPoint, withRecord);
359 } catch (CompilationException e) {
360 throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
361 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700362 }
363 )
364 {
365 return cbs;
366 }
367}
368
369@new
370Statement ChannelSubscriptionStatement() throws ParseException:
371{
372 Statement stmt = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800373 Pair<DataverseName,Identifier> nameComponents = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700374 List<Expression> argList = new ArrayList<Expression>();
375 Expression tmp = null;
376 String id = null;
377 String subscriptionId = null;
Dmitry Lychagin6e8a1542019-11-14 13:03:32 -0800378 Pair<DataverseName,Identifier> brokerName = null;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700379}
380{
381 (
Xikui Wang9d26e072020-08-20 21:18:04 -0700382 <SUBSCRIBE> <TO> nameComponents = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700383 <LEFTPAREN> (tmp = Expression()
384 {
385 argList.add(tmp);
386 }
387 (<COMMA> tmp = Expression()
388 {
389 argList.add(tmp);
390 }
391 )*)? <RIGHTPAREN> <ON> brokerName = QualifiedName()
392 {
393 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
394 }
Xikui Wang9d26e072020-08-20 21:18:04 -0700395 | <UNSUBSCRIBE> id = StringLiteral() <FROM> nameComponents = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700396 {
Dmitry Lychagin27a9a3c2019-10-03 18:10:45 -0700397 VariableExpr varExp = new VariableExpr(new VarIdentifier("$subscriptionPlaceholder"));
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700398 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
Steven Glenn Jacobsd6767262017-04-04 17:31:40 -0700399 stmt = new ChannelUnsubscribeStatement(varExp, nameComponents.first, nameComponents.second, id, getVarCounter());
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700400 }
401 | "change" "subscription" subscriptionId = StringLiteral() <ON> nameComponents = QualifiedName()
402 <LEFTPAREN> (tmp = Expression()
403 {
404 argList.add(tmp);
405 }
406 (<COMMA> tmp = Expression()
407 {
408 argList.add(tmp);
409 }
410 )*)? <RIGHTPAREN>
411 <TO> brokerName = QualifiedName()
412 {
413 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
414 }
415 )
416 {
417 return stmt;
418 }
Dmitry Lychagined047f62019-11-26 15:03:35 -0800419}
420
421@new
422ChannelDropStatement DropChannelStatement(Token startStmtToken) throws ParseException:
423{
424 ChannelDropStatement stmt = null;
425 Pair<DataverseName,Identifier> pairId = null;
426 boolean ifExists = false;
427}
428{
Xikui Wang9d26e072020-08-20 21:18:04 -0700429 <CHANNEL> pairId = QualifiedName() ifExists = IfExists()
Dmitry Lychagined047f62019-11-26 15:03:35 -0800430 {
431 stmt = new ChannelDropStatement(pairId.first, pairId.second, ifExists);
432 return addSourceLocation(stmt, startStmtToken);
433 }
434}
435
436@new
437BrokerDropStatement DropBrokerStatement(Token startStmtToken) throws ParseException:
438{
439 BrokerDropStatement stmt = null;
440 Pair<DataverseName,Identifier> pairId = null;
441 boolean ifExists = false;
442}
443{
Xikui Wang9d26e072020-08-20 21:18:04 -0700444 <BROKER> pairId = QualifiedName() ifExists = IfExists()
Dmitry Lychagined047f62019-11-26 15:03:35 -0800445 {
446 stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists);
447 return addSourceLocation(stmt, startStmtToken);
448 }
449}
450
451@new
452ProcedureDropStatement DropProcedureStatement(Token startStmtToken) throws ParseException:
453{
454 ProcedureDropStatement stmt = null;
455 FunctionSignature funcSig = null;
456 boolean ifExists = false;
457}
458{
Xikui Wang9d26e072020-08-20 21:18:04 -0700459 <PROCEDURE> funcSig = FunctionSignature() ifExists = IfExists()
Dmitry Lychagined047f62019-11-26 15:03:35 -0800460 {
461 stmt = new ProcedureDropStatement(funcSig, ifExists);
462 return addSourceLocation(stmt, startStmtToken);
463 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700464}