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