Steven Glenn Jacobs | 3982604 | 2017-03-28 20:28:27 -0700 | [diff] [blame] | 1 | // |
| 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 Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 20 | import org.apache.asterix.bad.lang.statement.BrokerDropStatement; |
| 21 | import org.apache.asterix.bad.lang.statement.ChannelDropStatement; |
| 22 | import org.apache.asterix.bad.lang.statement.ChannelSubscribeStatement; |
| 23 | import org.apache.asterix.bad.lang.statement.ChannelUnsubscribeStatement; |
| 24 | import org.apache.asterix.bad.lang.statement.CreateBrokerStatement; |
| 25 | import org.apache.asterix.bad.lang.statement.CreateChannelStatement; |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 26 | import org.apache.asterix.bad.lang.statement.CreateProcedureStatement; |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 27 | import org.apache.asterix.bad.lang.statement.ExecuteProcedureStatement; |
| 28 | import org.apache.asterix.bad.lang.statement.ProcedureDropStatement; |
Steven Glenn Jacobs | 5551404 | 2017-04-19 15:54:13 -0700 | [diff] [blame] | 29 | import org.apache.asterix.lang.sqlpp.parser.ParseException; |
| 30 | import org.apache.asterix.lang.sqlpp.parser.Token; |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 31 | |
| 32 | |
| 33 | @merge |
| 34 | Statement SingleStatement() throws ParseException: |
| 35 | { |
| 36 | // merge area 1 |
| 37 | before: |
| 38 | after: |
| 39 | } |
| 40 | { |
| 41 | ( |
| 42 | // merge area 2 |
| 43 | before: |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 44 | after: | stmt = ChannelSubscriptionStatement() | stmt = ProcedureExecution()) |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 45 | { |
| 46 | // merge area 3 |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | @merge |
| 51 | Statement CreateStatement() throws ParseException: |
| 52 | { |
| 53 | // merge area 1 |
| 54 | before: |
| 55 | after: |
| 56 | } |
| 57 | { |
| 58 | ( |
| 59 | // merge area 2 |
| 60 | before: |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 61 | after: | stmt = ChannelSpecification() | stmt = BrokerSpecification() | stmt = ProcedureSpecification()) |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 62 | { |
| 63 | // merge area 3 |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | @merge |
| 68 | Statement 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 Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 82 | | "broker" pairId = QualifiedName() ifExists = IfExists() |
| 83 | { |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 84 | stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists); |
| 85 | } |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 86 | | "procedure" funcSig = FunctionSignature() ifExists = IfExists() |
| 87 | { |
| 88 | stmt = new ProcedureDropStatement(funcSig, ifExists); |
| 89 | } |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 90 | ) |
| 91 | { |
| 92 | // merge area 3 |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | @new |
| 97 | CreateChannelStatement 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; |
| 104 | } |
| 105 | { |
| 106 | ( |
| 107 | "repetitive" "channel" nameComponents = QualifiedName() |
| 108 | <USING> appliedFunction = FunctionSignature() |
Steven Glenn Jacobs | 8b53ce5 | 2017-11-14 10:21:43 -0800 | [diff] [blame] | 109 | "period" period = FunctionCallExpr() |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 110 | { |
| 111 | ccs = new CreateChannelStatement(nameComponents.first, |
Steven Glenn Jacobs | 8b53ce5 | 2017-11-14 10:21:43 -0800 | [diff] [blame] | 112 | nameComponents.second, appliedFunction, period); |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 113 | } |
| 114 | ) |
| 115 | { |
| 116 | return ccs; |
| 117 | } |
| 118 | } |
| 119 | |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 120 | @new |
| 121 | CreateProcedureStatement ProcedureSpecification() throws ParseException: |
| 122 | { |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 123 | FunctionName fctName = null; |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 124 | FunctionSignature signature; |
| 125 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
Steven Glenn Jacobs | 8b53ce5 | 2017-11-14 10:21:43 -0800 | [diff] [blame] | 126 | List<Integer> paramIds = new ArrayList<Integer>(); |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 127 | String functionBody; |
| 128 | Token beginPos; |
| 129 | Token endPos; |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 130 | Statement functionBodyExpr; |
| 131 | Expression period = null; |
Steven Glenn Jacobs | 5b87065 | 2018-01-19 19:52:51 -0800 | [diff] [blame^] | 132 | String currentDataverse = defaultDataverse; |
| 133 | createNewScope(); |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 134 | } |
| 135 | { |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 136 | "procedure" fctName = FunctionName() |
Steven Glenn Jacobs | 5b87065 | 2018-01-19 19:52:51 -0800 | [diff] [blame^] | 137 | { |
| 138 | defaultDataverse = fctName.dataverse; |
| 139 | } |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 140 | paramList = ParameterList() |
| 141 | <LEFTBRACE> |
| 142 | { |
Steven Glenn Jacobs | 8b53ce5 | 2017-11-14 10:21:43 -0800 | [diff] [blame] | 143 | for (VarIdentifier param : paramList) |
| 144 | { |
| 145 | VarIdentifier v = new VarIdentifier(param.toString()); |
| 146 | getCurrentScope().addNewVarSymbolToScope(v); |
| 147 | paramIds.add(v.getId()); |
| 148 | } |
| 149 | beginPos = token; |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 150 | } |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 151 | functionBodyExpr = SingleStatement() <RIGHTBRACE> |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 152 | { |
| 153 | endPos = token; |
| 154 | functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn); |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 155 | signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size()); |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 156 | removeCurrentScope(); |
Steven Glenn Jacobs | 5b87065 | 2018-01-19 19:52:51 -0800 | [diff] [blame^] | 157 | defaultDataverse = currentDataverse; |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 158 | } |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 159 | ("period" period = FunctionCallExpr())? |
| 160 | { |
Steven Glenn Jacobs | 8b53ce5 | 2017-11-14 10:21:43 -0800 | [diff] [blame] | 161 | return new CreateProcedureStatement(signature, paramList, paramIds, functionBody, functionBodyExpr, period); |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 162 | } |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 163 | } |
| 164 | |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 165 | @new |
| 166 | ExecuteProcedureStatement ProcedureExecution() throws ParseException: |
| 167 | { |
| 168 | ExecuteProcedureStatement callExpr; |
| 169 | List<Expression> argList = new ArrayList<Expression>(); |
| 170 | Expression tmp; |
| 171 | int arity = 0; |
| 172 | FunctionName funcName = null; |
| 173 | String hint = null; |
| 174 | } |
| 175 | { |
| 176 | "execute" |
| 177 | funcName = FunctionName() |
| 178 | <LEFTPAREN> (tmp = Expression() |
| 179 | { |
| 180 | argList.add(tmp); |
| 181 | arity ++; |
| 182 | } |
| 183 | (<COMMA> tmp = Expression() |
| 184 | { |
| 185 | argList.add(tmp); |
| 186 | arity++; |
| 187 | } |
| 188 | )*)? <RIGHTPAREN> |
| 189 | { |
| 190 | String fqFunctionName = funcName.function; |
Steven Glenn Jacobs | 8b53ce5 | 2017-11-14 10:21:43 -0800 | [diff] [blame] | 191 | return new ExecuteProcedureStatement(funcName.dataverse, fqFunctionName, arity, argList); |
Steven Glenn Jacobs | 79226b5 | 2017-02-23 21:13:42 -0800 | [diff] [blame] | 192 | } |
| 193 | } |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 194 | |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 195 | @new |
| 196 | CreateBrokerStatement BrokerSpecification() throws ParseException: |
| 197 | { |
| 198 | CreateBrokerStatement cbs = null; |
| 199 | Pair<Identifier,Identifier> name = null; |
| 200 | String endPoint = null; |
| 201 | } |
| 202 | { |
| 203 | ( |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 204 | "broker" name = QualifiedName() |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 205 | <AT> endPoint = StringLiteral() |
| 206 | { |
| 207 | cbs = new CreateBrokerStatement(name.first, name.second,endPoint); |
| 208 | } |
| 209 | ) |
| 210 | { |
| 211 | return cbs; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | @new |
| 216 | Statement ChannelSubscriptionStatement() throws ParseException: |
| 217 | { |
| 218 | Statement stmt = null; |
| 219 | Pair<Identifier,Identifier> nameComponents = null; |
| 220 | List<Expression> argList = new ArrayList<Expression>(); |
| 221 | Expression tmp = null; |
| 222 | String id = null; |
| 223 | String subscriptionId = null; |
| 224 | Pair<Identifier,Identifier> brokerName = null; |
| 225 | } |
| 226 | { |
| 227 | ( |
| 228 | "subscribe" <TO> nameComponents = QualifiedName() |
| 229 | <LEFTPAREN> (tmp = Expression() |
| 230 | { |
| 231 | argList.add(tmp); |
| 232 | } |
| 233 | (<COMMA> tmp = Expression() |
| 234 | { |
| 235 | argList.add(tmp); |
| 236 | } |
| 237 | )*)? <RIGHTPAREN> <ON> brokerName = QualifiedName() |
| 238 | { |
| 239 | stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId); |
| 240 | } |
| 241 | | "unsubscribe" id = StringLiteral() <FROM> nameComponents = QualifiedName() |
| 242 | { |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 243 | VariableExpr varExp = new VariableExpr(); |
| 244 | VarIdentifier var = new VarIdentifier(); |
| 245 | varExp.setVar(var); |
| 246 | var.setValue("$subscriptionPlaceholder"); |
| 247 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
Steven Glenn Jacobs | d676726 | 2017-04-04 17:31:40 -0700 | [diff] [blame] | 248 | stmt = new ChannelUnsubscribeStatement(varExp, nameComponents.first, nameComponents.second, id, getVarCounter()); |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 249 | } |
| 250 | | "change" "subscription" subscriptionId = StringLiteral() <ON> nameComponents = QualifiedName() |
| 251 | <LEFTPAREN> (tmp = Expression() |
| 252 | { |
| 253 | argList.add(tmp); |
| 254 | } |
| 255 | (<COMMA> tmp = Expression() |
| 256 | { |
| 257 | argList.add(tmp); |
| 258 | } |
| 259 | )*)? <RIGHTPAREN> |
| 260 | <TO> brokerName = QualifiedName() |
| 261 | { |
| 262 | stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId); |
| 263 | } |
| 264 | ) |
| 265 | { |
| 266 | return stmt; |
| 267 | } |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 268 | } |