Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 1 | import org.apache.asterix.bad.lang.statement.BrokerDropStatement; |
| 2 | import org.apache.asterix.bad.lang.statement.ChannelDropStatement; |
| 3 | import org.apache.asterix.bad.lang.statement.ChannelSubscribeStatement; |
| 4 | import org.apache.asterix.bad.lang.statement.ChannelUnsubscribeStatement; |
| 5 | import org.apache.asterix.bad.lang.statement.CreateBrokerStatement; |
| 6 | import org.apache.asterix.bad.lang.statement.CreateChannelStatement; |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 7 | import org.apache.asterix.bad.lang.statement.CreateProcedureStatement; |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 8 | |
| 9 | |
| 10 | @merge |
| 11 | Statement SingleStatement() throws ParseException: |
| 12 | { |
| 13 | // merge area 1 |
| 14 | before: |
| 15 | after: |
| 16 | } |
| 17 | { |
| 18 | ( |
| 19 | // merge area 2 |
| 20 | before: |
| 21 | after: | stmt = ChannelSubscriptionStatement()) |
| 22 | { |
| 23 | // merge area 3 |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | @merge |
| 28 | Statement CreateStatement() throws ParseException: |
| 29 | { |
| 30 | // merge area 1 |
| 31 | before: |
| 32 | after: |
| 33 | } |
| 34 | { |
| 35 | ( |
| 36 | // merge area 2 |
| 37 | before: |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 38 | after: | stmt = ChannelSpecification() | stmt = BrokerSpecification() | stmt = ProcedureSpecification()) |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 39 | { |
| 40 | // merge area 3 |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | @merge |
| 45 | Statement DropStatement() throws ParseException: |
| 46 | { |
| 47 | // merge area 1 |
| 48 | before: |
| 49 | after: |
| 50 | } |
| 51 | { |
| 52 | ( |
| 53 | // merge area 2 |
| 54 | before: |
| 55 | after: | "channel" pairId = QualifiedName() ifExists = IfExists() |
| 56 | { |
| 57 | stmt = new ChannelDropStatement(pairId.first, pairId.second, ifExists); |
| 58 | } |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 59 | | "broker" pairId = QualifiedName() ifExists = IfExists() |
| 60 | { |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 61 | stmt = new BrokerDropStatement(pairId.first, pairId.second, ifExists); |
| 62 | } |
| 63 | ) |
| 64 | { |
| 65 | // merge area 3 |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | @new |
| 70 | CreateChannelStatement ChannelSpecification() throws ParseException: |
| 71 | { |
| 72 | Pair<Identifier,Identifier> nameComponents = null; |
| 73 | FunctionSignature appliedFunction = null; |
| 74 | CreateChannelStatement ccs = null; |
| 75 | String fqFunctionName = null; |
| 76 | Expression period = null; |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 77 | boolean distributed = false; |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 78 | } |
| 79 | { |
| 80 | ( |
| 81 | "repetitive" "channel" nameComponents = QualifiedName() |
| 82 | <USING> appliedFunction = FunctionSignature() |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 83 | "period" period = FunctionCallExpr() ("distributed" { distributed = true; })? |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 84 | { |
| 85 | ccs = new CreateChannelStatement(nameComponents.first, |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 86 | nameComponents.second, appliedFunction, period, distributed); |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 87 | } |
| 88 | ) |
| 89 | { |
| 90 | return ccs; |
| 91 | } |
| 92 | } |
| 93 | |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 94 | |
| 95 | @new |
| 96 | CreateProcedureStatement ProcedureSpecification() throws ParseException: |
| 97 | { |
| 98 | Pair<Identifier,Identifier> nameComponents = null; |
| 99 | FunctionSignature signature; |
| 100 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 101 | String functionBody; |
| 102 | Token beginPos; |
| 103 | Token endPos; |
| 104 | Expression functionBodyExpr; |
| 105 | } |
| 106 | { |
| 107 | "procedure" nameComponents = QualifiedName() |
| 108 | paramList = ParameterList() |
| 109 | <LEFTBRACE> |
| 110 | { |
| 111 | beginPos = token; |
| 112 | } |
| 113 | functionBodyExpr = Expression() <RIGHTBRACE> |
| 114 | { |
| 115 | endPos = token; |
| 116 | functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn); |
| 117 | signature = new FunctionSignature(nameComponents.first.toString(), nameComponents.second.toString(), paramList.size()); |
| 118 | removeCurrentScope(); |
| 119 | return new CreateProcedureStatement(signature, paramList, functionBody); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 126 | @new |
| 127 | CreateBrokerStatement BrokerSpecification() throws ParseException: |
| 128 | { |
| 129 | CreateBrokerStatement cbs = null; |
| 130 | Pair<Identifier,Identifier> name = null; |
| 131 | String endPoint = null; |
| 132 | } |
| 133 | { |
| 134 | ( |
Steven Glenn Jacobs | d0ec837 | 2016-12-07 11:00:08 -0800 | [diff] [blame] | 135 | "broker" name = QualifiedName() |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 136 | <AT> endPoint = StringLiteral() |
| 137 | { |
| 138 | cbs = new CreateBrokerStatement(name.first, name.second,endPoint); |
| 139 | } |
| 140 | ) |
| 141 | { |
| 142 | return cbs; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | @new |
| 147 | Statement ChannelSubscriptionStatement() throws ParseException: |
| 148 | { |
| 149 | Statement stmt = null; |
| 150 | Pair<Identifier,Identifier> nameComponents = null; |
| 151 | List<Expression> argList = new ArrayList<Expression>(); |
| 152 | Expression tmp = null; |
| 153 | String id = null; |
| 154 | String subscriptionId = null; |
| 155 | Pair<Identifier,Identifier> brokerName = null; |
| 156 | } |
| 157 | { |
| 158 | ( |
| 159 | "subscribe" <TO> nameComponents = QualifiedName() |
| 160 | <LEFTPAREN> (tmp = Expression() |
| 161 | { |
| 162 | argList.add(tmp); |
| 163 | } |
| 164 | (<COMMA> tmp = Expression() |
| 165 | { |
| 166 | argList.add(tmp); |
| 167 | } |
| 168 | )*)? <RIGHTPAREN> <ON> brokerName = QualifiedName() |
| 169 | { |
| 170 | stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId); |
| 171 | } |
| 172 | | "unsubscribe" id = StringLiteral() <FROM> nameComponents = QualifiedName() |
| 173 | { |
| 174 | setDataverses(new ArrayList<String>()); |
| 175 | setDatasets(new ArrayList<String>()); |
| 176 | VariableExpr varExp = new VariableExpr(); |
| 177 | VarIdentifier var = new VarIdentifier(); |
| 178 | varExp.setVar(var); |
| 179 | var.setValue("$subscriptionPlaceholder"); |
| 180 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
| 181 | List<String> dataverses = getDataverses(); |
| 182 | List<String> datasets = getDatasets(); |
| 183 | // we remove the pointer to the dataverses and datasets |
| 184 | setDataverses(null); |
| 185 | setDatasets(null); |
| 186 | stmt = new ChannelUnsubscribeStatement(varExp, nameComponents.first, nameComponents.second, id, getVarCounter(), dataverses, datasets); |
| 187 | } |
| 188 | | "change" "subscription" subscriptionId = StringLiteral() <ON> nameComponents = QualifiedName() |
| 189 | <LEFTPAREN> (tmp = Expression() |
| 190 | { |
| 191 | argList.add(tmp); |
| 192 | } |
| 193 | (<COMMA> tmp = Expression() |
| 194 | { |
| 195 | argList.add(tmp); |
| 196 | } |
| 197 | )*)? <RIGHTPAREN> |
| 198 | <TO> brokerName = QualifiedName() |
| 199 | { |
| 200 | stmt = new ChannelSubscribeStatement(nameComponents.first, nameComponents.second, argList, getVarCounter(), brokerName.first, brokerName.second, subscriptionId); |
| 201 | } |
| 202 | ) |
| 203 | { |
| 204 | return stmt; |
| 205 | } |
Steven Glenn Jacobs | 409c3e7 | 2016-09-14 11:32:13 -0700 | [diff] [blame] | 206 | } |