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