blob: b433f5f7a1029a54a37f9bf42a3f9aba3ce484e8 [file] [log] [blame]
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -07001import org.apache.asterix.bad.lang.statement.BrokerDropStatement;
2import org.apache.asterix.bad.lang.statement.ChannelDropStatement;
3import org.apache.asterix.bad.lang.statement.ChannelSubscribeStatement;
4import org.apache.asterix.bad.lang.statement.ChannelUnsubscribeStatement;
5import org.apache.asterix.bad.lang.statement.CreateBrokerStatement;
6import org.apache.asterix.bad.lang.statement.CreateChannelStatement;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -08007import org.apache.asterix.bad.lang.statement.CreateProcedureStatement;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -08008import org.apache.asterix.bad.lang.statement.ExecuteProcedureStatement;
9import org.apache.asterix.bad.lang.statement.ProcedureDropStatement;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070010
11
12@merge
13Statement SingleStatement() throws ParseException:
14{
15 // merge area 1
16 before:
17 after:
18}
19{
20 (
21 // merge area 2
22 before:
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080023 after: | stmt = ChannelSubscriptionStatement() | stmt = ProcedureExecution())
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070024 {
25 // merge area 3
26 }
27}
28
29@merge
30Statement CreateStatement() throws ParseException:
31{
32 // merge area 1
33 before:
34 after:
35}
36{
37 (
38 // merge area 2
39 before:
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -080040 after: | stmt = ChannelSpecification() | stmt = BrokerSpecification() | stmt = ProcedureSpecification())
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070041 {
42 // merge area 3
43 }
44}
45
46@merge
47Statement DropStatement() throws ParseException:
48{
49 // merge area 1
50 before:
51 after:
52}
53{
54 (
55 // merge area 2
56 before:
57 after: | "channel" pairId = QualifiedName() ifExists = IfExists()
58 {
59 stmt = new ChannelDropStatement(pairId.first, pairId.second, ifExists);
60 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -080061 | "broker" pairId = QualifiedName() ifExists = IfExists()
62 {
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070063 stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists);
64 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080065 | "procedure" funcSig = FunctionSignature() ifExists = IfExists()
66 {
67 stmt = new ProcedureDropStatement(funcSig, ifExists);
68 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070069 )
70 {
71 // merge area 3
72 }
73}
74
75@new
76CreateChannelStatement ChannelSpecification() throws ParseException:
77{
78 Pair<Identifier,Identifier> nameComponents = null;
79 FunctionSignature appliedFunction = null;
80 CreateChannelStatement ccs = null;
81 String fqFunctionName = null;
82 Expression period = null;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080083 boolean distributed = true;
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070084}
85{
86 (
87 "repetitive" "channel" nameComponents = QualifiedName()
88 <USING> appliedFunction = FunctionSignature()
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -080089 "period" period = FunctionCallExpr() ("nondistributed" { distributed = false; })?
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070090 {
91 ccs = new CreateChannelStatement(nameComponents.first,
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -080092 nameComponents.second, appliedFunction, period, distributed);
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -070093 }
94 )
95 {
96 return ccs;
97 }
98}
99
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800100@new
101CreateProcedureStatement ProcedureSpecification() throws ParseException:
102{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800103 FunctionName fctName = null;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800104 FunctionSignature signature;
105 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
106 String functionBody;
107 Token beginPos;
108 Token endPos;
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800109 Statement functionBodyExpr;
110 Expression period = null;
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800111}
112{
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800113 "procedure" fctName = FunctionName()
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800114 paramList = ParameterList()
115 <LEFTBRACE>
116 {
117 beginPos = token;
118 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800119 functionBodyExpr = SingleStatement() <RIGHTBRACE>
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800120 {
121 endPos = token;
122 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800123 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800124 removeCurrentScope();
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800125 }
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800126 ("period" period = FunctionCallExpr())?
127 {
128 return new CreateProcedureStatement(signature, paramList, functionBody, period);
129 }
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800130}
131
Steven Glenn Jacobs79226b52017-02-23 21:13:42 -0800132@new
133ExecuteProcedureStatement ProcedureExecution() throws ParseException:
134{
135 ExecuteProcedureStatement callExpr;
136 List<Expression> argList = new ArrayList<Expression>();
137 Expression tmp;
138 int arity = 0;
139 FunctionName funcName = null;
140 String hint = null;
141}
142{
143 "execute"
144 funcName = FunctionName()
145 <LEFTPAREN> (tmp = Expression()
146 {
147 argList.add(tmp);
148 arity ++;
149 }
150 (<COMMA> tmp = Expression()
151 {
152 argList.add(tmp);
153 arity++;
154 }
155 )*)? <RIGHTPAREN>
156 {
157 String fqFunctionName = funcName.function;
158 return new ExecuteProcedureStatement(funcName.dataverse, fqFunctionName, arity);
159 }
160}
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800161
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700162@new
163CreateBrokerStatement BrokerSpecification() throws ParseException:
164{
165 CreateBrokerStatement cbs = null;
166 Pair<Identifier,Identifier> name = null;
167 String endPoint = null;
168}
169{
170 (
Steven Glenn Jacobsd0ec8372016-12-07 11:00:08 -0800171 "broker" name = QualifiedName()
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700172 <AT> endPoint = StringLiteral()
173 {
174 cbs = new CreateBrokerStatement(name.first, name.second,endPoint);
175 }
176 )
177 {
178 return cbs;
179 }
180}
181
182@new
183Statement ChannelSubscriptionStatement() throws ParseException:
184{
185 Statement stmt = null;
186 Pair<Identifier,Identifier> nameComponents = null;
187 List<Expression> argList = new ArrayList<Expression>();
188 Expression tmp = null;
189 String id = null;
190 String subscriptionId = null;
191 Pair<Identifier,Identifier> brokerName = null;
192}
193{
194 (
195 "subscribe" <TO> nameComponents = QualifiedName()
196 <LEFTPAREN> (tmp = Expression()
197 {
198 argList.add(tmp);
199 }
200 (<COMMA> tmp = Expression()
201 {
202 argList.add(tmp);
203 }
204 )*)? <RIGHTPAREN> <ON> brokerName = QualifiedName()
205 {
206 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
207 }
208 | "unsubscribe" id = StringLiteral() <FROM> nameComponents = QualifiedName()
209 {
210 setDataverses(new ArrayList<String>());
211 setDatasets(new ArrayList<String>());
212 VariableExpr varExp = new VariableExpr();
213 VarIdentifier var = new VarIdentifier();
214 varExp.setVar(var);
215 var.setValue("$subscriptionPlaceholder");
216 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
217 List<String> dataverses = getDataverses();
218 List<String> datasets = getDatasets();
219 // we remove the pointer to the dataverses and datasets
220 setDataverses(null);
221 setDatasets(null);
222 stmt = new ChannelUnsubscribeStatement(varExp, nameComponents.first, nameComponents.second, id, getVarCounter(), dataverses, datasets);
223 }
224 | "change" "subscription" subscriptionId = StringLiteral() <ON> nameComponents = QualifiedName()
225 <LEFTPAREN> (tmp = Expression()
226 {
227 argList.add(tmp);
228 }
229 (<COMMA> tmp = Expression()
230 {
231 argList.add(tmp);
232 }
233 )*)? <RIGHTPAREN>
234 <TO> brokerName = QualifiedName()
235 {
236 stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId);
237 }
238 )
239 {
240 return stmt;
241 }
Steven Glenn Jacobs409c3e72016-09-14 11:32:13 -0700242}