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