vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1 | options { |
| 2 | |
| 3 | |
| 4 | STATIC = false; |
| 5 | |
| 6 | } |
| 7 | |
| 8 | |
| 9 | PARSER_BEGIN(AQLParser) |
| 10 | |
| 11 | package edu.uci.ics.asterix.aql.parser; |
| 12 | |
| 13 | import java.io.*; |
| 14 | import java.util.List; |
| 15 | import java.util.ArrayList; |
| 16 | import java.util.Stack; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | import java.util.HashMap; |
diegogiorgini@gmail.com | eb1910e | 2013-02-14 07:43:00 +0000 | [diff] [blame] | 20 | import java.util.LinkedHashMap; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 21 | import edu.uci.ics.asterix.aql.literal.FloatLiteral; |
| 22 | import edu.uci.ics.asterix.aql.literal.DoubleLiteral; |
| 23 | import edu.uci.ics.asterix.aql.literal.FalseLiteral; |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 24 | import edu.uci.ics.asterix.aql.base.Literal; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 25 | import edu.uci.ics.asterix.aql.literal.IntegerLiteral; |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 26 | import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 27 | import edu.uci.ics.asterix.aql.literal.NullLiteral; |
| 28 | import edu.uci.ics.asterix.aql.literal.StringLiteral; |
| 29 | import edu.uci.ics.asterix.aql.literal.TrueLiteral; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 30 | import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 31 | |
| 32 | import edu.uci.ics.asterix.aql.base.*; |
| 33 | import edu.uci.ics.asterix.aql.expression.*; |
| 34 | import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType; |
| 35 | import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType; |
| 36 | import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor; |
| 37 | import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign; |
| 38 | import edu.uci.ics.asterix.aql.base.Statement.Kind; |
| 39 | import edu.uci.ics.asterix.aql.context.Scope; |
| 40 | import edu.uci.ics.asterix.aql.context.RootScopeFactory; |
| 41 | import edu.uci.ics.asterix.common.annotations.*; |
| 42 | import edu.uci.ics.asterix.common.exceptions.AsterixException; |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 43 | import edu.uci.ics.asterix.om.functions.AsterixFunction; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 44 | import edu.uci.ics.asterix.common.functions.FunctionSignature; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 45 | import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation; |
| 46 | import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 47 | import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; |
| 48 | import edu.uci.ics.hyracks.algebricks.common.utils.Pair; |
| 49 | import edu.uci.ics.hyracks.algebricks.common.utils.Triple; |
| 50 | |
| 51 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 52 | |
| 53 | |
| 54 | public class AQLParser extends ScopeChecker { |
| 55 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 56 | // optimizer hints |
| 57 | private static final String HASH_GROUP_BY_HINT = "hash"; |
| 58 | private static final String BROADCAST_JOIN_HINT = "bcast"; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 59 | private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl"; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 60 | private static final String INMEMORY_HINT = "inmem"; |
| 61 | private static final String VAL_FILE_HINT = "val-files"; |
| 62 | private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx"; |
| 63 | private static final String INTERVAL_HINT = "interval"; |
| 64 | private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files"; |
| 65 | private static final String INSERT_RAND_INT_HINT = "insert-rand-int"; |
| 66 | private static final String LIST_VAL_FILE_HINT = "list-val-file"; |
| 67 | private static final String LIST_HINT = "list"; |
| 68 | private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years"; |
| 69 | private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years"; |
| 70 | private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours"; |
| 71 | private static final String AUTO_HINT = "auto"; |
| 72 | |
| 73 | private static final String GEN_FIELDS_HINT = "gen-fields"; |
| 74 | |
| 75 | // data generator hints |
| 76 | private static final String DGEN_HINT = "dgen"; |
| 77 | |
| 78 | private static String getHint(Token t) { |
| 79 | if (t.specialToken == null) { |
| 80 | return null; |
| 81 | } |
| 82 | String s = t.specialToken.image; |
| 83 | int n = s.length(); |
| 84 | if (n < 2) { |
| 85 | return null; |
| 86 | } |
| 87 | return s.substring(1).trim(); |
| 88 | } |
| 89 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 90 | public AQLParser(String s){ |
| 91 | this(new StringReader(s)); |
| 92 | super.setInput(s); |
| 93 | } |
| 94 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 95 | public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException { |
| 96 | File file = new File(args[0]); |
| 97 | Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); |
| 98 | AQLParser parser = new AQLParser(fis); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 99 | List<Statement> st = parser.Statement(); |
| 100 | //st.accept(new AQLPrintVisitor(), 0); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
| 104 | } |
| 105 | |
| 106 | PARSER_END(AQLParser) |
| 107 | |
| 108 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 109 | List<Statement> Statement() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 110 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 111 | scopeStack.push(RootScopeFactory.createRootScope(this)); |
| 112 | List<Statement> decls = new ArrayList<Statement>(); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 113 | Query query=null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 114 | } |
| 115 | { |
| 116 | ( |
| 117 | ( |
| 118 | ( |
| 119 | "use" |
| 120 | { |
| 121 | decls.add(DataverseDeclaration()); |
| 122 | } |
| 123 | | "declare" "function" { |
| 124 | decls.add(FunctionDeclaration()); |
| 125 | } |
| 126 | | "create" ( |
| 127 | { |
| 128 | String hint = getHint(token); |
| 129 | boolean dgen = false; |
| 130 | if (hint != null && hint.startsWith(DGEN_HINT)) { |
| 131 | dgen = true; |
| 132 | } |
| 133 | } |
| 134 | "type" |
| 135 | { |
| 136 | decls.add(TypeDeclaration(dgen, hint)); |
| 137 | } |
| 138 | | "nodegroup" |
| 139 | { |
| 140 | decls.add(NodegroupDeclaration()); |
| 141 | } |
| 142 | | "external" <DATASET> |
| 143 | { |
| 144 | decls.add(DatasetDeclaration(DatasetType.EXTERNAL)); |
| 145 | } |
| 146 | | "feed" <DATASET> |
| 147 | { |
| 148 | decls.add(DatasetDeclaration(DatasetType.FEED)); |
| 149 | } |
| 150 | | <DATASET> |
| 151 | { |
| 152 | decls.add(DatasetDeclaration(DatasetType.INTERNAL)); |
| 153 | } |
| 154 | | "index" |
| 155 | { |
| 156 | decls.add(CreateIndexStatement()); |
| 157 | } |
| 158 | | "dataverse" |
| 159 | { |
| 160 | decls.add(CreateDataverseStatement()); |
| 161 | } |
| 162 | | "function" |
| 163 | { |
| 164 | decls.add(FunctionCreation()); |
| 165 | } |
| 166 | ) |
| 167 | | "load" { |
| 168 | decls.add(LoadStatement()); |
| 169 | } |
| 170 | |
| 171 | | "drop" |
| 172 | ( |
| 173 | <DATASET> |
| 174 | { |
| 175 | decls.add(DropStatement()); |
| 176 | } |
| 177 | | "index" |
| 178 | { |
| 179 | decls.add(IndexDropStatement()); |
| 180 | } |
| 181 | | "nodegroup" |
| 182 | { |
| 183 | decls.add(NodeGroupDropStatement()); |
| 184 | } |
| 185 | | "type" |
| 186 | { |
| 187 | decls.add(TypeDropStatement()); |
| 188 | } |
| 189 | | "dataverse" |
| 190 | { |
| 191 | decls.add(DataverseDropStatement()); |
| 192 | } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 193 | | "function" |
| 194 | { |
| 195 | decls.add(FunctionDropStatement()); |
| 196 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 197 | ) |
| 198 | | "write" { |
| 199 | decls.add(WriteStatement()); |
| 200 | } |
| 201 | | "set" { |
| 202 | decls.add(SetStatement()); |
| 203 | } |
| 204 | | "insert" { |
| 205 | decls.add(InsertStatement()); |
| 206 | } |
| 207 | | "delete" { |
| 208 | decls.add(DeleteStatement()); |
| 209 | } |
| 210 | | "update" { |
| 211 | decls.add(UpdateStatement()); |
| 212 | } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 213 | | "begin" "feed" |
| 214 | { |
| 215 | Pair<Identifier,Identifier> nameComponents = getDotSeparatedPair(); |
| 216 | decls.add(new BeginFeedStatement(nameComponents.first, nameComponents.second, getVarCounter())); |
| 217 | } ";" |
| 218 | |
| 219 | | "suspend" "feed" |
| 220 | { |
| 221 | decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.SUSPEND)); |
| 222 | } ";" |
| 223 | | "resume" "feed" { |
| 224 | decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.RESUME)); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 225 | } ";" |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 226 | | "end" "feed" { |
| 227 | decls.add(ControlFeedDeclaration(ControlFeedStatement.OperationType.END)); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 228 | } ";" |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 229 | | "alter" "feed" { |
| 230 | decls.add(AlterFeedDeclaration()); |
| 231 | } ";" |
| 232 | |
| 233 | | (query = Query()) { |
| 234 | decls.add(query); |
| 235 | } |
| 236 | )* |
| 237 | // (query = Query())? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 238 | ) |
| 239 | |
| 240 | <EOF> |
| 241 | ) |
| 242 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 243 | return decls; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | InsertStatement InsertStatement() throws ParseException: |
| 248 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 249 | Identifier dataverseName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 250 | Identifier datasetName; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 251 | Pair<Identifier,Identifier> nameComponents = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 252 | Query query; |
| 253 | } |
| 254 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 255 | "into" <DATASET> |
| 256 | |
| 257 | { |
| 258 | nameComponents = getDotSeparatedPair(); |
| 259 | dataverseName = nameComponents.first; |
| 260 | datasetName = nameComponents.second; |
| 261 | } |
| 262 | |
vinayakb | e2aaa38c | 2013-04-03 05:53:44 +0000 | [diff] [blame] | 263 | query = Query() (";")? |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 264 | {return new InsertStatement(dataverseName, datasetName, query, getVarCounter());} |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | DeleteStatement DeleteStatement() throws ParseException: |
| 268 | { |
| 269 | VariableExpr var = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 270 | Identifier dataverseName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 271 | Identifier datasetName = null; |
| 272 | Expression condition = null; |
| 273 | Clause dieClause = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 274 | Pair<Identifier, Identifier> nameComponents; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 275 | } |
| 276 | { |
| 277 | var = Variable() { getCurrentScope().addNewVarSymbolToScope(var.getVar()); } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 278 | "from" |
| 279 | <DATASET> |
| 280 | { |
| 281 | nameComponents = getDotSeparatedPair(); |
| 282 | } |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 283 | ("where" condition = Expression())? (dieClause = DieClause())? (";")? |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 284 | {return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, dieClause, getVarCounter()); } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | UpdateStatement UpdateStatement() throws ParseException: |
| 288 | { |
| 289 | VariableExpr vars; |
| 290 | Expression target; |
| 291 | Expression condition; |
| 292 | UpdateClause uc; |
| 293 | List<UpdateClause> ucs = new ArrayList<UpdateClause>(); |
| 294 | } |
| 295 | { |
| 296 | vars = Variable() "in" target = Expression() |
| 297 | "where" condition = Expression() |
| 298 | <LEFTPAREN> (uc=UpdateClause() {ucs.add(uc); } ("," uc=UpdateClause() {ucs.add(uc); } )*) <RIGHTPAREN> ";" |
| 299 | {return new UpdateStatement(vars, target, condition, ucs);} |
| 300 | } |
| 301 | |
| 302 | |
| 303 | |
| 304 | UpdateClause UpdateClause() throws ParseException: |
| 305 | { |
| 306 | Expression target = null; |
| 307 | Expression value = null ; |
| 308 | InsertStatement is = null; |
| 309 | DeleteStatement ds = null; |
| 310 | UpdateStatement us = null; |
| 311 | Expression condition = null; |
| 312 | UpdateClause ifbranch = null; |
| 313 | UpdateClause elsebranch = null; |
| 314 | } |
| 315 | { |
| 316 | "set" target = Expression() ":=" value = Expression() |
| 317 | | "insert" is = InsertStatement() |
| 318 | | "delete" ds = DeleteStatement() |
| 319 | | "update" us = UpdateStatement() |
| 320 | | "if" <LEFTPAREN> condition = Expression() <RIGHTPAREN> "then" ifbranch = UpdateClause() [LOOKAHEAD(1) "else" elsebranch = UpdateClause()] |
| 321 | {return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);} |
| 322 | } |
| 323 | |
| 324 | |
| 325 | Statement SetStatement() throws ParseException: |
| 326 | { |
| 327 | String pn = null; |
| 328 | Statement stmt = null; |
| 329 | } |
| 330 | { |
| 331 | <IDENTIFIER> { pn = token.image; } |
| 332 | <STRING_LITERAL> |
| 333 | { String pv = removeQuotesAndEscapes(token.image); } |
| 334 | ";" |
| 335 | { |
| 336 | return new SetStatement(pn, pv); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | Statement WriteStatement() throws ParseException: |
| 341 | { |
| 342 | Identifier nodeName = null; |
| 343 | String fileName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 344 | Statement stmt = null; |
| 345 | Query query; |
| 346 | String writerClass = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 347 | Pair<Identifier,Identifier> nameComponents = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 348 | } |
| 349 | { |
| 350 | (( "output" "to" |
| 351 | <IDENTIFIER> { nodeName = new Identifier(token.image); } |
| 352 | ":" <STRING_LITERAL> { fileName = removeQuotesAndEscapes(token.image); } |
| 353 | ( "using" <STRING_LITERAL> { writerClass = removeQuotesAndEscapes(token.image); } )? |
| 354 | { |
| 355 | stmt = new WriteStatement(nodeName, fileName, writerClass); |
| 356 | } ) |
| 357 | | |
| 358 | ( "into" |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 359 | <DATASET> |
| 360 | |
| 361 | { |
| 362 | nameComponents = getDotSeparatedPair(); |
| 363 | } |
| 364 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 365 | <LEFTPAREN> query = Query() <RIGHTPAREN> |
| 366 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 367 | stmt = new WriteFromQueryResultStatement(nameComponents.first, nameComponents.second, query, getVarCounter()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 368 | } )) |
| 369 | |
| 370 | ";" |
| 371 | { |
| 372 | return stmt; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | CreateIndexStatement CreateIndexStatement() throws ParseException: |
| 377 | { |
| 378 | CreateIndexStatement cis = new CreateIndexStatement(); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 379 | Pair<Identifier,Identifier> nameComponents = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 380 | } |
| 381 | { |
| 382 | <IDENTIFIER> { cis.setIndexName(new Identifier(token.image)); } |
| 383 | ( |
| 384 | "if not exists" |
| 385 | { |
| 386 | cis.setIfNotExists(true); |
| 387 | } |
| 388 | )? |
| 389 | "on" |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 390 | |
| 391 | { |
| 392 | nameComponents = getDotSeparatedPair(); |
| 393 | cis.setDataverseName(nameComponents.first); |
| 394 | cis.setDatasetName(nameComponents.second); |
| 395 | } |
| 396 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 397 | <LEFTPAREN> |
| 398 | ( <IDENTIFIER> { cis.addFieldExpr(token.image); } ) |
| 399 | ("," <IDENTIFIER> { cis.addFieldExpr(token.image); })* |
| 400 | <RIGHTPAREN> |
| 401 | ("type" |
alexander.behm | b742e09 | 2012-11-24 11:54:56 +0000 | [diff] [blame] | 402 | ("btree" { cis.setIndexType(IndexType.BTREE); } |
alexander.behm | c576c60 | 2012-07-06 02:41:15 +0000 | [diff] [blame] | 403 | | "rtree" { cis.setIndexType(IndexType.RTREE); } |
alexander.behm | b742e09 | 2012-11-24 11:54:56 +0000 | [diff] [blame] | 404 | | "keyword" { cis.setIndexType(IndexType.WORD_INVIX); } |
| 405 | | "fuzzy keyword" { cis.setIndexType(IndexType.FUZZY_WORD_INVIX); } |
alexander.behm | c576c60 | 2012-07-06 02:41:15 +0000 | [diff] [blame] | 406 | | "ngram" |
| 407 | <LEFTPAREN> |
| 408 | (<INTEGER_LITERAL> |
| 409 | { |
| 410 | cis.setIndexType(IndexType.NGRAM_INVIX); |
| 411 | cis.setGramLength(Integer.valueOf(token.image)); |
| 412 | } |
| 413 | ) |
alexander.behm | b742e09 | 2012-11-24 11:54:56 +0000 | [diff] [blame] | 414 | <RIGHTPAREN> |
| 415 | | "fuzzy ngram" |
| 416 | <LEFTPAREN> |
| 417 | (<INTEGER_LITERAL> |
| 418 | { |
| 419 | cis.setIndexType(IndexType.FUZZY_NGRAM_INVIX); |
| 420 | cis.setGramLength(Integer.valueOf(token.image)); |
| 421 | } |
| 422 | ) |
| 423 | <RIGHTPAREN> |
alexander.behm | c576c60 | 2012-07-06 02:41:15 +0000 | [diff] [blame] | 424 | ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 425 | ";" |
| 426 | | ";" |
| 427 | ) |
| 428 | { |
| 429 | return cis; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | DataverseDecl DataverseDeclaration() throws ParseException: |
| 434 | { |
| 435 | Identifier dvName = null; |
| 436 | } |
| 437 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 438 | "dataverse" <IDENTIFIER> { defaultDataverse = token.image;} |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 439 | ";" |
| 440 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 441 | return new DataverseDecl(new Identifier(defaultDataverse)); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
| 445 | DropStatement DropStatement() throws ParseException : |
| 446 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 447 | Identifier dataverseName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 448 | Identifier datasetName = null; |
| 449 | boolean ifExists = false; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 450 | Pair<Identifier,Identifier> nameComponents=null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 451 | } |
| 452 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 453 | { |
| 454 | nameComponents = getDotSeparatedPair(); |
| 455 | dataverseName = nameComponents.first; |
| 456 | datasetName = nameComponents.second; |
| 457 | } |
| 458 | |
| 459 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 460 | ( |
| 461 | "if exists" |
| 462 | { |
| 463 | ifExists = true; |
| 464 | } |
| 465 | )? ";" |
| 466 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 467 | return new DropStatement(dataverseName, datasetName, ifExists); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
| 471 | IndexDropStatement IndexDropStatement() throws ParseException : |
| 472 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 473 | Identifier dataverseName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 474 | Identifier datasetName = null; |
| 475 | Identifier indexName = null; |
| 476 | boolean ifExists = false; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 477 | Triple<Identifier,Identifier,Identifier> nameComponents=null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 478 | } |
| 479 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 480 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 481 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 482 | nameComponents = getDotSeparatedTriple(); |
| 483 | dataverseName = nameComponents.first; |
| 484 | datasetName = nameComponents.second; |
| 485 | indexName = nameComponents.third; |
| 486 | } |
| 487 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 488 | ( |
| 489 | "if exists" |
| 490 | { |
| 491 | ifExists = true; |
| 492 | } |
| 493 | )? ";" |
| 494 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 495 | return new IndexDropStatement(dataverseName, datasetName, indexName, ifExists); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | |
| 499 | NodeGroupDropStatement NodeGroupDropStatement() throws ParseException : |
| 500 | { |
| 501 | Identifier groupName = null; |
| 502 | boolean ifExists = false; |
| 503 | } |
| 504 | { |
| 505 | < IDENTIFIER > |
| 506 | { |
| 507 | groupName = new Identifier(token.image); |
| 508 | } |
| 509 | ( |
| 510 | "if exists" |
| 511 | { |
| 512 | ifExists = true; |
| 513 | } |
| 514 | )? ";" |
| 515 | { |
| 516 | return new NodeGroupDropStatement(groupName, ifExists); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | TypeDropStatement TypeDropStatement() throws ParseException : |
| 521 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 522 | Identifier dataverseName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 523 | Identifier typeName = null; |
| 524 | boolean ifExists = false; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 525 | Pair<Identifier,Identifier> nameComponents; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 526 | } |
| 527 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 528 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 529 | nameComponents = getDotSeparatedPair(); |
| 530 | dataverseName = nameComponents.first == null ? new Identifier(defaultDataverse) : nameComponents.first; |
| 531 | typeName = nameComponents.second; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 532 | } |
| 533 | ( |
| 534 | "if exists" |
| 535 | { |
| 536 | ifExists = true; |
| 537 | } |
| 538 | )? ";" |
| 539 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 540 | return new TypeDropStatement(dataverseName, typeName, ifExists); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
| 544 | DataverseDropStatement DataverseDropStatement() throws ParseException : |
| 545 | { |
| 546 | Identifier dataverseName = null; |
| 547 | boolean ifExists = false; |
| 548 | } |
| 549 | { |
| 550 | < IDENTIFIER > |
| 551 | { |
| 552 | dataverseName = new Identifier(token.image); |
| 553 | } |
| 554 | ( |
| 555 | "if exists" |
| 556 | { |
| 557 | ifExists = true; |
| 558 | } |
| 559 | )? ";" |
| 560 | { |
| 561 | return new DataverseDropStatement(dataverseName, ifExists); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | CreateDataverseStatement CreateDataverseStatement() throws ParseException : |
| 566 | { |
| 567 | Identifier dvName = null; |
| 568 | boolean ifNotExists = false; |
| 569 | String format = null; |
| 570 | } |
| 571 | { |
| 572 | < IDENTIFIER > |
| 573 | { |
| 574 | dvName = new Identifier(token.image); |
| 575 | } |
| 576 | ( |
| 577 | "if not exists" |
| 578 | { |
| 579 | ifNotExists = true; |
| 580 | } |
| 581 | )? |
| 582 | ( |
| 583 | "with format" < STRING_LITERAL > |
| 584 | { |
| 585 | format = removeQuotesAndEscapes(token.image); |
| 586 | } |
| 587 | )? |
| 588 | ";" |
| 589 | { |
| 590 | return new CreateDataverseStatement(dvName, format, ifNotExists); |
| 591 | } |
| 592 | } |
| 593 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 594 | |
| 595 | FunctionDropStatement FunctionDropStatement() throws ParseException : |
| 596 | { |
| 597 | String dataverse; |
| 598 | String functionName; |
| 599 | int arity=0; |
| 600 | boolean ifExists = false; |
| 601 | Pair<Identifier, Identifier> nameComponents=null; |
| 602 | } |
| 603 | { |
| 604 | { |
| 605 | nameComponents = getDotSeparatedPair(); |
| 606 | dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse; |
| 607 | functionName = nameComponents.second.getValue(); |
| 608 | } |
| 609 | |
| 610 | "@" |
| 611 | <INTEGER_LITERAL> |
| 612 | { |
| 613 | Token t= getToken(0); |
| 614 | arity = new Integer(t.image); |
| 615 | if( arity < 0 && arity != FunctionIdentifier.VARARGS){ |
| 616 | throw new ParseException(" invalid arity:" + arity); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | ( |
| 621 | "if exists" |
| 622 | { |
| 623 | ifExists = true; |
| 624 | } |
| 625 | )? ";" |
| 626 | { |
| 627 | return new FunctionDropStatement(new FunctionSignature(dataverse, functionName, arity), ifExists); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 632 | LoadFromFileStatement LoadStatement() throws ParseException: |
| 633 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 634 | Identifier dataverseName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 635 | Identifier datasetName = null; |
| 636 | boolean alreadySorted = false; |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 637 | String adapterName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 638 | Map<String,String> properties; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 639 | Pair<Identifier,Identifier> nameComponents = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 640 | } |
| 641 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 642 | <DATASET> |
| 643 | { |
| 644 | nameComponents = getDotSeparatedPair(); |
| 645 | dataverseName = nameComponents.first; |
| 646 | datasetName = nameComponents.second; |
| 647 | } |
| 648 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 649 | "using" |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 650 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 651 | { |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 652 | adapterName = getAdapterName(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 653 | } |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 654 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 655 | { |
| 656 | properties = getConfiguration(); |
| 657 | } |
| 658 | |
| 659 | ("pre-sorted" |
| 660 | { alreadySorted = true; } |
| 661 | )? |
| 662 | |
| 663 | ";" |
| 664 | { |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 665 | return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | |
| 669 | |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 670 | String getAdapterName() throws ParseException : |
| 671 | { |
| 672 | String adapterName = null; |
| 673 | } |
| 674 | { |
| 675 | ( |
| 676 | <IDENTIFIER> { |
| 677 | adapterName = (new Identifier(token.image)).getValue();; |
| 678 | } |
| 679 | | |
| 680 | <STRING_LITERAL> |
| 681 | { |
| 682 | adapterName = removeQuotesAndEscapes(token.image); |
| 683 | } |
| 684 | ) |
| 685 | { |
| 686 | return adapterName; |
| 687 | } |
| 688 | } |
| 689 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 690 | |
| 691 | DatasetDecl DatasetDeclaration(DatasetType datasetType) throws ParseException : |
| 692 | { |
| 693 | DatasetDecl dd = null; |
| 694 | Identifier datasetName = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 695 | Identifier dataverseName = null; |
| 696 | Identifier itemDataverseName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 697 | Identifier itemTypeName = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 698 | String nameComponentFirst = null; |
| 699 | String nameComponentSecond = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 700 | boolean ifNotExists = false; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 701 | IDatasetDetailsDecl datasetDetails = null; |
ramangrover29 | 71e5c6a | 2013-01-30 05:30:12 +0000 | [diff] [blame] | 702 | Pair<Identifier,Identifier> nameComponents = null; |
| 703 | Map<String,String> hints = new HashMap<String,String>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 704 | } |
| 705 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 706 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 707 | nameComponents = getDotSeparatedPair(); |
| 708 | dataverseName = nameComponents.first; |
| 709 | datasetName = nameComponents.second; |
| 710 | } |
| 711 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 712 | ( |
| 713 | "if not exists" |
| 714 | { |
| 715 | ifNotExists = true; |
| 716 | } |
| 717 | )? |
| 718 | ( |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 719 | < LEFTPAREN > <IDENTIFIER> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 720 | { |
| 721 | itemTypeName = new Identifier(token.image); |
| 722 | } |
| 723 | < RIGHTPAREN > |
RamanGrover29@gmail.com | c022a0d | 2012-07-28 05:13:44 +0000 | [diff] [blame] | 724 | ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 725 | { |
| 726 | if(datasetType == DatasetType.INTERNAL) { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 727 | datasetDetails = InternalDatasetDeclaration(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 728 | } |
| 729 | else if(datasetType == DatasetType.EXTERNAL) { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 730 | datasetDetails = ExternalDatasetDeclaration(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 731 | } |
| 732 | else if(datasetType == DatasetType.FEED) { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 733 | datasetDetails = FeedDatasetDeclaration(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 734 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 735 | } |
ramangrover29 | 71e5c6a | 2013-01-30 05:30:12 +0000 | [diff] [blame] | 736 | |
| 737 | ( |
| 738 | "hints" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 739 | { |
ramangrover29 | 71e5c6a | 2013-01-30 05:30:12 +0000 | [diff] [blame] | 740 | initProperties(hints); |
| 741 | } |
| 742 | )? |
| 743 | ";" |
| 744 | |
| 745 | { |
| 746 | dd = new DatasetDecl(dataverseName, datasetName, itemTypeName, hints, datasetType, datasetDetails,ifNotExists); |
| 747 | return dd; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | |
| 751 | InternalDetailsDecl InternalDatasetDeclaration() throws ParseException : |
| 752 | { |
| 753 | InternalDetailsDecl idd = null; |
ramangrover29 | 2f199b0 | 2013-02-13 05:32:01 +0000 | [diff] [blame] | 754 | List<String> primaryKeyFields = new ArrayList<String>(); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 755 | Identifier nodeGroupName=null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 756 | } |
| 757 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 758 | ( |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 759 | { |
ramangrover29 | 2f199b0 | 2013-02-13 05:32:01 +0000 | [diff] [blame] | 760 | primaryKeyFields = getPrimaryKeyFields(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 761 | } |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 762 | ) |
| 763 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 764 | ( |
| 765 | "on" < IDENTIFIER > |
| 766 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 767 | nodeGroupName = new Identifier(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 768 | } |
| 769 | )? |
ramangrover29 | 71e5c6a | 2013-01-30 05:30:12 +0000 | [diff] [blame] | 770 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 771 | { |
ramangrover29 | 2f199b0 | 2013-02-13 05:32:01 +0000 | [diff] [blame] | 772 | idd = new InternalDetailsDecl(nodeGroupName, primaryKeyFields); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 773 | return idd; |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | ExternalDetailsDecl ExternalDatasetDeclaration() throws ParseException : |
| 778 | { |
| 779 | ExternalDetailsDecl edd = null; |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 780 | String adapterName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 781 | Map < String, String > properties; |
| 782 | } |
| 783 | { |
| 784 | { |
| 785 | edd = new ExternalDetailsDecl(); |
| 786 | } |
| 787 | |
| 788 | "using" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 789 | { |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 790 | adapterName = getAdapterName(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | { |
| 794 | properties = getConfiguration(); |
| 795 | } |
| 796 | |
| 797 | { |
| 798 | edd = new ExternalDetailsDecl(); |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 799 | edd.setAdapter(adapterName); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 800 | edd.setProperties(properties); |
| 801 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 802 | |
| 803 | { |
| 804 | return edd; |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | FeedDetailsDecl FeedDatasetDeclaration() throws ParseException : |
| 809 | { |
| 810 | FeedDetailsDecl fdd = null; |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 811 | String adapterName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 812 | Map < String, String > properties; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 813 | Pair<Identifier,Identifier> nameComponents; |
ramangrover29 | 2f199b0 | 2013-02-13 05:32:01 +0000 | [diff] [blame] | 814 | List<String> primaryKeyFields = new ArrayList<String>(); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 815 | Identifier nodeGroupName=null; |
| 816 | FunctionSignature appliedFunction=null; |
| 817 | String dataverse; |
| 818 | String functionName; |
| 819 | int arity; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 820 | } |
| 821 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 822 | "using" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 823 | { |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 824 | adapterName = getAdapterName(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | { |
| 828 | properties = getConfiguration(); |
| 829 | } |
| 830 | |
| 831 | ("apply" "function" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 832 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 833 | nameComponents = getDotSeparatedPair(); |
| 834 | dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse; |
| 835 | functionName = nameComponents.second.getValue(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 836 | } |
ramangrover29 | fbaba5f | 2013-01-26 02:36:29 +0000 | [diff] [blame] | 837 | ("@" <INTEGER_LITERAL> |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 838 | { |
| 839 | arity = Integer.parseInt(token.image); |
| 840 | } |
| 841 | ) |
| 842 | |
| 843 | { |
| 844 | appliedFunction = new FunctionSignature(dataverse, functionName, arity); |
| 845 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 846 | )? |
| 847 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 848 | ( |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 849 | { |
ramangrover29 | 2f199b0 | 2013-02-13 05:32:01 +0000 | [diff] [blame] | 850 | primaryKeyFields = getPrimaryKeyFields(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 851 | } |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 852 | ) |
| 853 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 854 | ( |
| 855 | "on" < IDENTIFIER > |
| 856 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 857 | nodeGroupName = new Identifier(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 858 | } |
| 859 | )? |
ramangrover29 | 71e5c6a | 2013-01-30 05:30:12 +0000 | [diff] [blame] | 860 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 861 | { |
ramangrover29 | 2f199b0 | 2013-02-13 05:32:01 +0000 | [diff] [blame] | 862 | fdd = new FeedDetailsDecl(adapterName, properties, appliedFunction, nodeGroupName, primaryKeyFields); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 863 | return fdd; |
| 864 | } |
| 865 | } |
| 866 | |
ramangrover29 | 2f199b0 | 2013-02-13 05:32:01 +0000 | [diff] [blame] | 867 | List<String> getPrimaryKeyFields() throws ParseException : |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 868 | { |
ramangrover29 | 2f199b0 | 2013-02-13 05:32:01 +0000 | [diff] [blame] | 869 | List<String> primaryKeyFields = new ArrayList<String>(); |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 870 | } |
| 871 | { |
| 872 | |
| 873 | "primary" "key" |
| 874 | < IDENTIFIER > |
| 875 | { |
ramangrover29 | 2f199b0 | 2013-02-13 05:32:01 +0000 | [diff] [blame] | 876 | primaryKeyFields.add(token.image); |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 877 | } |
| 878 | ( |
| 879 | "," < IDENTIFIER > |
| 880 | { |
ramangrover29 | 2f199b0 | 2013-02-13 05:32:01 +0000 | [diff] [blame] | 881 | primaryKeyFields.add(token.image); |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 882 | } |
| 883 | )* |
| 884 | { |
ramangrover29 | 2f199b0 | 2013-02-13 05:32:01 +0000 | [diff] [blame] | 885 | return primaryKeyFields; |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | } |
| 889 | |
| 890 | |
| 891 | |
| 892 | |
| 893 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 894 | ControlFeedStatement ControlFeedDeclaration(ControlFeedStatement.OperationType operationType) throws ParseException : |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 895 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 896 | Pair<Identifier,Identifier> nameComponents = null; |
| 897 | } |
| 898 | { |
| 899 | { |
| 900 | nameComponents = getDotSeparatedPair(); |
| 901 | return new ControlFeedStatement(operationType, nameComponents.first, nameComponents.second); |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | |
| 906 | ControlFeedStatement AlterFeedDeclaration() throws ParseException : |
| 907 | { |
| 908 | Pair<Identifier,Identifier> nameComponents = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 909 | Map < String, String > configuration = new HashMap < String, String > (); |
| 910 | } |
| 911 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 912 | { |
| 913 | nameComponents = getDotSeparatedPair(); |
| 914 | } |
| 915 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 916 | "set" |
| 917 | { |
| 918 | configuration = getConfiguration(); |
| 919 | } |
ramangrover29 | fbaba5f | 2013-01-26 02:36:29 +0000 | [diff] [blame] | 920 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 921 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 922 | return new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
| 926 | Map<String,String> getConfiguration() throws ParseException : |
| 927 | { |
diegogiorgini@gmail.com | eb1910e | 2013-02-14 07:43:00 +0000 | [diff] [blame] | 928 | Map<String,String> configuration = new LinkedHashMap<String,String>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 929 | String key; |
| 930 | String value; |
| 931 | } |
| 932 | { |
| 933 | |
| 934 | <LEFTPAREN> |
| 935 | ( |
| 936 | ( |
| 937 | <LEFTPAREN> |
| 938 | ( |
| 939 | <STRING_LITERAL> |
| 940 | { |
| 941 | key = removeQuotesAndEscapes(token.image); |
| 942 | } |
| 943 | "=" <STRING_LITERAL> |
| 944 | { |
| 945 | value = removeQuotesAndEscapes(token.image); |
| 946 | } |
| 947 | ) |
| 948 | <RIGHTPAREN> |
| 949 | { |
| 950 | configuration.put(key, value); |
| 951 | } |
| 952 | ) |
| 953 | ( |
| 954 | "," <LEFTPAREN> |
| 955 | ( |
| 956 | <STRING_LITERAL> |
| 957 | { |
| 958 | key = removeQuotesAndEscapes(token.image); |
| 959 | } |
| 960 | "=" <STRING_LITERAL> |
| 961 | { |
| 962 | value = removeQuotesAndEscapes(token.image); |
| 963 | } |
| 964 | ) |
| 965 | <RIGHTPAREN> |
| 966 | { |
| 967 | configuration.put(key, value); |
| 968 | } |
| 969 | )* |
| 970 | )? |
| 971 | <RIGHTPAREN> |
| 972 | { |
| 973 | return configuration; |
| 974 | } |
| 975 | } |
| 976 | |
ramangrover29 | 71e5c6a | 2013-01-30 05:30:12 +0000 | [diff] [blame] | 977 | void initProperties(Map<String,String> properties) throws ParseException : |
| 978 | { |
| 979 | String key; |
| 980 | String value; |
| 981 | } |
| 982 | { |
| 983 | ( |
| 984 | <LEFTPAREN> |
| 985 | ( |
| 986 | <IDENTIFIER> |
| 987 | { |
| 988 | key = (new Identifier(token.image)).getValue(); |
| 989 | } |
| 990 | "=" |
| 991 | ( |
| 992 | (<STRING_LITERAL> |
| 993 | { |
| 994 | value = removeQuotesAndEscapes(token.image); |
| 995 | } |
| 996 | ) | |
| 997 | (<INTEGER_LITERAL> |
| 998 | { |
| 999 | try{ |
ramangrover29 | 21b8818 | 2013-01-31 00:51:19 +0000 | [diff] [blame] | 1000 | value = "" + Long.valueOf(token.image); |
ramangrover29 | 71e5c6a | 2013-01-30 05:30:12 +0000 | [diff] [blame] | 1001 | } catch (NumberFormatException nfe){ |
| 1002 | throw new ParseException("inapproriate value: " + token.image); |
| 1003 | } |
| 1004 | } |
| 1005 | ) |
| 1006 | ) |
| 1007 | { |
ramangrover29 | 54f1fc4 | 2013-02-09 00:46:26 +0000 | [diff] [blame] | 1008 | properties.put(key.toUpperCase(), value); |
ramangrover29 | 71e5c6a | 2013-01-30 05:30:12 +0000 | [diff] [blame] | 1009 | } |
| 1010 | ( |
| 1011 | "," |
| 1012 | ( |
| 1013 | <IDENTIFIER> |
| 1014 | { |
| 1015 | key = (new Identifier(token.image)).getValue(); |
| 1016 | } |
| 1017 | "=" |
| 1018 | ( |
| 1019 | (<STRING_LITERAL> |
| 1020 | { |
| 1021 | value = removeQuotesAndEscapes(token.image); |
| 1022 | } |
| 1023 | ) | |
| 1024 | (<INTEGER_LITERAL> |
| 1025 | { |
| 1026 | try{ |
ramangrover29 | 21b8818 | 2013-01-31 00:51:19 +0000 | [diff] [blame] | 1027 | value = "" + Long.valueOf(token.image); |
ramangrover29 | 71e5c6a | 2013-01-30 05:30:12 +0000 | [diff] [blame] | 1028 | } catch (NumberFormatException nfe){ |
| 1029 | throw new ParseException("inapproriate value: " + token.image); |
| 1030 | } |
| 1031 | } |
| 1032 | ) |
| 1033 | ) |
| 1034 | ) |
| 1035 | { |
ramangrover29 | 54f1fc4 | 2013-02-09 00:46:26 +0000 | [diff] [blame] | 1036 | properties.put(key.toUpperCase(), value); |
ramangrover29 | 71e5c6a | 2013-01-30 05:30:12 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | )* |
| 1040 | ) |
| 1041 | <RIGHTPAREN> |
| 1042 | )? |
| 1043 | } |
| 1044 | |
| 1045 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1046 | |
| 1047 | NodegroupDecl NodegroupDeclaration() throws ParseException : |
| 1048 | { |
| 1049 | Identifier name = null; |
| 1050 | List < Identifier > ncNames = new ArrayList < Identifier > (); |
| 1051 | boolean ifNotExists = false; |
| 1052 | } |
| 1053 | { |
| 1054 | < IDENTIFIER > |
| 1055 | { |
| 1056 | name = new Identifier(token.image); |
| 1057 | } |
| 1058 | ( |
| 1059 | "if not exists" |
| 1060 | { |
| 1061 | ifNotExists = true; |
| 1062 | } |
| 1063 | )? |
| 1064 | "on" < IDENTIFIER > |
| 1065 | { |
| 1066 | ncNames.add(new Identifier(token.image)); |
| 1067 | } |
| 1068 | ( |
| 1069 | "," < IDENTIFIER > |
| 1070 | { |
| 1071 | ncNames.add(new Identifier(token.image)); |
| 1072 | } |
| 1073 | )* |
| 1074 | ";" |
| 1075 | { |
| 1076 | return new NodegroupDecl(name, ncNames, ifNotExists); |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | |
| 1081 | TypeDecl TypeDeclaration(boolean dgen, String hint) throws ParseException: |
| 1082 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1083 | Identifier dataverse; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1084 | Identifier ident; |
| 1085 | TypeExpression typeExpr; |
| 1086 | boolean ifNotExists = false; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1087 | Pair<Identifier,Identifier> nameComponents=null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1088 | } |
| 1089 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1090 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1091 | nameComponents = getDotSeparatedPair(); |
| 1092 | dataverse = nameComponents.first; |
| 1093 | ident = nameComponents.second; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1094 | } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1095 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1096 | ( |
| 1097 | "if not exists" |
| 1098 | { |
| 1099 | ifNotExists = true; |
| 1100 | } |
| 1101 | )? |
| 1102 | "as" |
| 1103 | ( typeExpr = TypeExpr() ) |
RamanGrover29@gmail.com | c022a0d | 2012-07-28 05:13:44 +0000 | [diff] [blame] | 1104 | (";")? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1105 | { |
| 1106 | long numValues = -1; |
| 1107 | String filename = null; |
| 1108 | if (dgen) { |
| 1109 | String splits[] = hint.split(" +"); |
| 1110 | if (splits.length != 3) { |
| 1111 | throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */"); |
| 1112 | } |
| 1113 | filename = splits[1]; |
| 1114 | numValues = Long.parseLong(splits[2]); |
| 1115 | } |
| 1116 | TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1117 | return new TypeDecl(dataverse, ident, typeExpr, tddg, ifNotExists); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | TypeExpression TypeExpr() throws ParseException: |
| 1122 | { |
| 1123 | TypeExpression typeExpr = null; |
| 1124 | } |
| 1125 | { |
| 1126 | ( |
| 1127 | typeExpr = RecordTypeDef() |
| 1128 | | typeExpr = TypeReference() |
| 1129 | | typeExpr = OrderedListTypeDef() |
| 1130 | | typeExpr = UnorderedListTypeDef() |
| 1131 | ) |
| 1132 | { |
| 1133 | return typeExpr; |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | RecordTypeDefinition RecordTypeDef() throws ParseException: |
| 1138 | { |
| 1139 | RecordTypeDefinition recType = new RecordTypeDefinition(); |
| 1140 | RecordTypeDefinition.RecordKind recordKind = null; |
| 1141 | } |
| 1142 | { |
| 1143 | ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; } |
| 1144 | | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )? |
| 1145 | "{" |
| 1146 | { |
| 1147 | String hint = getHint(token); |
| 1148 | if (hint != null) { |
| 1149 | String splits[] = hint.split(" +"); |
| 1150 | if (splits[0].equals(GEN_FIELDS_HINT)) { |
| 1151 | if (splits.length != 5) { |
| 1152 | throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/"); |
| 1153 | } |
| 1154 | if (!splits[1].equals("int")) { |
| 1155 | throw new ParseException("The only supported type for gen-fields is int."); |
| 1156 | } |
| 1157 | UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT, |
| 1158 | Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]); |
| 1159 | recType.setUndeclaredFieldsDataGen(ufdg); |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | } |
| 1164 | ( |
| 1165 | RecordField(recType) |
| 1166 | ( "," RecordField(recType) )* |
| 1167 | )? |
| 1168 | "}" |
| 1169 | { |
| 1170 | if (recordKind == null) { |
| 1171 | recordKind = RecordTypeDefinition.RecordKind.OPEN; |
| 1172 | } |
| 1173 | recType.setRecordKind(recordKind); |
| 1174 | return recType; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | void RecordField(RecordTypeDefinition recType) throws ParseException: |
| 1179 | { |
| 1180 | String fieldName; |
| 1181 | TypeExpression type = null; |
| 1182 | boolean nullable = false; |
| 1183 | } |
| 1184 | { |
| 1185 | <IDENTIFIER> |
| 1186 | { |
| 1187 | Token t = getToken(0); |
| 1188 | fieldName = t.toString(); |
| 1189 | String hint = getHint(t); |
| 1190 | IRecordFieldDataGen rfdg = null; |
| 1191 | if (hint != null) { |
| 1192 | String splits[] = hint.split(" +"); |
| 1193 | if (splits[0].equals(VAL_FILE_HINT)) { |
| 1194 | File[] valFiles = new File[splits.length - 1]; |
| 1195 | for (int k=1; k<splits.length; k++) { |
| 1196 | valFiles[k-1] = new File(splits[k]); |
| 1197 | } |
| 1198 | rfdg = new FieldValFileDataGen(valFiles); |
| 1199 | } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) { |
| 1200 | rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]); |
| 1201 | } else if (splits[0].equals(LIST_VAL_FILE_HINT)) { |
| 1202 | rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3])); |
| 1203 | } else if (splits[0].equals(LIST_HINT)) { |
| 1204 | rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 1205 | } else if (splits[0].equals(INTERVAL_HINT)) { |
| 1206 | FieldIntervalDataGen.ValueType vt; |
| 1207 | if (splits[1].equals("int")) { |
| 1208 | vt = FieldIntervalDataGen.ValueType.INT; |
| 1209 | } else if (splits[1].equals("long")) { |
| 1210 | vt = FieldIntervalDataGen.ValueType.LONG; |
| 1211 | } else if (splits[1].equals("float")) { |
| 1212 | vt = FieldIntervalDataGen.ValueType.FLOAT; |
| 1213 | } else if (splits[1].equals("double")) { |
| 1214 | vt = FieldIntervalDataGen.ValueType.DOUBLE; |
| 1215 | } else { |
| 1216 | throw new ParseException("Unknown type for interval data gen: " + splits[1]); |
| 1217 | } |
| 1218 | rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]); |
| 1219 | } else if (splits[0].equals(INSERT_RAND_INT_HINT)) { |
| 1220 | rfdg = new InsertRandIntDataGen(splits[1], splits[2]); |
| 1221 | } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) { |
| 1222 | rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 1223 | } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) { |
| 1224 | rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 1225 | } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) { |
| 1226 | rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]); |
| 1227 | } else if (splits[0].equals(AUTO_HINT)) { |
| 1228 | rfdg = new AutoDataGen(splits[1]); |
| 1229 | } |
| 1230 | } |
| 1231 | } |
| 1232 | ":" |
| 1233 | ( type = TypeExpr() ) |
| 1234 | ("?" { nullable = true; } )? |
| 1235 | { |
| 1236 | recType.addField(fieldName, type, nullable, rfdg); |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | TypeReferenceExpression TypeReference() throws ParseException: |
| 1241 | {} |
| 1242 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1243 | <IDENTIFIER> |
| 1244 | { |
| 1245 | Token t = getToken(0); |
| 1246 | Identifier id = new Identifier(t.toString()); |
| 1247 | return new TypeReferenceExpression(id); |
| 1248 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | OrderedListTypeDefinition OrderedListTypeDef() throws ParseException: |
| 1252 | { |
| 1253 | TypeExpression type = null; |
| 1254 | } |
| 1255 | { |
| 1256 | "[" |
| 1257 | ( type = TypeExpr() ) |
| 1258 | "]" |
| 1259 | { |
| 1260 | return new OrderedListTypeDefinition(type); |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | |
| 1265 | UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException: |
| 1266 | { |
| 1267 | TypeExpression type = null; |
| 1268 | } |
| 1269 | { |
| 1270 | "{{" |
| 1271 | ( type = TypeExpr() ) |
| 1272 | "}}" |
| 1273 | { |
| 1274 | return new UnorderedListTypeDefinition(type); |
| 1275 | } |
| 1276 | } |
| 1277 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1278 | Pair<Identifier,Identifier> getDotSeparatedPair() throws ParseException: |
| 1279 | { |
| 1280 | Identifier first = null; |
| 1281 | Identifier second = null; |
| 1282 | } |
| 1283 | { |
| 1284 | < IDENTIFIER > |
| 1285 | { |
| 1286 | first = new Identifier(token.image); |
| 1287 | } |
| 1288 | ("." <IDENTIFIER> |
| 1289 | { |
| 1290 | second = new Identifier(token.image); |
| 1291 | } |
| 1292 | )? |
| 1293 | |
| 1294 | { |
| 1295 | if(second == null){ |
| 1296 | second = first; |
| 1297 | first = null; |
| 1298 | } |
| 1299 | |
| 1300 | return new Pair<Identifier,Identifier>(first,second); |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | Triple<Identifier,Identifier,Identifier> getDotSeparatedTriple() throws ParseException: |
| 1305 | { |
| 1306 | Identifier first = null; |
| 1307 | Identifier second = null; |
| 1308 | Identifier third = null; |
| 1309 | } |
| 1310 | { |
| 1311 | < IDENTIFIER > |
| 1312 | { |
| 1313 | first = new Identifier(token.image); |
| 1314 | } |
| 1315 | "." <IDENTIFIER> |
| 1316 | { |
| 1317 | second = new Identifier(token.image); |
| 1318 | } |
| 1319 | ( |
| 1320 | "." <IDENTIFIER> |
| 1321 | { |
| 1322 | third = new Identifier(token.image); |
| 1323 | } |
| 1324 | )? |
| 1325 | |
| 1326 | { |
| 1327 | if(third == null){ |
| 1328 | third = second; |
| 1329 | second = first; |
| 1330 | first = null; |
| 1331 | } |
| 1332 | |
| 1333 | return new Triple<Identifier,Identifier,Identifier>(first,second,third); |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | |
| 1338 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1339 | |
| 1340 | FunctionDecl FunctionDeclaration() throws ParseException: |
| 1341 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1342 | FunctionDecl funcDecl; |
| 1343 | FunctionSignature signature; |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1344 | String functionName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1345 | int arity = 0; |
| 1346 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 1347 | Expression funcBody; |
| 1348 | VarIdentifier var = null; |
| 1349 | createNewScope(); |
| 1350 | } |
| 1351 | { |
| 1352 | |
| 1353 | <IDENTIFIER> |
| 1354 | { |
| 1355 | Token t = getToken(0); |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1356 | functionName = t.toString(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1357 | } |
| 1358 | <LEFTPAREN> (<VARIABLE> |
| 1359 | { |
| 1360 | var = new VarIdentifier(); |
| 1361 | var.setValue(getToken(0).toString()); |
| 1362 | paramList.add(var); |
| 1363 | getCurrentScope().addNewVarSymbolToScope(var); |
| 1364 | arity++; |
| 1365 | } |
| 1366 | ("," <VARIABLE> |
| 1367 | { |
| 1368 | var = new VarIdentifier(); |
| 1369 | var.setValue(getToken(0).toString()); |
| 1370 | paramList.add(var); |
| 1371 | getCurrentScope().addNewVarSymbolToScope(var); |
| 1372 | arity++; |
| 1373 | })*)? <RIGHTPAREN> "{" funcBody = Expression() "}" |
ramangrover29@gmail.com | f18c14b | 2013-04-10 16:26:57 +0000 | [diff] [blame] | 1374 | (";")? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1375 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1376 | signature = new FunctionSignature(defaultDataverse, functionName, arity); |
| 1377 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 1378 | funcDecl = new FunctionDecl(signature, paramList, funcBody); |
| 1379 | return funcDecl; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | CreateFunctionStatement FunctionCreation() throws ParseException: |
| 1384 | { |
| 1385 | CreateFunctionStatement cfs = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1386 | FunctionSignature signature; |
| 1387 | String dataverse; |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1388 | String functionName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1389 | boolean ifNotExists = false; |
| 1390 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1391 | String functionBody; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1392 | VarIdentifier var = null; |
| 1393 | createNewScope(); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1394 | Expression functionBodyExpr; |
| 1395 | Token beginPos; |
| 1396 | Token endPos; |
| 1397 | Pair<Identifier,Identifier> nameComponents=null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1398 | } |
| 1399 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1400 | { |
| 1401 | nameComponents = getDotSeparatedPair(); |
| 1402 | dataverse = nameComponents.first != null ? nameComponents.first.getValue() : defaultDataverse; |
| 1403 | functionName= nameComponents.second.getValue(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | ( |
| 1407 | "if not exists" |
| 1408 | { |
| 1409 | ifNotExists = true; |
| 1410 | } |
| 1411 | )? |
| 1412 | |
| 1413 | <LEFTPAREN> (<VARIABLE> |
| 1414 | { |
| 1415 | var = new VarIdentifier(); |
| 1416 | var.setValue(getToken(0).toString()); |
| 1417 | paramList.add(var); |
| 1418 | getCurrentScope().addNewVarSymbolToScope(var); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1419 | } |
| 1420 | ("," <VARIABLE> |
| 1421 | { |
| 1422 | var = new VarIdentifier(); |
| 1423 | var.setValue(getToken(0).toString()); |
| 1424 | paramList.add(var); |
| 1425 | getCurrentScope().addNewVarSymbolToScope(var); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1426 | })*)? <RIGHTPAREN> "{" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1427 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1428 | beginPos = getToken(0); |
| 1429 | } |
| 1430 | functionBodyExpr = Expression() |
ramangrover29@gmail.com | f18c14b | 2013-04-10 16:26:57 +0000 | [diff] [blame] | 1431 | "}" |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1432 | { |
| 1433 | endPos = getToken(0); |
| 1434 | functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn); |
| 1435 | } |
ramangrover29@gmail.com | f18c14b | 2013-04-10 16:26:57 +0000 | [diff] [blame] | 1436 | (";")? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1437 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1438 | signature = new FunctionSignature(dataverse, functionName, paramList.size()); |
| 1439 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 1440 | cfs = new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1441 | return cfs; |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | |
| 1446 | |
| 1447 | Query Query()throws ParseException: |
| 1448 | { |
| 1449 | Query query = new Query(); |
| 1450 | Expression expr; |
| 1451 | } |
| 1452 | { |
| 1453 | expr = Expression() |
RamanGrover29@gmail.com | c022a0d | 2012-07-28 05:13:44 +0000 | [diff] [blame] | 1454 | (";")? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1455 | { |
| 1456 | query.setBody(expr); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1457 | query.setVarCounter(getVarCounter()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1458 | return query; |
| 1459 | } |
RamanGrover29@gmail.com | c022a0d | 2012-07-28 05:13:44 +0000 | [diff] [blame] | 1460 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | |
| 1464 | |
| 1465 | Expression Expression(): |
| 1466 | { |
| 1467 | Expression expr = null; |
| 1468 | Expression exprP = null; |
| 1469 | } |
| 1470 | { |
| 1471 | ( |
| 1472 | |
| 1473 | //OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression |
| 1474 | expr = OperatorExpr() |
| 1475 | | expr = IfThenElse() |
| 1476 | | expr = FLWOGR() |
| 1477 | | expr = QuantifiedExpression() |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1478 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1479 | |
| 1480 | ) |
| 1481 | { |
| 1482 | return (exprP==null) ? expr : exprP; |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | |
| 1487 | |
| 1488 | Expression OperatorExpr()throws ParseException: |
| 1489 | { |
| 1490 | OperatorExpr op = null; |
| 1491 | Expression operand = null; |
| 1492 | } |
| 1493 | { |
| 1494 | operand = AndExpr() |
| 1495 | ( |
| 1496 | |
| 1497 | "or" |
| 1498 | { |
| 1499 | if (op == null) { |
| 1500 | op = new OperatorExpr(); |
| 1501 | op.addOperand(operand); |
| 1502 | op.setCurrentop(true); |
| 1503 | } |
| 1504 | Token t = getToken(0); |
| 1505 | op.addOperator(t.toString()); |
| 1506 | } |
| 1507 | |
| 1508 | operand = AndExpr() |
| 1509 | { |
| 1510 | op.addOperand(operand); |
| 1511 | } |
| 1512 | |
| 1513 | )* |
| 1514 | |
| 1515 | { |
| 1516 | return op==null? operand: op; |
| 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | Expression AndExpr()throws ParseException: |
| 1521 | { |
| 1522 | OperatorExpr op = null; |
| 1523 | Expression operand = null; |
| 1524 | } |
| 1525 | { |
| 1526 | operand = RelExpr() |
| 1527 | ( |
| 1528 | |
| 1529 | "and" |
| 1530 | { |
| 1531 | if (op == null) { |
| 1532 | op = new OperatorExpr(); |
| 1533 | op.addOperand(operand); |
| 1534 | op.setCurrentop(true); |
| 1535 | } |
| 1536 | Token t = getToken(0); |
| 1537 | op.addOperator(t.toString()); |
| 1538 | } |
| 1539 | |
| 1540 | operand = RelExpr() |
| 1541 | { |
| 1542 | op.addOperand(operand); |
| 1543 | } |
| 1544 | |
| 1545 | )* |
| 1546 | |
| 1547 | { |
| 1548 | return op==null? operand: op; |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | |
| 1553 | |
| 1554 | Expression RelExpr()throws ParseException: |
| 1555 | { |
| 1556 | OperatorExpr op = null; |
| 1557 | Expression operand = null; |
| 1558 | boolean broadcast = false; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1559 | IExpressionAnnotation annotation = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1560 | } |
| 1561 | { |
| 1562 | operand = AddExpr() |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1563 | { |
| 1564 | if (operand instanceof VariableExpr) { |
| 1565 | String hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1566 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1567 | broadcast = true; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1568 | } |
| 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | ( |
| 1573 | LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=") |
| 1574 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1575 | String mhint = getHint(token); |
| 1576 | if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 1577 | annotation = IndexedNLJoinExpressionAnnotation.INSTANCE; |
| 1578 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1579 | if (op == null) { |
| 1580 | op = new OperatorExpr(); |
| 1581 | op.addOperand(operand, broadcast); |
| 1582 | op.setCurrentop(true); |
| 1583 | broadcast = false; |
| 1584 | } |
| 1585 | Token t = getToken(0); |
| 1586 | op.addOperator(t.toString()); |
| 1587 | } |
| 1588 | |
| 1589 | operand = AddExpr() |
| 1590 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1591 | broadcast = false; |
| 1592 | if (operand instanceof VariableExpr) { |
| 1593 | String hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1594 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1595 | broadcast = true; |
| 1596 | } |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1597 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1598 | op.addOperand(operand, broadcast); |
| 1599 | } |
| 1600 | )? |
| 1601 | |
| 1602 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1603 | if (annotation != null) { |
| 1604 | op.addHint(annotation); |
| 1605 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1606 | return op==null? operand: op; |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | Expression AddExpr()throws ParseException: |
| 1611 | { |
| 1612 | OperatorExpr op = null; |
| 1613 | Expression operand = null; |
| 1614 | } |
| 1615 | { |
| 1616 | operand = MultExpr() |
| 1617 | |
| 1618 | ( ("+" | "-") |
| 1619 | { |
| 1620 | if (op == null) { |
| 1621 | op = new OperatorExpr(); |
| 1622 | op.addOperand(operand); |
| 1623 | op.setCurrentop(true); |
| 1624 | } |
| 1625 | Token t = getToken(0); |
| 1626 | ((OperatorExpr)op).addOperator(t.toString()); |
| 1627 | } |
| 1628 | |
| 1629 | operand = MultExpr() |
| 1630 | { |
| 1631 | op.addOperand(operand); |
| 1632 | } |
| 1633 | )* |
| 1634 | |
| 1635 | { |
| 1636 | return op==null? operand: op; |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | Expression MultExpr()throws ParseException: |
| 1641 | { |
| 1642 | OperatorExpr op = null; |
| 1643 | Expression operand = null; |
| 1644 | } |
| 1645 | { |
| 1646 | operand = UnionExpr() |
| 1647 | |
| 1648 | (( "*" | "/" | "%" | <CARET> | "idiv") |
| 1649 | { |
| 1650 | if (op == null) { |
| 1651 | op = new OperatorExpr(); |
| 1652 | op.addOperand(operand); |
| 1653 | op.setCurrentop(true); |
| 1654 | } |
| 1655 | Token t = getToken(0); |
| 1656 | op.addOperator(t.toString()); |
| 1657 | } |
| 1658 | operand = UnionExpr() |
| 1659 | { |
| 1660 | op.addOperand(operand); |
| 1661 | } |
| 1662 | )* |
| 1663 | |
| 1664 | { |
| 1665 | return op==null?operand:op; |
| 1666 | } |
| 1667 | } |
| 1668 | |
| 1669 | Expression UnionExpr() throws ParseException: |
| 1670 | { |
| 1671 | UnionExpr union = null; |
| 1672 | Expression operand1 = null; |
| 1673 | Expression operand2 = null; |
| 1674 | } |
| 1675 | { |
| 1676 | operand1 = UnaryExpr() |
| 1677 | ("union" |
| 1678 | (operand2 = UnaryExpr()) { |
| 1679 | if (union == null) { |
| 1680 | union = new UnionExpr(); |
| 1681 | union.addExpr(operand1); |
| 1682 | } |
| 1683 | union.addExpr(operand2); |
| 1684 | } )* |
| 1685 | { |
| 1686 | return (union == null)? operand1: union; |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | Expression UnaryExpr() throws ParseException: |
| 1691 | { |
| 1692 | Expression uexpr = null; |
| 1693 | Expression expr = null; |
| 1694 | } |
| 1695 | { |
| 1696 | (( "+"|"-") |
| 1697 | { |
| 1698 | uexpr = new UnaryExpr(); |
| 1699 | Token t = getToken(0); |
| 1700 | if("+".equals(t.toString())) |
| 1701 | ((UnaryExpr)uexpr).setSign(Sign.POSITIVE); |
| 1702 | else if("-".equals(t.toString())) |
| 1703 | ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE); |
| 1704 | else |
| 1705 | throw new ParseException(); |
| 1706 | } |
| 1707 | )? |
| 1708 | |
| 1709 | expr = ValueExpr() |
| 1710 | { |
| 1711 | if(uexpr!=null){ |
| 1712 | ((UnaryExpr)uexpr).setExpr(expr); |
| 1713 | return uexpr; |
| 1714 | } |
| 1715 | else{ |
| 1716 | return expr; |
| 1717 | } |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | Expression ValueExpr() throws ParseException: |
| 1722 | { |
| 1723 | Expression expr; |
| 1724 | } |
| 1725 | { |
| 1726 | expr = FieldOrIndexAccessor() |
| 1727 | { |
| 1728 | return expr; |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | |
| 1733 | Expression FieldOrIndexAccessor()throws ParseException: |
| 1734 | { |
| 1735 | Expression expr = null; |
| 1736 | Identifier ident = null; |
| 1737 | AbstractAccessor fa = null; |
| 1738 | int index; |
| 1739 | |
| 1740 | } |
| 1741 | { |
| 1742 | ( expr = PrimaryExpr() |
| 1743 | |
| 1744 | ) |
| 1745 | |
| 1746 | |
| 1747 | ( |
| 1748 | ( |
| 1749 | ident = Field() |
| 1750 | { |
| 1751 | if(fa == null) |
| 1752 | fa = new FieldAccessor(expr, ident); |
| 1753 | else |
| 1754 | fa = new FieldAccessor(fa, ident); |
| 1755 | } |
| 1756 | ) |
| 1757 | | ( |
| 1758 | index = Index() |
| 1759 | { |
| 1760 | if(fa == null) |
| 1761 | fa = new IndexAccessor(expr, index); |
| 1762 | else |
| 1763 | fa = new IndexAccessor(fa, index); |
| 1764 | } |
| 1765 | ) |
| 1766 | )* |
| 1767 | |
| 1768 | |
| 1769 | { |
| 1770 | return fa==null?expr:fa; |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | Identifier Field() throws ParseException: |
| 1775 | { |
| 1776 | Identifier ident = null; |
| 1777 | |
| 1778 | } |
| 1779 | { |
| 1780 | "." < IDENTIFIER > |
| 1781 | { |
| 1782 | |
| 1783 | ident = new Identifier(); |
| 1784 | ident.setValue(getToken(0).toString()); |
| 1785 | |
| 1786 | return ident; |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | int Index() throws ParseException: |
| 1791 | { |
| 1792 | Expression expr = null; |
| 1793 | int idx = -2; |
| 1794 | } |
| 1795 | { |
| 1796 | "[" ( expr = Expression() |
| 1797 | { |
| 1798 | if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION) |
| 1799 | { |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 1800 | Literal lit = ((LiteralExpr)expr).getValue(); |
| 1801 | if(lit.getLiteralType() == Literal.Type.INTEGER || |
| 1802 | lit.getLiteralType() == Literal.Type.LONG) { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1803 | idx = Integer.valueOf(lit.getStringValue()); |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 1804 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1805 | else { |
| 1806 | throw new ParseException("Index should be an INTEGER"); |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | } |
| 1811 | |
| 1812 | | "?" |
| 1813 | { |
| 1814 | idx = IndexAccessor.ANY; |
| 1815 | // ANY |
| 1816 | } |
| 1817 | |
| 1818 | ) |
| 1819 | |
| 1820 | "]" |
| 1821 | { |
| 1822 | return idx; |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | |
| 1827 | Expression PrimaryExpr()throws ParseException: |
| 1828 | { |
| 1829 | Expression expr = null; |
| 1830 | } |
| 1831 | { |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1832 | //Literal | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | DatasetAccessExpression | ParenthesizedExpression |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1833 | ( |
| 1834 | expr =Literal() |
| 1835 | | expr = FunctionCallExpr() |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1836 | | expr = DatasetAccessExpression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1837 | | expr =VariableRef() |
| 1838 | |
| 1839 | { |
| 1840 | if(((VariableExpr)expr).getIsNewVar() == true) |
| 1841 | throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar()); |
| 1842 | } |
| 1843 | | expr = ListConstructor() |
| 1844 | | expr = RecordConstructor() |
| 1845 | | expr = ParenthesizedExpression() |
| 1846 | ) |
| 1847 | { |
| 1848 | return expr; |
| 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | Expression Literal() throws ParseException: |
| 1853 | { |
| 1854 | |
| 1855 | LiteralExpr lit = new LiteralExpr(); |
| 1856 | Token t; |
| 1857 | } |
| 1858 | { |
| 1859 | ( |
| 1860 | <STRING_LITERAL> |
| 1861 | { |
| 1862 | t= getToken(0); |
| 1863 | lit.setValue( new StringLiteral(removeQuotesAndEscapes(t.image))); |
| 1864 | } |
| 1865 | |
| 1866 | | <INTEGER_LITERAL> |
| 1867 | { |
| 1868 | t= getToken(0); |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 1869 | try { |
| 1870 | lit.setValue(new IntegerLiteral(new Integer(t.image))); |
| 1871 | } catch(NumberFormatException ex) { |
| 1872 | lit.setValue(new LongIntegerLiteral(new Long(t.image))); |
| 1873 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1874 | } |
| 1875 | | < FLOAT_LITERAL > |
| 1876 | { |
| 1877 | t= getToken(0); |
| 1878 | lit.setValue(new FloatLiteral(new Float(t.image))); |
| 1879 | } |
| 1880 | | < DOUBLE_LITERAL > |
| 1881 | { |
| 1882 | t= getToken(0); |
| 1883 | lit.setValue(new DoubleLiteral(new Double(t.image))); |
| 1884 | } |
| 1885 | | <NULL> |
| 1886 | { |
| 1887 | t= getToken(0); |
| 1888 | lit.setValue(NullLiteral.INSTANCE); |
| 1889 | } |
| 1890 | | <TRUE> |
| 1891 | { |
| 1892 | t= getToken(0); |
| 1893 | lit.setValue(TrueLiteral.INSTANCE); |
| 1894 | } |
| 1895 | | <FALSE> |
| 1896 | { |
| 1897 | t= getToken(0); |
| 1898 | lit.setValue(FalseLiteral.INSTANCE); |
| 1899 | } |
| 1900 | ) |
| 1901 | { |
| 1902 | return lit; |
| 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | |
| 1907 | VariableExpr VariableRef() throws ParseException: |
| 1908 | { |
| 1909 | VariableExpr varExp = new VariableExpr(); |
| 1910 | VarIdentifier var = new VarIdentifier(); |
| 1911 | Token t; |
| 1912 | } |
| 1913 | { |
| 1914 | <VARIABLE> |
| 1915 | { |
| 1916 | t = getToken(0);//get current token |
| 1917 | String varName = t.toString(); |
| 1918 | Identifier ident = lookupSymbol(varName); |
| 1919 | if (isInForbiddenScopes(varName)) { |
| 1920 | throw new ParseException("Inside limit clauses, it is disallowed to reference a variable having the same name as any variable bound in the same scope as the limit clause."); |
| 1921 | } |
| 1922 | if(ident != null) { // exist such ident |
| 1923 | varExp.setIsNewVar(false); |
| 1924 | varExp.setVar((VarIdentifier)ident); |
| 1925 | } else { |
| 1926 | varExp.setVar(var); |
| 1927 | } |
| 1928 | var.setValue(t.toString()); |
| 1929 | return varExp; |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | |
| 1934 | VariableExpr Variable() throws ParseException: |
| 1935 | { |
| 1936 | VariableExpr varExp = new VariableExpr(); |
| 1937 | VarIdentifier var = new VarIdentifier(); |
| 1938 | Token t; |
| 1939 | } |
| 1940 | { |
| 1941 | <VARIABLE> |
| 1942 | { |
| 1943 | t = getToken(0);//get current token |
| 1944 | Identifier ident = lookupSymbol(t.toString()); |
| 1945 | if(ident != null) { // exist such ident |
| 1946 | varExp.setIsNewVar(false); |
| 1947 | } |
| 1948 | varExp.setVar(var); |
| 1949 | var.setValue(t.toString()); |
| 1950 | return varExp; |
| 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | Expression ListConstructor() throws ParseException: |
| 1955 | { |
| 1956 | Expression expr = null; |
| 1957 | } |
| 1958 | { |
| 1959 | ( |
| 1960 | expr = OrderedListConstructor() | expr = UnorderedListConstructor() |
| 1961 | ) |
| 1962 | |
| 1963 | { |
| 1964 | return expr; |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | |
| 1969 | ListConstructor OrderedListConstructor() throws ParseException: |
| 1970 | { |
| 1971 | ListConstructor expr = new ListConstructor(); |
| 1972 | Expression tmp = null; |
| 1973 | List<Expression> exprList = new ArrayList<Expression>(); |
| 1974 | expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR); |
| 1975 | } |
| 1976 | { |
| 1977 | |
| 1978 | "[" |
| 1979 | ( tmp = Expression() |
| 1980 | { |
| 1981 | exprList.add(tmp); |
| 1982 | } |
| 1983 | |
| 1984 | ("," tmp = Expression() { exprList.add(tmp); })* |
| 1985 | )? |
| 1986 | |
| 1987 | "]" |
| 1988 | |
| 1989 | { |
| 1990 | expr.setExprList(exprList); |
| 1991 | return expr; |
| 1992 | } |
| 1993 | } |
| 1994 | |
| 1995 | ListConstructor UnorderedListConstructor() throws ParseException: |
| 1996 | { |
| 1997 | ListConstructor expr = new ListConstructor(); |
| 1998 | Expression tmp = null; |
| 1999 | List<Expression> exprList = new ArrayList<Expression>(); |
| 2000 | expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR); |
| 2001 | } |
| 2002 | { |
| 2003 | |
| 2004 | "{{" ( tmp = Expression() |
| 2005 | { |
| 2006 | exprList.add(tmp); |
| 2007 | } |
| 2008 | ("," tmp = Expression() { exprList.add(tmp); })*)? "}}" |
| 2009 | { |
| 2010 | expr.setExprList(exprList); |
| 2011 | return expr; |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | RecordConstructor RecordConstructor() throws ParseException: |
| 2016 | { |
| 2017 | RecordConstructor expr = new RecordConstructor(); |
| 2018 | FieldBinding tmp = null; |
| 2019 | List<FieldBinding> fbList = new ArrayList<FieldBinding>(); |
| 2020 | } |
| 2021 | { |
| 2022 | "{" (tmp = FieldBinding() |
| 2023 | { |
| 2024 | fbList.add(tmp); |
| 2025 | } |
| 2026 | ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}" |
| 2027 | { |
| 2028 | expr.setFbList(fbList); |
| 2029 | return expr; |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | FieldBinding FieldBinding() throws ParseException: |
| 2034 | { |
| 2035 | FieldBinding fb = new FieldBinding(); |
| 2036 | Expression left, right; |
| 2037 | } |
| 2038 | { |
| 2039 | left = Expression() ":" right = Expression() |
| 2040 | { |
| 2041 | fb.setLeftExpr(left); |
| 2042 | fb.setRightExpr(right); |
| 2043 | return fb; |
| 2044 | } |
| 2045 | } |
| 2046 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 2047 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2048 | Expression FunctionCallExpr() throws ParseException: |
| 2049 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 2050 | CallExpr callExpr; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 2051 | List<Expression> argList = new ArrayList<Expression>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2052 | Expression tmp; |
| 2053 | int arity = 0; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 2054 | String funcName; |
| 2055 | String dataverse; |
| 2056 | String hint=null; |
| 2057 | String id1=null; |
| 2058 | String id2=null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2059 | } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 2060 | { |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 2061 | |
| 2062 | <IDENTIFIER> { dataverse = defaultDataverse; funcName = token.image;} ("." <IDENTIFIER> { dataverse = funcName; funcName = token.image;})? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2063 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 2064 | hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2065 | } |
| 2066 | <LEFTPAREN> (tmp = Expression() |
| 2067 | { |
| 2068 | argList.add(tmp); |
| 2069 | arity ++; |
| 2070 | } ("," tmp = Expression() { argList.add(tmp); arity++; })*)? <RIGHTPAREN> |
| 2071 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 2072 | { |
| 2073 | FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity); |
| 2074 | if(signature == null) |
| 2075 | { |
| 2076 | signature = new FunctionSignature(dataverse, funcName.toString(), arity); |
| 2077 | } |
| 2078 | callExpr = new CallExpr(signature,argList); |
| 2079 | if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 2080 | callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE); |
| 2081 | } |
| 2082 | return callExpr; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2083 | } |
| 2084 | } |
| 2085 | |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 2086 | Expression DatasetAccessExpression() throws ParseException: |
| 2087 | { |
| 2088 | CallExpr callExpr; |
| 2089 | List<Expression> argList = new ArrayList<Expression>(); |
| 2090 | String funcName; |
| 2091 | String dataverse; |
| 2092 | LiteralExpr ds; |
| 2093 | LiteralExpr dvds; |
| 2094 | Expression nameArg; |
| 2095 | int arity = 0; |
| 2096 | } |
| 2097 | { |
| 2098 | <DATASET> {dataverse = MetadataConstants.METADATA_DATAVERSE_NAME; funcName = getToken(0).toString();} |
| 2099 | ( |
| 2100 | (<IDENTIFIER> {ds = new LiteralExpr(); ds.setValue( new StringLiteral(token.image) ); argList.add(ds); arity ++;} ("." <IDENTIFIER> { dvds = new LiteralExpr(); dvds.setValue(new StringLiteral(ds.getValue()+"."+token.image)); argList.remove(0); argList.add(dvds);})? ) | |
| 2101 | (<LEFTPAREN> nameArg = Expression() {argList.add(nameArg); arity ++;} ("," nameArg = Expression() { argList.add(nameArg); arity++; })* <RIGHTPAREN>) |
| 2102 | ) |
| 2103 | |
| 2104 | { |
| 2105 | FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity); |
| 2106 | if(signature == null) |
| 2107 | { |
| 2108 | signature = new FunctionSignature(dataverse, funcName.toString(), arity); |
| 2109 | } |
| 2110 | callExpr = new CallExpr(signature,argList); |
| 2111 | return callExpr; |
| 2112 | } |
| 2113 | } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 2114 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2115 | Expression ParenthesizedExpression() throws ParseException: |
| 2116 | { |
| 2117 | Expression expr; |
| 2118 | } |
| 2119 | { |
| 2120 | <LEFTPAREN> expr = Expression() <RIGHTPAREN> |
| 2121 | { |
| 2122 | return expr; |
| 2123 | } |
| 2124 | } |
| 2125 | |
| 2126 | Expression IfThenElse() throws ParseException: |
| 2127 | { |
| 2128 | Expression condExpr; |
| 2129 | Expression thenExpr; |
| 2130 | Expression elseExpr; |
| 2131 | IfExpr ifExpr = new IfExpr(); |
| 2132 | } |
| 2133 | { |
| 2134 | "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression() |
| 2135 | |
| 2136 | { |
| 2137 | ifExpr.setCondExpr(condExpr); |
| 2138 | ifExpr.setThenExpr(thenExpr); |
| 2139 | ifExpr.setElseExpr(elseExpr); |
| 2140 | return ifExpr; |
| 2141 | } |
| 2142 | } |
| 2143 | |
| 2144 | Expression FLWOGR() throws ParseException: |
| 2145 | { |
| 2146 | FLWOGRExpression flworg = new FLWOGRExpression(); |
| 2147 | List<Clause> clauseList = new ArrayList<Clause>(); |
| 2148 | Expression returnExpr; |
| 2149 | Clause tmp; |
| 2150 | createNewScope(); |
| 2151 | } |
| 2152 | { |
| 2153 | (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);}) |
| 2154 | (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression() |
| 2155 | |
| 2156 | { |
| 2157 | flworg.setClauseList(clauseList); |
| 2158 | flworg.setReturnExpr(returnExpr); |
| 2159 | removeCurrentScope(); |
| 2160 | return flworg; |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | Clause Clause()throws ParseException : |
| 2165 | { |
| 2166 | Clause clause; |
| 2167 | } |
| 2168 | { |
| 2169 | ( |
| 2170 | clause = ForClause() |
| 2171 | | clause = LetClause() |
| 2172 | | clause = WhereClause() |
| 2173 | | clause = OrderbyClause() |
| 2174 | | clause = GroupClause() |
| 2175 | | clause = LimitClause() |
| 2176 | | clause = DistinctClause() |
| 2177 | | clause = DieClause() |
| 2178 | ) |
| 2179 | { |
| 2180 | return clause; |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | Clause ForClause()throws ParseException : |
| 2185 | { |
| 2186 | ForClause fc = new ForClause(); |
| 2187 | VariableExpr varExp; |
| 2188 | VariableExpr varPos = null; |
| 2189 | Expression inExp; |
| 2190 | extendCurrentScope(); |
| 2191 | } |
| 2192 | { |
| 2193 | "for" varExp = Variable() |
| 2194 | { |
| 2195 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
| 2196 | } |
| 2197 | ("at" varPos = Variable() |
| 2198 | { |
| 2199 | getCurrentScope().addNewVarSymbolToScope(varPos.getVar()); |
| 2200 | } |
| 2201 | )? |
| 2202 | "in" ( inExp = Expression() ) |
| 2203 | { |
| 2204 | fc.setVarExpr(varExp); |
| 2205 | fc.setInExpr(inExp); |
| 2206 | if (varPos != null) { |
| 2207 | fc.setPosExpr(varPos); |
| 2208 | } |
| 2209 | return fc; |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | Clause LetClause() throws ParseException: |
| 2214 | { |
| 2215 | LetClause lc = new LetClause(); |
| 2216 | VariableExpr varExp; |
| 2217 | Expression beExp; |
| 2218 | extendCurrentScope(); |
| 2219 | } |
| 2220 | { |
ilovesoup | b2527c1 | 2012-07-12 03:21:13 +0000 | [diff] [blame] | 2221 | "let" varExp = Variable() ":=" beExp = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2222 | { |
| 2223 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2224 | lc.setVarExpr(varExp); |
| 2225 | lc.setBeExpr(beExp); |
| 2226 | return lc; |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | Clause WhereClause()throws ParseException : |
| 2231 | { |
| 2232 | WhereClause wc = new WhereClause(); |
| 2233 | Expression whereExpr; |
| 2234 | } |
| 2235 | { |
| 2236 | "where" whereExpr = Expression() |
| 2237 | { |
| 2238 | wc.setWhereExpr(whereExpr); |
| 2239 | return wc; |
| 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | Clause OrderbyClause()throws ParseException : |
| 2244 | { |
| 2245 | OrderbyClause oc = new OrderbyClause(); |
| 2246 | Expression orderbyExpr; |
| 2247 | List<Expression> orderbyList = new ArrayList<Expression>(); |
| 2248 | List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >(); |
| 2249 | int numOfOrderby = 0; |
| 2250 | } |
| 2251 | { |
| 2252 | ( |
| 2253 | "order" |
| 2254 | { |
| 2255 | String hint = getHint(token); |
| 2256 | if (hint != null && hint.startsWith(INMEMORY_HINT)) { |
| 2257 | String splits[] = hint.split(" +"); |
| 2258 | int numFrames = Integer.parseInt(splits[1]); |
| 2259 | int numTuples = Integer.parseInt(splits[2]); |
| 2260 | oc.setNumFrames(numFrames); |
| 2261 | oc.setNumTuples(numTuples); |
| 2262 | } |
| 2263 | } |
| 2264 | "by" orderbyExpr = Expression() |
| 2265 | { |
| 2266 | orderbyList.add(orderbyExpr); |
| 2267 | OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC; |
| 2268 | } |
| 2269 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 2270 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 2271 | { |
| 2272 | modifierList.add(modif); |
| 2273 | } |
| 2274 | |
| 2275 | ("," orderbyExpr = Expression() |
| 2276 | { |
| 2277 | orderbyList.add(orderbyExpr); |
| 2278 | modif = OrderbyClause.OrderModifier.ASC; |
| 2279 | } |
| 2280 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 2281 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 2282 | { |
| 2283 | modifierList.add(modif); |
| 2284 | } |
| 2285 | )* |
| 2286 | ) |
| 2287 | { |
| 2288 | oc.setModifierList(modifierList); |
| 2289 | oc.setOrderbyList(orderbyList); |
| 2290 | return oc; |
| 2291 | } |
| 2292 | } |
| 2293 | Clause GroupClause()throws ParseException : |
| 2294 | { |
| 2295 | GroupbyClause gbc = new GroupbyClause(); |
| 2296 | // GbyVariableExpressionPair pair = new GbyVariableExpressionPair(); |
| 2297 | List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>(); |
| 2298 | List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>(); |
| 2299 | List<VariableExpr> withVarList= new ArrayList<VariableExpr>(); |
| 2300 | VariableExpr var = null; |
| 2301 | VariableExpr withVar = null; |
| 2302 | Expression expr = null; |
| 2303 | VariableExpr decorVar = null; |
| 2304 | Expression decorExpr = null; |
| 2305 | } |
| 2306 | { |
| 2307 | { |
| 2308 | Scope newScope = extendCurrentScopeNoPush(true); |
| 2309 | // extendCurrentScope(true); |
| 2310 | } |
| 2311 | "group" |
| 2312 | { |
| 2313 | String hint = getHint(token); |
| 2314 | if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) { |
| 2315 | gbc.setHashGroupByHint(true); |
| 2316 | } |
| 2317 | } |
| 2318 | "by" (LOOKAHEAD(2) var = Variable() |
| 2319 | { |
| 2320 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 2321 | } ":=")? |
| 2322 | expr = Expression() |
| 2323 | { |
| 2324 | GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr); |
| 2325 | vePairList.add(pair1); |
| 2326 | } |
| 2327 | ("," ( LOOKAHEAD(2) var = Variable() |
| 2328 | { |
| 2329 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 2330 | } ":=")? |
| 2331 | expr = Expression() |
| 2332 | { |
| 2333 | GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr); |
| 2334 | vePairList.add(pair2); |
| 2335 | } |
| 2336 | )* |
| 2337 | ("decor" decorVar = Variable() ":=" decorExpr = Expression() |
| 2338 | { |
| 2339 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 2340 | GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 2341 | decorPairList.add(pair3); |
| 2342 | } |
| 2343 | ("," "decor" decorVar = Variable() ":=" decorExpr = Expression() |
| 2344 | { |
| 2345 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 2346 | GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 2347 | decorPairList.add(pair4); |
| 2348 | } |
| 2349 | )* |
| 2350 | )? |
| 2351 | "with" withVar = VariableRef() |
| 2352 | { |
| 2353 | if(withVar.getIsNewVar()==true) |
| 2354 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 2355 | withVarList.add(withVar); |
| 2356 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 2357 | } |
| 2358 | ("," withVar = VariableRef() |
| 2359 | { |
| 2360 | if(withVar.getIsNewVar()==true) |
| 2361 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 2362 | withVarList.add(withVar); |
| 2363 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 2364 | })* |
| 2365 | { |
| 2366 | gbc.setGbyPairList(vePairList); |
| 2367 | gbc.setDecorPairList(decorPairList); |
| 2368 | gbc.setWithVarList(withVarList); |
| 2369 | replaceCurrentScope(newScope); |
| 2370 | return gbc; |
| 2371 | } |
| 2372 | } |
| 2373 | |
| 2374 | |
| 2375 | LimitClause LimitClause() throws ParseException: |
| 2376 | { |
| 2377 | LimitClause lc = new LimitClause(); |
| 2378 | Expression expr; |
| 2379 | pushForbiddenScope(getCurrentScope()); |
| 2380 | } |
| 2381 | { |
| 2382 | "limit" expr = Expression() { lc.setLimitExpr(expr); } |
| 2383 | ("offset" expr = Expression() { lc.setOffset(expr); })? |
| 2384 | |
| 2385 | { |
| 2386 | popForbiddenScope(); |
| 2387 | return lc; |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | DistinctClause DistinctClause() throws ParseException: |
| 2392 | { |
| 2393 | List<Expression> exprs = new ArrayList<Expression>(); |
| 2394 | Expression expr; |
| 2395 | } |
| 2396 | { |
| 2397 | "distinct" "by" expr = Expression() |
| 2398 | { |
| 2399 | exprs.add(expr); |
| 2400 | } |
| 2401 | ("," expr = Expression() |
| 2402 | { |
| 2403 | exprs.add(expr); |
| 2404 | } |
| 2405 | )* |
| 2406 | { |
| 2407 | return new DistinctClause(exprs); |
| 2408 | } |
| 2409 | } |
| 2410 | |
| 2411 | DieClause DieClause() throws ParseException: |
| 2412 | { |
| 2413 | DieClause lc = new DieClause(); |
| 2414 | Expression expr; |
| 2415 | pushForbiddenScope(getCurrentScope()); |
| 2416 | } |
| 2417 | { |
| 2418 | "die" "after" expr = Expression() { lc.setDieExpr(expr); } |
| 2419 | { |
| 2420 | popForbiddenScope(); |
| 2421 | return lc; |
| 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | |
| 2426 | QuantifiedExpression QuantifiedExpression()throws ParseException: |
| 2427 | { |
| 2428 | QuantifiedExpression qc = new QuantifiedExpression(); |
| 2429 | List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>(); |
| 2430 | Expression satisfiesExpr; |
| 2431 | VariableExpr var; |
| 2432 | Expression inExpr; |
| 2433 | QuantifiedPair pair; |
| 2434 | } |
| 2435 | { |
| 2436 | { |
| 2437 | createNewScope(); |
| 2438 | } |
| 2439 | |
| 2440 | ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }) |
| 2441 | | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); })) |
| 2442 | var = Variable() "in" inExpr = Expression() |
| 2443 | { |
| 2444 | pair = new QuantifiedPair(var, inExpr); |
| 2445 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2446 | quantifiedList.add(pair); |
| 2447 | } |
| 2448 | ( |
| 2449 | "," var = Variable() "in" inExpr = Expression() |
| 2450 | { |
| 2451 | pair = new QuantifiedPair(var, inExpr); |
| 2452 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2453 | quantifiedList.add(pair); |
| 2454 | } |
| 2455 | )* |
| 2456 | "satisfies" satisfiesExpr = Expression() |
| 2457 | { |
| 2458 | qc.setSatisfiesExpr(satisfiesExpr); |
| 2459 | qc.setQuantifiedList(quantifiedList); |
| 2460 | removeCurrentScope(); |
| 2461 | return qc; |
| 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | TOKEN_MGR_DECLS: |
| 2466 | { |
| 2467 | public int commentDepth = 0; |
| 2468 | } |
| 2469 | |
| 2470 | <DEFAULT> |
| 2471 | TOKEN : |
| 2472 | { |
| 2473 | <CARET : "^" > |
| 2474 | } |
| 2475 | |
| 2476 | <DEFAULT> |
| 2477 | TOKEN : |
| 2478 | { |
| 2479 | <DATASET : "dataset" > |
| 2480 | } |
| 2481 | |
| 2482 | <DEFAULT> |
| 2483 | TOKEN : |
| 2484 | { |
| 2485 | <LEFTPAREN : "(" > |
| 2486 | } |
| 2487 | |
| 2488 | <DEFAULT> |
| 2489 | TOKEN : |
| 2490 | { |
| 2491 | <RIGHTPAREN : ")" > |
| 2492 | } |
| 2493 | |
| 2494 | |
| 2495 | <DEFAULT> |
| 2496 | TOKEN : |
| 2497 | { |
| 2498 | <INTEGER_LITERAL : (<DIGIT>)+ > |
| 2499 | } |
| 2500 | |
| 2501 | |
| 2502 | <DEFAULT> |
| 2503 | TOKEN : |
| 2504 | { |
| 2505 | <NULL : "null"> |
| 2506 | } |
| 2507 | |
| 2508 | <DEFAULT> |
| 2509 | TOKEN : |
| 2510 | { |
| 2511 | <TRUE : "true"> |
| 2512 | } |
| 2513 | |
| 2514 | <DEFAULT> |
| 2515 | TOKEN : |
| 2516 | { |
| 2517 | <FALSE : "false"> |
| 2518 | } |
| 2519 | |
| 2520 | <DEFAULT> |
| 2521 | TOKEN : |
| 2522 | { |
| 2523 | <#DIGIT : ["0" - "9"]> |
| 2524 | } |
| 2525 | |
| 2526 | |
| 2527 | TOKEN: |
| 2528 | { |
| 2529 | < DOUBLE_LITERAL: <INTEGER> |
| 2530 | | <INTEGER> ( "." <INTEGER> )? |
| 2531 | | "." <INTEGER> |
| 2532 | > |
| 2533 | | |
| 2534 | < FLOAT_LITERAL: <INTEGER> ( "f" | "F" ) |
| 2535 | | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )? |
| 2536 | | "." <INTEGER> ( "f" | "F" ) |
| 2537 | > |
| 2538 | | |
| 2539 | <INTEGER : (<DIGIT>)+ > |
| 2540 | } |
| 2541 | |
| 2542 | <DEFAULT> |
| 2543 | TOKEN : |
| 2544 | { |
| 2545 | <#LETTER : ["A" - "Z", "a" - "z"]> |
| 2546 | } |
| 2547 | |
| 2548 | <DEFAULT> |
| 2549 | TOKEN : |
| 2550 | { |
| 2551 | <SPECIALCHARS : ["$", "_", "-"] > |
| 2552 | } |
| 2553 | |
| 2554 | <DEFAULT> |
| 2555 | TOKEN : |
| 2556 | { |
| 2557 | <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")> |
| 2558 | | |
| 2559 | < #EscapeQuot: "\\\"" > |
| 2560 | | |
| 2561 | < #EscapeApos: "\\\'" > |
| 2562 | } |
| 2563 | |
| 2564 | <DEFAULT> |
| 2565 | TOKEN : |
| 2566 | { |
| 2567 | <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*> |
| 2568 | } |
| 2569 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 2570 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2571 | <DEFAULT> |
| 2572 | TOKEN : |
| 2573 | { |
| 2574 | <VARIABLE : "$" <IDENTIFIER> > |
| 2575 | } |
| 2576 | |
| 2577 | SKIP: |
| 2578 | { |
| 2579 | " " |
| 2580 | | "\t" |
| 2581 | | "\r" |
| 2582 | | "\n" |
| 2583 | } |
| 2584 | |
| 2585 | SKIP: |
| 2586 | { |
| 2587 | <"//" (~["\n"])* "\n"> |
| 2588 | } |
| 2589 | |
| 2590 | SKIP: |
| 2591 | { |
| 2592 | <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
| 2593 | } |
| 2594 | |
| 2595 | |
| 2596 | SKIP: |
| 2597 | { |
| 2598 | <"/*"> {commentDepth=1;}: INSIDE_COMMENT |
| 2599 | } |
| 2600 | |
| 2601 | <INSIDE_COMMENT> |
| 2602 | SPECIAL_TOKEN: |
| 2603 | { |
| 2604 | <"+"(" ")*(~["*"])*> |
| 2605 | } |
| 2606 | |
| 2607 | <INSIDE_COMMENT> |
| 2608 | SKIP: |
| 2609 | { |
| 2610 | <"/*"> {commentDepth++;} |
| 2611 | } |
| 2612 | |
| 2613 | <INSIDE_COMMENT> |
| 2614 | SKIP: |
| 2615 | { |
| 2616 | <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);} |
| 2617 | | <~[]> |
| 2618 | } |