Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1 | options { |
| 2 | |
| 3 | |
| 4 | STATIC = false; |
| 5 | |
| 6 | } |
| 7 | |
| 8 | |
| 9 | PARSER_BEGIN(SQLPPParser) |
| 10 | |
| 11 | package org.apache.asterix.lang.sqlpp.parser; |
| 12 | |
| 13 | // For SQL++ ParserTokenManager |
| 14 | import org.apache.xerces.util.IntStack; |
| 15 | |
| 16 | import java.io.BufferedReader; |
| 17 | import java.io.File; |
| 18 | import java.io.FileInputStream; |
| 19 | import java.io.FileNotFoundException; |
| 20 | import java.io.IOException; |
| 21 | import java.io.InputStreamReader; |
| 22 | import java.io.Reader; |
| 23 | import java.io.StringReader; |
| 24 | import java.util.ArrayList; |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 25 | import java.util.Collections; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 26 | import java.util.HashMap; |
| 27 | import java.util.Iterator; |
| 28 | import java.util.LinkedHashMap; |
| 29 | import java.util.List; |
| 30 | import java.util.Map; |
| 31 | |
| 32 | import org.apache.asterix.common.annotations.AutoDataGen; |
| 33 | import org.apache.asterix.common.annotations.DateBetweenYearsDataGen; |
| 34 | import org.apache.asterix.common.annotations.DatetimeAddRandHoursDataGen; |
| 35 | import org.apache.asterix.common.annotations.DatetimeBetweenYearsDataGen; |
| 36 | import org.apache.asterix.common.annotations.FieldIntervalDataGen; |
| 37 | import org.apache.asterix.common.annotations.FieldValFileDataGen; |
| 38 | import org.apache.asterix.common.annotations.FieldValFileSameIndexDataGen; |
| 39 | import org.apache.asterix.common.annotations.IRecordFieldDataGen; |
| 40 | import org.apache.asterix.common.annotations.InsertRandIntDataGen; |
| 41 | import org.apache.asterix.common.annotations.ListDataGen; |
| 42 | import org.apache.asterix.common.annotations.ListValFileDataGen; |
| 43 | import org.apache.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation; |
| 44 | import org.apache.asterix.common.annotations.TypeDataGen; |
| 45 | import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen; |
| 46 | import org.apache.asterix.common.config.DatasetConfig.DatasetType; |
| 47 | import org.apache.asterix.common.config.DatasetConfig.IndexType; |
Abdullah Alamoudi | e800e6d | 2016-01-14 11:20:55 +0300 | [diff] [blame] | 48 | import org.apache.asterix.common.config.MetadataConstants; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 49 | import org.apache.asterix.common.exceptions.AsterixException; |
| 50 | import org.apache.asterix.common.functions.FunctionSignature; |
| 51 | import org.apache.asterix.lang.common.base.Expression; |
| 52 | import org.apache.asterix.lang.common.base.Literal; |
| 53 | import org.apache.asterix.lang.common.base.IParser; |
| 54 | import org.apache.asterix.lang.common.base.Statement; |
| 55 | import org.apache.asterix.lang.common.clause.GroupbyClause; |
| 56 | import org.apache.asterix.lang.common.clause.LetClause; |
| 57 | import org.apache.asterix.lang.common.clause.LimitClause; |
| 58 | import org.apache.asterix.lang.common.clause.OrderbyClause; |
| 59 | import org.apache.asterix.lang.common.clause.UpdateClause; |
| 60 | import org.apache.asterix.lang.common.clause.WhereClause; |
| 61 | import org.apache.asterix.lang.common.context.RootScopeFactory; |
| 62 | import org.apache.asterix.lang.common.context.Scope; |
| 63 | import org.apache.asterix.lang.common.expression.AbstractAccessor; |
| 64 | import org.apache.asterix.lang.common.expression.CallExpr; |
| 65 | import org.apache.asterix.lang.common.expression.FieldAccessor; |
| 66 | import org.apache.asterix.lang.common.expression.FieldBinding; |
| 67 | import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair; |
| 68 | import org.apache.asterix.lang.common.expression.IfExpr; |
| 69 | import org.apache.asterix.lang.common.expression.IndexAccessor; |
| 70 | import org.apache.asterix.lang.common.expression.ListConstructor; |
| 71 | import org.apache.asterix.lang.common.expression.LiteralExpr; |
| 72 | import org.apache.asterix.lang.common.expression.OperatorExpr; |
| 73 | import org.apache.asterix.lang.common.expression.OrderedListTypeDefinition; |
| 74 | import org.apache.asterix.lang.common.expression.QuantifiedExpression; |
| 75 | import org.apache.asterix.lang.common.expression.RecordConstructor; |
| 76 | import org.apache.asterix.lang.common.expression.RecordTypeDefinition; |
| 77 | import org.apache.asterix.lang.common.expression.TypeExpression; |
| 78 | import org.apache.asterix.lang.common.expression.TypeReferenceExpression; |
| 79 | import org.apache.asterix.lang.common.expression.UnaryExpr; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 80 | import org.apache.asterix.lang.common.expression.UnorderedListTypeDefinition; |
| 81 | import org.apache.asterix.lang.common.expression.VariableExpr; |
| 82 | import org.apache.asterix.lang.common.literal.DoubleLiteral; |
| 83 | import org.apache.asterix.lang.common.literal.FalseLiteral; |
| 84 | import org.apache.asterix.lang.common.literal.FloatLiteral; |
| 85 | import org.apache.asterix.lang.common.literal.LongIntegerLiteral; |
Yingyi Bu | 535d86b | 2016-05-23 16:44:25 -0700 | [diff] [blame] | 86 | import org.apache.asterix.lang.common.literal.MissingLiteral; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 87 | import org.apache.asterix.lang.common.literal.NullLiteral; |
| 88 | import org.apache.asterix.lang.common.literal.StringLiteral; |
| 89 | import org.apache.asterix.lang.common.literal.TrueLiteral; |
| 90 | import org.apache.asterix.lang.common.parser.ScopeChecker; |
| 91 | import org.apache.asterix.lang.common.statement.CompactStatement; |
| 92 | import org.apache.asterix.lang.common.statement.ConnectFeedStatement; |
| 93 | import org.apache.asterix.lang.common.statement.CreateDataverseStatement; |
| 94 | import org.apache.asterix.lang.common.statement.CreateFeedPolicyStatement; |
| 95 | import org.apache.asterix.lang.common.statement.CreateFeedStatement; |
| 96 | import org.apache.asterix.lang.common.statement.CreateFunctionStatement; |
| 97 | import org.apache.asterix.lang.common.statement.CreateIndexStatement; |
| 98 | import org.apache.asterix.lang.common.statement.CreatePrimaryFeedStatement; |
| 99 | import org.apache.asterix.lang.common.statement.CreateSecondaryFeedStatement; |
| 100 | import org.apache.asterix.lang.common.statement.DatasetDecl; |
| 101 | import org.apache.asterix.lang.common.statement.DataverseDecl; |
| 102 | import org.apache.asterix.lang.common.statement.DataverseDropStatement; |
| 103 | import org.apache.asterix.lang.common.statement.DeleteStatement; |
| 104 | import org.apache.asterix.lang.common.statement.DisconnectFeedStatement; |
| 105 | import org.apache.asterix.lang.common.statement.DropStatement; |
| 106 | import org.apache.asterix.lang.common.statement.ExternalDetailsDecl; |
| 107 | import org.apache.asterix.lang.common.statement.FeedDropStatement; |
| 108 | import org.apache.asterix.lang.common.statement.FunctionDecl; |
| 109 | import org.apache.asterix.lang.common.statement.FunctionDropStatement; |
| 110 | import org.apache.asterix.lang.common.statement.IndexDropStatement; |
| 111 | import org.apache.asterix.lang.common.statement.InsertStatement; |
| 112 | import org.apache.asterix.lang.common.statement.InternalDetailsDecl; |
| 113 | import org.apache.asterix.lang.common.statement.LoadStatement; |
| 114 | import org.apache.asterix.lang.common.statement.NodeGroupDropStatement; |
| 115 | import org.apache.asterix.lang.common.statement.NodegroupDecl; |
| 116 | import org.apache.asterix.lang.common.statement.Query; |
| 117 | import org.apache.asterix.lang.common.statement.RefreshExternalDatasetStatement; |
| 118 | import org.apache.asterix.lang.common.statement.RunStatement; |
| 119 | import org.apache.asterix.lang.common.statement.SetStatement; |
| 120 | import org.apache.asterix.lang.common.statement.TypeDecl; |
| 121 | import org.apache.asterix.lang.common.statement.TypeDropStatement; |
| 122 | import org.apache.asterix.lang.common.statement.UpdateStatement; |
| 123 | import org.apache.asterix.lang.common.statement.WriteStatement; |
| 124 | import org.apache.asterix.lang.common.struct.Identifier; |
| 125 | import org.apache.asterix.lang.common.struct.QuantifiedPair; |
| 126 | import org.apache.asterix.lang.common.struct.VarIdentifier; |
| 127 | import org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause; |
| 128 | import org.apache.asterix.lang.sqlpp.clause.FromClause; |
| 129 | import org.apache.asterix.lang.sqlpp.clause.FromTerm; |
| 130 | import org.apache.asterix.lang.sqlpp.clause.HavingClause; |
| 131 | import org.apache.asterix.lang.sqlpp.clause.JoinClause; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 132 | import org.apache.asterix.lang.sqlpp.clause.Projection; |
| 133 | import org.apache.asterix.lang.sqlpp.clause.SelectBlock; |
| 134 | import org.apache.asterix.lang.sqlpp.clause.SelectClause; |
| 135 | import org.apache.asterix.lang.sqlpp.clause.SelectElement; |
| 136 | import org.apache.asterix.lang.sqlpp.clause.SelectRegular; |
| 137 | import org.apache.asterix.lang.sqlpp.clause.SelectSetOperation; |
| 138 | import org.apache.asterix.lang.sqlpp.clause.UnnestClause; |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame^] | 139 | import org.apache.asterix.lang.sqlpp.expression.CaseExpression; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 140 | import org.apache.asterix.lang.sqlpp.expression.SelectExpression; |
| 141 | import org.apache.asterix.lang.sqlpp.optype.JoinType; |
| 142 | import org.apache.asterix.lang.sqlpp.optype.SetOpType; |
| 143 | import org.apache.asterix.lang.sqlpp.struct.SetOperationInput; |
| 144 | import org.apache.asterix.lang.sqlpp.struct.SetOperationRight; |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 145 | import org.apache.asterix.lang.sqlpp.util.ExpressionToVariableUtil; |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 146 | import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 147 | import org.apache.hyracks.algebricks.common.utils.Pair; |
| 148 | import org.apache.hyracks.algebricks.common.utils.Triple; |
| 149 | import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation; |
| 150 | import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation; |
| 151 | import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; |
| 152 | |
| 153 | |
| 154 | |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 155 | class SQLPPParser extends ScopeChecker implements IParser { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 156 | |
| 157 | // optimizer hints |
| 158 | private static final String AUTO_HINT = "auto"; |
| 159 | private static final String BROADCAST_JOIN_HINT = "bcast"; |
| 160 | private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files"; |
| 161 | private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years"; |
| 162 | private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours"; |
| 163 | private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years"; |
| 164 | private static final String HASH_GROUP_BY_HINT = "hash"; |
| 165 | private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl"; |
| 166 | private static final String INMEMORY_HINT = "inmem"; |
| 167 | private static final String INSERT_RAND_INT_HINT = "insert-rand-int"; |
| 168 | private static final String INTERVAL_HINT = "interval"; |
| 169 | private static final String LIST_HINT = "list"; |
| 170 | private static final String LIST_VAL_FILE_HINT = "list-val-file"; |
| 171 | private static final String RANGE_HINT = "range"; |
| 172 | private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index"; |
| 173 | private static final String VAL_FILE_HINT = "val-files"; |
| 174 | private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx"; |
| 175 | |
| 176 | private static final String GEN_FIELDS_HINT = "gen-fields"; |
| 177 | |
| 178 | // data generator hints |
| 179 | private static final String DGEN_HINT = "dgen"; |
| 180 | |
| 181 | private static class IndexParams { |
| 182 | public IndexType type; |
| 183 | public int gramLength; |
| 184 | |
| 185 | public IndexParams(IndexType type, int gramLength) { |
| 186 | this.type = type; |
| 187 | this.gramLength = gramLength; |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | private static class FunctionName { |
| 192 | public String dataverse = null; |
| 193 | public String library = null; |
| 194 | public String function = null; |
| 195 | public String hint = null; |
| 196 | } |
| 197 | |
| 198 | private static String getHint(Token t) { |
| 199 | if (t.specialToken == null) { |
| 200 | return null; |
| 201 | } |
| 202 | String s = t.specialToken.image; |
| 203 | int n = s.length(); |
| 204 | if (n < 2) { |
| 205 | return null; |
| 206 | } |
| 207 | return s.substring(1).trim(); |
| 208 | } |
| 209 | |
| 210 | private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException { |
| 211 | IRecordFieldDataGen rfdg = null; |
| 212 | String splits[] = hint.split(" +"); |
| 213 | if (splits[0].equals(VAL_FILE_HINT)) { |
| 214 | File[] valFiles = new File[splits.length - 1]; |
| 215 | for (int k=1; k<splits.length; k++) { |
| 216 | valFiles[k-1] = new File(splits[k]); |
| 217 | } |
| 218 | rfdg = new FieldValFileDataGen(valFiles); |
| 219 | } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) { |
| 220 | rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]); |
| 221 | } else if (splits[0].equals(LIST_VAL_FILE_HINT)) { |
| 222 | rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3])); |
| 223 | } else if (splits[0].equals(LIST_HINT)) { |
| 224 | rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 225 | } else if (splits[0].equals(INTERVAL_HINT)) { |
| 226 | FieldIntervalDataGen.ValueType vt; |
| 227 | if (splits[1].equals("int")) { |
| 228 | vt = FieldIntervalDataGen.ValueType.INT; |
| 229 | } else if (splits[1].equals("long")) { |
| 230 | vt = FieldIntervalDataGen.ValueType.LONG; |
| 231 | } else if (splits[1].equals("float")) { |
| 232 | vt = FieldIntervalDataGen.ValueType.FLOAT; |
| 233 | } else if (splits[1].equals("double")) { |
| 234 | vt = FieldIntervalDataGen.ValueType.DOUBLE; |
| 235 | } else { |
| 236 | throw new ParseException("Unknown type for interval data gen: " + splits[1]); |
| 237 | } |
| 238 | rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]); |
| 239 | } else if (splits[0].equals(INSERT_RAND_INT_HINT)) { |
| 240 | rfdg = new InsertRandIntDataGen(splits[1], splits[2]); |
| 241 | } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) { |
| 242 | rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 243 | } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) { |
| 244 | rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 245 | } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) { |
| 246 | rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]); |
| 247 | } else if (splits[0].equals(AUTO_HINT)) { |
| 248 | rfdg = new AutoDataGen(splits[1]); |
| 249 | } |
| 250 | return rfdg; |
| 251 | } |
| 252 | |
| 253 | public SQLPPParser(String s){ |
| 254 | this(new StringReader(s)); |
| 255 | super.setInput(s); |
| 256 | } |
| 257 | |
| 258 | public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException { |
| 259 | File file = new File(args[0]); |
| 260 | Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); |
| 261 | SQLPPParser parser = new SQLPPParser(fis); |
| 262 | List<Statement> st = parser.parse(); |
| 263 | //st.accept(new SQLPPPrintVisitor(), 0); |
| 264 | } |
| 265 | |
| 266 | public List<Statement> parse() throws AsterixException { |
| 267 | try { |
| 268 | return Statement(); |
| 269 | } catch (Error e) { |
| 270 | // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled |
| 271 | // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes) |
| 272 | throw new AsterixException(new ParseException(e.getMessage())); |
| 273 | } catch (ParseException e) { |
| 274 | throw new AsterixException(e.getMessage()); |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | PARSER_END(SQLPPParser) |
| 280 | |
| 281 | |
| 282 | List<Statement> Statement() throws ParseException: |
| 283 | { |
| 284 | scopeStack.push(RootScopeFactory.createRootScope(this)); |
| 285 | List<Statement> decls = new ArrayList<Statement>(); |
| 286 | Statement stmt = null; |
| 287 | } |
| 288 | { |
| 289 | ( stmt = SingleStatement() (<SEMICOLON>)* |
| 290 | { |
| 291 | decls.add(stmt); |
| 292 | } |
| 293 | )* |
| 294 | <EOF> |
| 295 | { |
| 296 | return decls; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | Statement SingleStatement() throws ParseException: |
| 301 | { |
| 302 | Statement stmt = null; |
| 303 | } |
| 304 | { |
| 305 | ( |
| 306 | stmt = DataverseDeclaration() |
| 307 | | stmt = FunctionDeclaration() |
| 308 | | stmt = CreateStatement() |
| 309 | | stmt = LoadStatement() |
| 310 | | stmt = DropStatement() |
| 311 | | stmt = WriteStatement() |
| 312 | | stmt = SetStatement() |
| 313 | | stmt = InsertStatement() |
| 314 | | stmt = DeleteStatement() |
| 315 | | stmt = UpdateStatement() |
| 316 | | stmt = FeedStatement() |
| 317 | | stmt = CompactStatement() |
| 318 | | stmt = Query() <SEMICOLON> |
| 319 | | stmt = RefreshExternalDatasetStatement() |
| 320 | | stmt = RunStatement() |
| 321 | ) |
| 322 | { |
| 323 | return stmt; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | DataverseDecl DataverseDeclaration() throws ParseException: |
| 328 | { |
| 329 | String dvName = null; |
| 330 | } |
| 331 | { |
| 332 | <USE> dvName = Identifier() |
| 333 | { |
| 334 | defaultDataverse = dvName; |
| 335 | return new DataverseDecl(new Identifier(dvName)); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | Statement CreateStatement() throws ParseException: |
| 340 | { |
| 341 | String hint = null; |
| 342 | boolean dgen = false; |
| 343 | Statement stmt = null; |
| 344 | } |
| 345 | { |
| 346 | <CREATE> |
| 347 | ( |
| 348 | { |
| 349 | hint = getHint(token); |
| 350 | if (hint != null && hint.startsWith(DGEN_HINT)) { |
| 351 | dgen = true; |
| 352 | } |
| 353 | } |
| 354 | stmt = TypeSpecification(hint, dgen) |
| 355 | | stmt = NodegroupSpecification() |
| 356 | | stmt = DatasetSpecification() |
| 357 | | stmt = IndexSpecification() |
| 358 | | stmt = DataverseSpecification() |
| 359 | | stmt = FunctionSpecification() |
| 360 | | stmt = FeedSpecification() |
| 361 | | stmt = FeedPolicySpecification() |
| 362 | ) |
| 363 | { |
| 364 | return stmt; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException: |
| 369 | { |
| 370 | Pair<Identifier,Identifier> nameComponents = null; |
| 371 | boolean ifNotExists = false; |
| 372 | TypeExpression typeExpr = null; |
| 373 | } |
| 374 | { |
| 375 | <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists() |
| 376 | <AS> typeExpr = TypeExpr() |
| 377 | { |
| 378 | long numValues = -1; |
| 379 | String filename = null; |
| 380 | if (dgen) { |
| 381 | String splits[] = hint.split(" +"); |
| 382 | if (splits.length != 3) { |
| 383 | throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */"); |
| 384 | } |
| 385 | filename = splits[1]; |
| 386 | numValues = Long.parseLong(splits[2]); |
| 387 | } |
| 388 | TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues); |
| 389 | return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | |
| 394 | NodegroupDecl NodegroupSpecification() throws ParseException: |
| 395 | { |
| 396 | String name = null; |
| 397 | String tmp = null; |
| 398 | boolean ifNotExists = false; |
| 399 | List<Identifier>ncNames = null; |
| 400 | } |
| 401 | { |
| 402 | <NODEGROUP> name = Identifier() |
| 403 | ifNotExists = IfNotExists() <ON> tmp = Identifier() |
| 404 | { |
| 405 | ncNames = new ArrayList<Identifier>(); |
| 406 | ncNames.add(new Identifier(tmp)); |
| 407 | } |
| 408 | ( <COMMA> tmp = Identifier() |
| 409 | { |
| 410 | ncNames.add(new Identifier(tmp)); |
| 411 | } |
| 412 | )* |
| 413 | { |
| 414 | return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | DatasetDecl DatasetSpecification() throws ParseException: |
| 419 | { |
| 420 | Pair<Identifier,Identifier> nameComponents = null; |
| 421 | boolean ifNotExists = false; |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 422 | Pair<Identifier,Identifier> typeComponents = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 423 | String adapterName = null; |
| 424 | Map<String,String> properties = null; |
| 425 | Map<String,String> compactionPolicyProperties = null; |
| 426 | FunctionSignature appliedFunction = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 427 | Pair<List<Integer>, List<List<String>>> primaryKeyFields = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 428 | String nodeGroupName = null; |
| 429 | Map<String,String> hints = new HashMap<String,String>(); |
| 430 | DatasetDecl dsetDecl = null; |
| 431 | boolean autogenerated = false; |
| 432 | String compactionPolicy = null; |
| 433 | boolean temp = false; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 434 | Pair<Integer, List<String>> filterField = null; |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 435 | Pair<Identifier,Identifier> metaTypeComponents = new Pair<Identifier, Identifier>(null, null); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 436 | } |
| 437 | { |
| 438 | ( |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 439 | <EXTERNAL> Dataset() nameComponents = QualifiedName() |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 440 | <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 441 | ifNotExists = IfNotExists() |
| 442 | <USING> adapterName = AdapterName() properties = Configuration() |
| 443 | (<ON> nodeGroupName = Identifier() )? |
| 444 | ( <HINTS> hints = Properties() )? |
| 445 | ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (LOOKAHEAD(1) compactionPolicyProperties = Configuration())? )? |
| 446 | { |
| 447 | ExternalDetailsDecl edd = new ExternalDetailsDecl(); |
| 448 | edd.setAdapter(adapterName); |
| 449 | edd.setProperties(properties); |
| 450 | dsetDecl = new DatasetDecl(nameComponents.first, |
| 451 | nameComponents.second, |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 452 | typeComponents.first, |
| 453 | typeComponents.second, |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 454 | metaTypeComponents.first, |
| 455 | metaTypeComponents.second, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 456 | nodeGroupName != null? new Identifier(nodeGroupName): null, |
| 457 | compactionPolicy, |
| 458 | compactionPolicyProperties, |
| 459 | hints, |
| 460 | DatasetType.EXTERNAL, |
| 461 | edd, |
| 462 | ifNotExists); |
| 463 | } |
| 464 | |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 465 | | (<INTERNAL> | <TEMPORARY> { temp = true; })? |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 466 | Dataset() nameComponents = QualifiedName() |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 467 | <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN> |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 468 | ( |
| 469 | { String name; } |
| 470 | <WITH> |
| 471 | name = Identifier() |
| 472 | { |
| 473 | if(!name.toLowerCase().equals("meta")){ |
| 474 | throw new ParseException("We can only support one additional associated field called \"meta\"."); |
| 475 | } |
| 476 | } |
| 477 | <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN> |
| 478 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 479 | ifNotExists = IfNotExists() |
| 480 | primaryKeyFields = PrimaryKey() |
| 481 | (<AUTOGENERATED> { autogenerated = true; } )? |
| 482 | (<ON> nodeGroupName = Identifier() )? |
| 483 | ( <HINTS> hints = Properties() )? |
| 484 | ( <USING> <COMPACTION> <POLICY> compactionPolicy = CompactionPolicy() (LOOKAHEAD(1) compactionPolicyProperties = Configuration())? )? |
| 485 | ( LOOKAHEAD(2) <WITH> <FILTER> <ON> filterField = NestedField() )? |
| 486 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 487 | if(filterField!=null && filterField.first!=0){ |
| 488 | throw new ParseException("A filter field can only be a field in the main record of the dataset."); |
| 489 | } |
| 490 | InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second, |
| 491 | primaryKeyFields.first, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 492 | autogenerated, |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 493 | filterField == null? null : filterField.second, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 494 | temp); |
| 495 | dsetDecl = new DatasetDecl(nameComponents.first, |
| 496 | nameComponents.second, |
Your Name | dace5f2 | 2016-01-12 14:02:48 -0800 | [diff] [blame] | 497 | typeComponents.first, |
| 498 | typeComponents.second, |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 499 | metaTypeComponents.first, |
| 500 | metaTypeComponents.second, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 501 | nodeGroupName != null ? new Identifier(nodeGroupName) : null, |
| 502 | compactionPolicy, |
| 503 | compactionPolicyProperties, |
| 504 | hints, |
| 505 | DatasetType.INTERNAL, |
| 506 | idd, |
| 507 | ifNotExists); |
| 508 | } |
| 509 | ) |
| 510 | { |
| 511 | return dsetDecl; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException: |
| 516 | { |
| 517 | RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement(); |
| 518 | Pair<Identifier,Identifier> nameComponents = null; |
| 519 | String datasetName = null; |
| 520 | } |
| 521 | { |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 522 | <REFRESH> <EXTERNAL> Dataset() nameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 523 | { |
| 524 | redss.setDataverseName(nameComponents.first); |
| 525 | redss.setDatasetName(nameComponents.second); |
| 526 | return redss; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | RunStatement RunStatement() throws ParseException: |
| 531 | { |
| 532 | String system = null; |
| 533 | String tmp; |
| 534 | ArrayList<String> parameters = new ArrayList<String>(); |
| 535 | Pair<Identifier,Identifier> nameComponentsFrom = null; |
| 536 | Pair<Identifier,Identifier> nameComponentsTo = null; |
| 537 | } |
| 538 | { |
| 539 | <RUN> system = Identifier()<LEFTPAREN> ( tmp = Identifier() [<COMMA>] |
| 540 | { |
| 541 | parameters.add(tmp); |
| 542 | } |
| 543 | )*<RIGHTPAREN> |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 544 | <FROM> Dataset() nameComponentsFrom = QualifiedName() |
| 545 | <TO> Dataset() nameComponentsTo = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 546 | { |
| 547 | return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | CreateIndexStatement IndexSpecification() throws ParseException: |
| 552 | { |
| 553 | CreateIndexStatement cis = new CreateIndexStatement(); |
| 554 | String indexName = null; |
| 555 | boolean ifNotExists = false; |
| 556 | Pair<Identifier,Identifier> nameComponents = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 557 | Pair<Integer, Pair<List<String>, TypeExpression>> fieldPair = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 558 | IndexParams indexType = null; |
| 559 | boolean enforced = false; |
| 560 | } |
| 561 | { |
| 562 | <INDEX> indexName = Identifier() |
| 563 | ifNotExists = IfNotExists() |
| 564 | <ON> nameComponents = QualifiedName() |
| 565 | <LEFTPAREN> ( fieldPair = OpenField() |
| 566 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 567 | cis.addFieldExprPair(fieldPair.second); |
| 568 | cis.addFieldIndexIndicator(fieldPair.first); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 569 | } |
| 570 | ) (<COMMA> fieldPair = OpenField() |
| 571 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 572 | cis.addFieldExprPair(fieldPair.second); |
| 573 | cis.addFieldIndexIndicator(fieldPair.first); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 574 | } |
| 575 | )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )? |
| 576 | { |
| 577 | cis.setIndexName(new Identifier(indexName)); |
| 578 | cis.setIfNotExists(ifNotExists); |
| 579 | cis.setDataverseName(nameComponents.first); |
| 580 | cis.setDatasetName(nameComponents.second); |
| 581 | if (indexType != null) { |
| 582 | cis.setIndexType(indexType.type); |
| 583 | cis.setGramLength(indexType.gramLength); |
| 584 | } |
| 585 | cis.setEnforced(enforced); |
| 586 | return cis; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | String CompactionPolicy() throws ParseException : |
| 591 | { |
| 592 | String compactionPolicy = null; |
| 593 | } |
| 594 | { |
| 595 | compactionPolicy = Identifier() |
| 596 | { |
| 597 | return compactionPolicy; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | String FilterField() throws ParseException : |
| 602 | { |
| 603 | String filterField = null; |
| 604 | } |
| 605 | { |
| 606 | filterField = Identifier() |
| 607 | { |
| 608 | return filterField; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | IndexParams IndexType() throws ParseException: |
| 613 | { |
| 614 | IndexType type = null; |
| 615 | int gramLength = 0; |
| 616 | } |
| 617 | { |
| 618 | (<BTREE> |
| 619 | { |
| 620 | type = IndexType.BTREE; |
| 621 | } |
| 622 | | <RTREE> |
| 623 | { |
| 624 | type = IndexType.RTREE; |
| 625 | } |
| 626 | | <KEYWORD> |
| 627 | { |
| 628 | type = IndexType.LENGTH_PARTITIONED_WORD_INVIX; |
| 629 | } |
| 630 | | <NGRAM> <LEFTPAREN> <INTEGER_LITERAL> |
| 631 | { |
| 632 | type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX; |
| 633 | gramLength = Integer.valueOf(token.image); |
| 634 | } |
| 635 | <RIGHTPAREN>) |
| 636 | { |
| 637 | return new IndexParams(type, gramLength); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | CreateDataverseStatement DataverseSpecification() throws ParseException : |
| 642 | { |
| 643 | String dvName = null; |
| 644 | boolean ifNotExists = false; |
| 645 | String format = null; |
| 646 | } |
| 647 | { |
| 648 | <DATAVERSE> dvName = Identifier() |
| 649 | ifNotExists = IfNotExists() |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 650 | ( LOOKAHEAD(1) <WITH> <FORMAT> format = ConstantString() )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 651 | { |
| 652 | return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | CreateFunctionStatement FunctionSpecification() throws ParseException: |
| 657 | { |
| 658 | FunctionSignature signature; |
| 659 | boolean ifNotExists = false; |
| 660 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 661 | String functionBody; |
| 662 | VarIdentifier var = null; |
| 663 | Expression functionBodyExpr; |
| 664 | Token beginPos; |
| 665 | Token endPos; |
| 666 | FunctionName fctName = null; |
| 667 | |
| 668 | createNewScope(); |
| 669 | } |
| 670 | { |
| 671 | <FUNCTION> fctName = FunctionName() |
| 672 | ifNotExists = IfNotExists() |
| 673 | paramList = ParameterList() |
| 674 | <LEFTBRACE> |
| 675 | { |
| 676 | beginPos = token; |
| 677 | } |
| 678 | functionBodyExpr = Expression() <RIGHTBRACE> |
| 679 | { |
| 680 | endPos = token; |
| 681 | functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn); |
| 682 | // TODO use fctName.library |
| 683 | signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size()); |
| 684 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 685 | removeCurrentScope(); |
| 686 | return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | CreateFeedStatement FeedSpecification() throws ParseException: |
| 691 | { |
| 692 | Pair<Identifier,Identifier> nameComponents = null; |
| 693 | boolean ifNotExists = false; |
| 694 | String adapterName = null; |
| 695 | Map<String,String> properties = null; |
| 696 | FunctionSignature appliedFunction = null; |
| 697 | CreateFeedStatement cfs = null; |
| 698 | Pair<Identifier,Identifier> sourceNameComponents = null; |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 699 | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 700 | } |
| 701 | { |
| 702 | ( |
| 703 | <SECONDARY> <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists() |
| 704 | <FROM> <FEED> sourceNameComponents = QualifiedName() (appliedFunction = ApplyFunction())? |
| 705 | { |
| 706 | cfs = new CreateSecondaryFeedStatement(nameComponents, |
| 707 | sourceNameComponents, appliedFunction, ifNotExists); |
| 708 | } |
| 709 | | |
| 710 | (<PRIMARY>)? <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists() |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 711 | <USING> adapterName = AdapterName() properties = Configuration() (appliedFunction = ApplyFunction())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 712 | { |
| 713 | cfs = new CreatePrimaryFeedStatement(nameComponents, |
| 714 | adapterName, properties, appliedFunction, ifNotExists); |
| 715 | } |
| 716 | ) |
| 717 | { |
| 718 | return cfs; |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException: |
| 723 | { |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 724 | String policyName = null; |
| 725 | String basePolicyName = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 726 | String sourcePolicyFile = null; |
| 727 | String definition = null; |
| 728 | boolean ifNotExists = false; |
| 729 | Map<String,String> properties = null; |
| 730 | CreateFeedPolicyStatement cfps = null; |
| 731 | } |
| 732 | { |
| 733 | ( |
| 734 | <INGESTION> <POLICY> policyName = Identifier() ifNotExists = IfNotExists() |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 735 | <FROM> |
| 736 | (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = ConstantString())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 737 | { |
| 738 | cfps = new CreateFeedPolicyStatement(policyName, |
| 739 | basePolicyName, properties, definition, ifNotExists); |
| 740 | } |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 741 | | <PATH> sourcePolicyFile = Identifier() (<DEFINITION> definition = ConstantString())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 742 | { |
| 743 | cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists); |
| 744 | } |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 745 | ) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 746 | ) |
| 747 | { |
| 748 | return cfps; |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | |
| 753 | |
| 754 | List<VarIdentifier> ParameterList() throws ParseException: |
| 755 | { |
| 756 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 757 | VarIdentifier var = null; |
| 758 | } |
| 759 | { |
| 760 | <LEFTPAREN> (<IDENTIFIER> |
| 761 | { |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 762 | var = SqlppVariableUtil.toInternalVariableIdentifier(token.image); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 763 | paramList.add(var); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 764 | } |
| 765 | (<COMMA> <IDENTIFIER> |
| 766 | { |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 767 | var = SqlppVariableUtil.toInternalVariableIdentifier(token.image); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 768 | paramList.add(var); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 769 | } |
| 770 | )*)? <RIGHTPAREN> |
| 771 | { |
| 772 | return paramList; |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | boolean IfNotExists() throws ParseException: |
| 777 | { |
| 778 | } |
| 779 | { |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 780 | ( LOOKAHEAD(1) <IF> <NOT> <EXISTS> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 781 | { |
| 782 | return true; |
| 783 | } |
| 784 | )? |
| 785 | { |
| 786 | return false; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | FunctionSignature ApplyFunction() throws ParseException: |
| 791 | { |
| 792 | FunctionName functioName = null; |
| 793 | FunctionSignature funcSig = null; |
| 794 | } |
| 795 | { |
| 796 | <APPLY> <FUNCTION> functioName = FunctionName() |
| 797 | { |
| 798 | String fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function; |
| 799 | return new FunctionSignature(functioName.dataverse, fqFunctionName, 1); |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | String GetPolicy() throws ParseException: |
| 804 | { |
| 805 | String policy = null; |
| 806 | } |
| 807 | { |
| 808 | <USING> <POLICY> policy = Identifier() |
| 809 | { |
| 810 | return policy; |
| 811 | } |
| 812 | |
| 813 | } |
| 814 | |
| 815 | FunctionSignature FunctionSignature() throws ParseException: |
| 816 | { |
| 817 | FunctionName fctName = null; |
| 818 | int arity = 0; |
| 819 | } |
| 820 | { |
| 821 | fctName = FunctionName() <ATT> <INTEGER_LITERAL> |
| 822 | { |
| 823 | arity = new Integer(token.image); |
| 824 | if (arity < 0 && arity != FunctionIdentifier.VARARGS) { |
| 825 | throw new ParseException(" invalid arity:" + arity); |
| 826 | } |
| 827 | |
| 828 | // TODO use fctName.library |
| 829 | String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function; |
| 830 | return new FunctionSignature(fctName.dataverse, fqFunctionName, arity); |
| 831 | } |
| 832 | } |
| 833 | |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 834 | Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 835 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 836 | Pair<Integer, List<String>> tmp = null; |
| 837 | List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>(); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 838 | List<List<String>> primaryKeyFields = new ArrayList<List<String>>(); |
| 839 | } |
| 840 | { |
| 841 | <PRIMARY> <KEY> tmp = NestedField() |
| 842 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 843 | keyFieldSourceIndicators.add(tmp.first); |
| 844 | primaryKeyFields.add(tmp.second); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 845 | } |
| 846 | ( <COMMA> tmp = NestedField() |
| 847 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 848 | keyFieldSourceIndicators.add(tmp.first); |
| 849 | primaryKeyFields.add(tmp.second); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 850 | } |
| 851 | )* |
| 852 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 853 | return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | |
| 857 | Statement DropStatement() throws ParseException: |
| 858 | { |
| 859 | String id = null; |
| 860 | Pair<Identifier,Identifier> pairId = null; |
| 861 | Triple<Identifier,Identifier,Identifier> tripleId = null; |
| 862 | FunctionSignature funcSig = null; |
| 863 | boolean ifExists = false; |
| 864 | Statement stmt = null; |
| 865 | } |
| 866 | { |
| 867 | <DROP> |
| 868 | ( |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 869 | Dataset() pairId = QualifiedName() ifExists = IfExists() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 870 | { |
| 871 | stmt = new DropStatement(pairId.first, pairId.second, ifExists); |
| 872 | } |
| 873 | | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists() |
| 874 | { |
| 875 | stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists); |
| 876 | } |
| 877 | | <NODEGROUP> id = Identifier() ifExists = IfExists() |
| 878 | { |
| 879 | stmt = new NodeGroupDropStatement(new Identifier(id), ifExists); |
| 880 | } |
| 881 | | <TYPE> pairId = TypeName() ifExists = IfExists() |
| 882 | { |
| 883 | stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists); |
| 884 | } |
| 885 | | <DATAVERSE> id = Identifier() ifExists = IfExists() |
| 886 | { |
| 887 | stmt = new DataverseDropStatement(new Identifier(id), ifExists); |
| 888 | } |
| 889 | | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists() |
| 890 | { |
| 891 | stmt = new FunctionDropStatement(funcSig, ifExists); |
| 892 | } |
| 893 | | <FEED> pairId = QualifiedName() ifExists = IfExists() |
| 894 | { |
| 895 | stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists); |
| 896 | } |
| 897 | ) |
| 898 | { |
| 899 | return stmt; |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | boolean IfExists() throws ParseException : |
| 904 | { |
| 905 | } |
| 906 | { |
| 907 | ( LOOKAHEAD(1) <IF> <EXISTS> |
| 908 | { |
| 909 | return true; |
| 910 | } |
| 911 | )? |
| 912 | { |
| 913 | return false; |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | InsertStatement InsertStatement() throws ParseException: |
| 918 | { |
| 919 | Pair<Identifier,Identifier> nameComponents = null; |
| 920 | Query query; |
| 921 | } |
| 922 | { |
| 923 | <INSERT> <INTO> nameComponents = QualifiedName() query = Query() |
| 924 | { |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 925 | query.setTopLevel(true); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 926 | return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter()); |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | DeleteStatement DeleteStatement() throws ParseException: |
| 931 | { |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 932 | VariableExpr varExpr = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 933 | Expression condition = null; |
| 934 | Pair<Identifier, Identifier> nameComponents; |
| 935 | // This is related to the new metadata lock management |
| 936 | setDataverses(new ArrayList<String>()); |
| 937 | setDatasets(new ArrayList<String>()); |
| 938 | |
| 939 | } |
| 940 | { |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 941 | <DELETE> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 942 | <FROM> nameComponents = QualifiedName() |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 943 | ((<AS>)? varExpr = Variable())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 944 | (<WHERE> condition = Expression())? |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 945 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 946 | // First we get the dataverses and datasets that we want to lock |
| 947 | List<String> dataverses = getDataverses(); |
| 948 | List<String> datasets = getDatasets(); |
| 949 | // we remove the pointer to the dataverses and datasets |
| 950 | setDataverses(null); |
| 951 | setDatasets(null); |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 952 | |
| 953 | if(varExpr == null){ |
| 954 | varExpr = new VariableExpr(); |
| 955 | VarIdentifier var = SqlppVariableUtil.toInternalVariableIdentifier(nameComponents.second.getValue()); |
| 956 | varExpr.setVar(var); |
| 957 | } |
| 958 | return new DeleteStatement(varExpr, nameComponents.first, nameComponents.second, |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 959 | condition, getVarCounter(), dataverses, datasets); |
Yingyi Bu | 20e085b | 2016-07-06 12:57:27 -0700 | [diff] [blame] | 960 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | UpdateStatement UpdateStatement() throws ParseException: |
| 964 | { |
| 965 | VariableExpr vars; |
| 966 | Expression target; |
| 967 | Expression condition; |
| 968 | UpdateClause uc; |
| 969 | List<UpdateClause> ucs = new ArrayList<UpdateClause>(); |
| 970 | } |
| 971 | { |
| 972 | <UPDATE> vars = Variable() <IN> target = Expression() |
| 973 | <WHERE> condition = Expression() |
| 974 | <LEFTPAREN> (uc = UpdateClause() |
| 975 | { |
| 976 | ucs.add(uc); |
| 977 | } |
| 978 | (<COMMA> uc = UpdateClause() |
| 979 | { |
| 980 | ucs.add(uc); |
| 981 | } |
| 982 | )*) <RIGHTPAREN> |
| 983 | { |
| 984 | return new UpdateStatement(vars, target, condition, ucs); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | UpdateClause UpdateClause() throws ParseException: |
| 989 | { |
| 990 | Expression target = null; |
| 991 | Expression value = null ; |
| 992 | InsertStatement is = null; |
| 993 | DeleteStatement ds = null; |
| 994 | UpdateStatement us = null; |
| 995 | Expression condition = null; |
| 996 | UpdateClause ifbranch = null; |
| 997 | UpdateClause elsebranch = null; |
| 998 | } |
| 999 | { |
| 1000 | (<SET> target = Expression() <EQ> value = Expression() |
| 1001 | | is = InsertStatement() |
| 1002 | | ds = DeleteStatement() |
| 1003 | | us = UpdateStatement() |
| 1004 | | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN> |
| 1005 | <THEN> ifbranch = UpdateClause() |
| 1006 | [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()] |
| 1007 | { |
| 1008 | return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch); |
| 1009 | } |
| 1010 | ) |
| 1011 | } |
| 1012 | |
| 1013 | Statement SetStatement() throws ParseException: |
| 1014 | { |
| 1015 | String pn = null; |
| 1016 | String pv = null; |
| 1017 | } |
| 1018 | { |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1019 | <SET> pn = Identifier() pv = ConstantString() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1020 | { |
| 1021 | return new SetStatement(pn, pv); |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | Statement WriteStatement() throws ParseException: |
| 1026 | { |
| 1027 | String nodeName = null; |
| 1028 | String fileName = null; |
| 1029 | Query query; |
| 1030 | String writerClass = null; |
| 1031 | Pair<Identifier,Identifier> nameComponents = null; |
| 1032 | } |
| 1033 | { |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1034 | <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = ConstantString() |
| 1035 | ( <USING> writerClass = ConstantString() )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1036 | { |
| 1037 | return new WriteStatement(new Identifier(nodeName), fileName, writerClass); |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | LoadStatement LoadStatement() throws ParseException: |
| 1042 | { |
| 1043 | Identifier dataverseName = null; |
| 1044 | Identifier datasetName = null; |
| 1045 | boolean alreadySorted = false; |
| 1046 | String adapterName; |
| 1047 | Map<String,String> properties; |
| 1048 | Pair<Identifier,Identifier> nameComponents = null; |
| 1049 | } |
| 1050 | { |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 1051 | <LOAD> Dataset() nameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1052 | { |
| 1053 | dataverseName = nameComponents.first; |
| 1054 | datasetName = nameComponents.second; |
| 1055 | } |
| 1056 | <USING> adapterName = AdapterName() properties = Configuration() |
| 1057 | (<PRESORTED> |
| 1058 | { |
| 1059 | alreadySorted = true; |
| 1060 | } |
| 1061 | )? |
| 1062 | { |
| 1063 | return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | String AdapterName() throws ParseException : |
| 1069 | { |
| 1070 | String adapterName = null; |
| 1071 | } |
| 1072 | { |
| 1073 | adapterName = Identifier() |
| 1074 | { |
| 1075 | return adapterName; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | Statement CompactStatement() throws ParseException: |
| 1080 | { |
| 1081 | Pair<Identifier,Identifier> nameComponents = null; |
| 1082 | Statement stmt = null; |
| 1083 | } |
| 1084 | { |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 1085 | <COMPACT> Dataset() nameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1086 | { |
| 1087 | stmt = new CompactStatement(nameComponents.first, nameComponents.second); |
| 1088 | } |
| 1089 | { |
| 1090 | return stmt; |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | Statement FeedStatement() throws ParseException: |
| 1095 | { |
| 1096 | Pair<Identifier,Identifier> feedNameComponents = null; |
| 1097 | Pair<Identifier,Identifier> datasetNameComponents = null; |
| 1098 | |
| 1099 | Map<String,String> configuration = null; |
| 1100 | Statement stmt = null; |
| 1101 | String policy = null; |
| 1102 | } |
| 1103 | { |
| 1104 | ( |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 1105 | <CONNECT> <FEED> feedNameComponents = QualifiedName() <TO> Dataset() datasetNameComponents = QualifiedName() (policy = GetPolicy())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1106 | { |
| 1107 | stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter()); |
| 1108 | } |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 1109 | | <DISCONNECT> <FEED> feedNameComponents = QualifiedName() <FROM> Dataset() datasetNameComponents = QualifiedName() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1110 | { |
| 1111 | stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents); |
| 1112 | } |
| 1113 | ) |
| 1114 | { |
| 1115 | return stmt; |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | Map<String,String> Configuration() throws ParseException : |
| 1120 | { |
| 1121 | Map<String,String> configuration = new LinkedHashMap<String,String>(); |
| 1122 | Pair<String, String> keyValuePair = null; |
| 1123 | } |
| 1124 | { |
| 1125 | <LEFTPAREN> ( keyValuePair = KeyValuePair() |
| 1126 | { |
| 1127 | configuration.put(keyValuePair.first, keyValuePair.second); |
| 1128 | } |
| 1129 | ( <COMMA> keyValuePair = KeyValuePair() |
| 1130 | { |
| 1131 | configuration.put(keyValuePair.first, keyValuePair.second); |
| 1132 | } |
| 1133 | )* )? <RIGHTPAREN> |
| 1134 | { |
| 1135 | return configuration; |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | Pair<String, String> KeyValuePair() throws ParseException: |
| 1140 | { |
| 1141 | String key; |
| 1142 | String value; |
| 1143 | } |
| 1144 | { |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1145 | <LEFTPAREN> key = ConstantString() <EQ> value = ConstantString() <RIGHTPAREN> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1146 | { |
| 1147 | return new Pair<String, String>(key, value); |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | Map<String,String> Properties() throws ParseException: |
| 1152 | { |
| 1153 | Map<String,String> properties = new HashMap<String,String>(); |
| 1154 | Pair<String, String> property; |
| 1155 | } |
| 1156 | { |
| 1157 | (LOOKAHEAD(1) <LEFTPAREN> property = Property() |
| 1158 | { |
| 1159 | properties.put(property.first, property.second); |
| 1160 | } |
| 1161 | ( <COMMA> property = Property() |
| 1162 | { |
| 1163 | properties.put(property.first, property.second); |
| 1164 | } |
| 1165 | )* <RIGHTPAREN> )? |
| 1166 | { |
| 1167 | return properties; |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | Pair<String, String> Property() throws ParseException: |
| 1172 | { |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1173 | String key = null; |
| 1174 | String value = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1175 | } |
| 1176 | { |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1177 | (key = Identifier() | key = StringLiteral()) |
| 1178 | <EQ> |
| 1179 | ( value = ConstantString() | <INTEGER_LITERAL> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1180 | { |
| 1181 | try { |
| 1182 | value = "" + Long.valueOf(token.image); |
| 1183 | } catch (NumberFormatException nfe) { |
| 1184 | throw new ParseException("inapproriate value: " + token.image); |
| 1185 | } |
| 1186 | } |
| 1187 | ) |
| 1188 | { |
| 1189 | return new Pair<String, String>(key.toUpperCase(), value); |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | TypeExpression IndexedTypeExpr() throws ParseException: |
| 1194 | { |
| 1195 | TypeExpression typeExpr = null; |
| 1196 | } |
| 1197 | { |
| 1198 | ( |
| 1199 | typeExpr = TypeReference() |
| 1200 | | typeExpr = OrderedListTypeDef() |
| 1201 | | typeExpr = UnorderedListTypeDef() |
| 1202 | ) |
| 1203 | { |
| 1204 | return typeExpr; |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | TypeExpression TypeExpr() throws ParseException: |
| 1209 | { |
| 1210 | TypeExpression typeExpr = null; |
| 1211 | } |
| 1212 | { |
| 1213 | ( |
| 1214 | typeExpr = RecordTypeDef() |
| 1215 | | typeExpr = TypeReference() |
| 1216 | | typeExpr = OrderedListTypeDef() |
| 1217 | | typeExpr = UnorderedListTypeDef() |
| 1218 | ) |
| 1219 | { |
| 1220 | return typeExpr; |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | RecordTypeDefinition RecordTypeDef() throws ParseException: |
| 1225 | { |
| 1226 | RecordTypeDefinition recType = new RecordTypeDefinition(); |
| 1227 | RecordTypeDefinition.RecordKind recordKind = null; |
| 1228 | } |
| 1229 | { |
| 1230 | ( <CLOSED> { recordKind = RecordTypeDefinition.RecordKind.CLOSED; } |
| 1231 | | <OPEN> { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )? |
| 1232 | <LEFTBRACE> |
| 1233 | { |
| 1234 | String hint = getHint(token); |
| 1235 | if (hint != null) { |
| 1236 | String splits[] = hint.split(" +"); |
| 1237 | if (splits[0].equals(GEN_FIELDS_HINT)) { |
| 1238 | if (splits.length != 5) { |
| 1239 | throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/"); |
| 1240 | } |
| 1241 | if (!splits[1].equals("int")) { |
| 1242 | throw new ParseException("The only supported type for gen-fields is int."); |
| 1243 | } |
| 1244 | UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT, |
| 1245 | Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]); |
| 1246 | recType.setUndeclaredFieldsDataGen(ufdg); |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | } |
| 1251 | ( |
| 1252 | RecordField(recType) |
| 1253 | ( <COMMA> RecordField(recType) )* |
| 1254 | )? |
| 1255 | <RIGHTBRACE> |
| 1256 | { |
| 1257 | if (recordKind == null) { |
| 1258 | recordKind = RecordTypeDefinition.RecordKind.OPEN; |
| 1259 | } |
| 1260 | recType.setRecordKind(recordKind); |
| 1261 | return recType; |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | void RecordField(RecordTypeDefinition recType) throws ParseException: |
| 1266 | { |
| 1267 | String fieldName; |
| 1268 | TypeExpression type = null; |
| 1269 | boolean nullable = false; |
| 1270 | } |
| 1271 | { |
| 1272 | fieldName = Identifier() |
| 1273 | { |
| 1274 | String hint = getHint(token); |
| 1275 | IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null; |
| 1276 | } |
| 1277 | <COLON> type = TypeExpr() (<QUES> { nullable = true; } )? |
| 1278 | { |
| 1279 | recType.addField(fieldName, type, nullable, rfdg); |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | TypeReferenceExpression TypeReference() throws ParseException: |
| 1284 | { |
| 1285 | String id = null; |
| 1286 | } |
| 1287 | { |
| 1288 | id = Identifier() |
| 1289 | { |
| 1290 | if (id.equalsIgnoreCase("int")) { |
| 1291 | id = "int64"; |
| 1292 | } |
| 1293 | |
| 1294 | return new TypeReferenceExpression(new Identifier(id)); |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | OrderedListTypeDefinition OrderedListTypeDef() throws ParseException: |
| 1299 | { |
| 1300 | TypeExpression type = null; |
| 1301 | } |
| 1302 | { |
| 1303 | <LEFTBRACKET> |
| 1304 | ( type = TypeExpr() ) |
| 1305 | <RIGHTBRACKET> |
| 1306 | { |
| 1307 | return new OrderedListTypeDefinition(type); |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | |
| 1312 | UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException: |
| 1313 | { |
| 1314 | TypeExpression type = null; |
| 1315 | } |
| 1316 | { |
| 1317 | <LEFTDBLBRACE> |
| 1318 | ( type = TypeExpr() ) |
| 1319 | <RIGHTDBLBRACE> |
| 1320 | { |
| 1321 | return new UnorderedListTypeDefinition(type); |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | FunctionName FunctionName() throws ParseException: |
| 1326 | { |
| 1327 | String first = null; |
| 1328 | String second = null; |
| 1329 | String third = null; |
| 1330 | boolean secondAfterDot = false; |
| 1331 | } |
| 1332 | { |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 1333 | first = Identifier() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1334 | { |
| 1335 | FunctionName result = new FunctionName(); |
| 1336 | result.hint = getHint(token); |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 1337 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1338 | ( <DOT> second = Identifier() |
| 1339 | { |
| 1340 | secondAfterDot = true; |
| 1341 | } |
| 1342 | (<SHARP> third = Identifier())? | <SHARP> second = Identifier() )? |
| 1343 | { |
| 1344 | if (second == null) { |
| 1345 | result.dataverse = defaultDataverse; |
| 1346 | result.library = null; |
| 1347 | result.function = first; |
| 1348 | } else if (third == null) { |
| 1349 | if (secondAfterDot) { |
| 1350 | result.dataverse = first; |
| 1351 | result.library = null; |
| 1352 | result.function = second; |
| 1353 | } else { |
| 1354 | result.dataverse = defaultDataverse; |
| 1355 | result.library = first; |
| 1356 | result.function = second; |
| 1357 | } |
| 1358 | } else { |
| 1359 | result.dataverse = first; |
| 1360 | result.library = second; |
| 1361 | result.function = third; |
| 1362 | } |
| 1363 | |
| 1364 | if (result.function.equalsIgnoreCase("int")) { |
| 1365 | result.function = "int64"; |
| 1366 | } |
| 1367 | return result; |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | Pair<Identifier,Identifier> TypeName() throws ParseException: |
| 1372 | { |
| 1373 | Pair<Identifier,Identifier> name = null; |
| 1374 | } |
| 1375 | { |
| 1376 | name = QualifiedName() |
| 1377 | { |
| 1378 | if (name.first == null) { |
| 1379 | name.first = new Identifier(defaultDataverse); |
| 1380 | } |
| 1381 | return name; |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | String Identifier() throws ParseException: |
| 1386 | { |
| 1387 | String lit = null; |
| 1388 | } |
| 1389 | { |
| 1390 | (<IDENTIFIER> |
| 1391 | { |
| 1392 | return token.image; |
| 1393 | } |
| 1394 | | lit = QuotedString() |
| 1395 | { |
| 1396 | return lit; |
| 1397 | } |
| 1398 | ) |
| 1399 | } |
| 1400 | |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 1401 | void Dataset() throws ParseException: |
| 1402 | { |
| 1403 | } |
| 1404 | { |
| 1405 | (<DATASET>|<COLLECTION>) |
| 1406 | } |
| 1407 | |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1408 | Pair<Integer, Pair<List<String>, TypeExpression>> OpenField() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1409 | { |
| 1410 | TypeExpression fieldType = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1411 | Pair<Integer, List<String>> fieldList = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1412 | } |
| 1413 | { |
| 1414 | fieldList = NestedField() |
| 1415 | ( <COLON> fieldType = IndexedTypeExpr() )? |
| 1416 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1417 | return new Pair<Integer, Pair<List<String>, TypeExpression>> |
| 1418 | (fieldList.first, new Pair<List<String>, TypeExpression>(fieldList.second, fieldType)); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1419 | } |
| 1420 | } |
| 1421 | |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1422 | Pair<Integer, List<String>> NestedField() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1423 | { |
| 1424 | List<String> exprList = new ArrayList<String>(); |
| 1425 | String lit = null; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1426 | int source = 0; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1427 | } |
| 1428 | { |
| 1429 | lit = Identifier() |
| 1430 | { |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1431 | boolean meetParens = false; |
| 1432 | } |
| 1433 | ( |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1434 | LOOKAHEAD(1) |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1435 | <LEFTPAREN><RIGHTPAREN> |
| 1436 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1437 | if(!lit.toLowerCase().equals("meta")){ |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1438 | throw new ParseException("The string before () has to be \"meta\"."); |
| 1439 | } |
| 1440 | meetParens = true; |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1441 | source = 1; |
Yingyi Bu | b9169b6 | 2016-02-26 21:21:49 -0800 | [diff] [blame] | 1442 | } |
| 1443 | )? |
| 1444 | { |
| 1445 | if(!meetParens){ |
| 1446 | exprList.add(lit); |
| 1447 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1448 | } |
| 1449 | (<DOT> |
| 1450 | lit = Identifier() |
| 1451 | { |
| 1452 | exprList.add(lit); |
| 1453 | } |
| 1454 | )* |
| 1455 | { |
Yingyi Bu | c9bfe25 | 2016-03-01 00:02:40 -0800 | [diff] [blame] | 1456 | return new Pair<Integer, List<String>>(source, exprList); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 1460 | String ConstantString() throws ParseException: |
| 1461 | { |
| 1462 | String value = null; |
| 1463 | } |
| 1464 | { |
| 1465 | (value = QuotedString() | value = StringLiteral()) |
| 1466 | { |
| 1467 | return value; |
| 1468 | } |
| 1469 | } |
| 1470 | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1471 | |
| 1472 | String QuotedString() throws ParseException: |
| 1473 | { |
| 1474 | } |
| 1475 | { |
| 1476 | <QUOTED_STRING> |
| 1477 | { |
| 1478 | return removeQuotesAndEscapes(token.image); |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | |
| 1483 | String StringLiteral() throws ParseException: |
| 1484 | { |
| 1485 | } |
| 1486 | { |
| 1487 | <STRING_LITERAL> |
| 1488 | { |
| 1489 | return removeQuotesAndEscapes(token.image); |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | Pair<Identifier,Identifier> QualifiedName() throws ParseException: |
| 1494 | { |
| 1495 | String first = null; |
| 1496 | String second = null; |
| 1497 | } |
| 1498 | { |
| 1499 | first = Identifier() (<DOT> second = Identifier())? |
| 1500 | { |
| 1501 | Identifier id1 = null; |
| 1502 | Identifier id2 = null; |
| 1503 | if (second == null) { |
| 1504 | id2 = new Identifier(first); |
| 1505 | } else |
| 1506 | { |
| 1507 | id1 = new Identifier(first); |
| 1508 | id2 = new Identifier(second); |
| 1509 | } |
| 1510 | return new Pair<Identifier,Identifier>(id1, id2); |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException: |
| 1515 | { |
| 1516 | String first = null; |
| 1517 | String second = null; |
| 1518 | String third = null; |
| 1519 | } |
| 1520 | { |
| 1521 | first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())? |
| 1522 | { |
| 1523 | Identifier id1 = null; |
| 1524 | Identifier id2 = null; |
| 1525 | Identifier id3 = null; |
| 1526 | if (third == null) { |
| 1527 | id2 = new Identifier(first); |
| 1528 | id3 = new Identifier(second); |
| 1529 | } else { |
| 1530 | id1 = new Identifier(first); |
| 1531 | id2 = new Identifier(second); |
| 1532 | id3 = new Identifier(third); |
| 1533 | } |
| 1534 | return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3); |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | FunctionDecl FunctionDeclaration() throws ParseException: |
| 1539 | { |
| 1540 | FunctionDecl funcDecl; |
| 1541 | FunctionSignature signature; |
| 1542 | String functionName; |
| 1543 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 1544 | Expression funcBody; |
| 1545 | createNewScope(); |
| 1546 | } |
| 1547 | { |
| 1548 | <DECLARE> <FUNCTION> functionName = Identifier() |
| 1549 | paramList = ParameterList() |
| 1550 | <LEFTBRACE> funcBody = Expression() <RIGHTBRACE> |
| 1551 | { |
| 1552 | signature = new FunctionSignature(defaultDataverse, functionName, paramList.size()); |
| 1553 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 1554 | funcDecl = new FunctionDecl(signature, paramList, funcBody); |
| 1555 | removeCurrentScope(); |
| 1556 | return funcDecl; |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | |
| 1561 | Query Query() throws ParseException: |
| 1562 | { |
| 1563 | Query query = new Query(); |
| 1564 | // we set the pointers to the dataverses and datasets lists to fill them with entities to be locked |
| 1565 | setDataverses(query.getDataverses()); |
| 1566 | setDatasets(query.getDatasets()); |
| 1567 | Expression expr; |
| 1568 | } |
| 1569 | { |
| 1570 | ( |
| 1571 | expr = Expression() |
| 1572 | | |
| 1573 | expr = SelectExpression(false) |
| 1574 | ) |
| 1575 | { |
| 1576 | query.setBody(expr); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1577 | // we remove the pointers to the locked entities before we return the query object |
| 1578 | setDataverses(null); |
| 1579 | setDatasets(null); |
| 1580 | return query; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | Expression Expression(): |
| 1587 | { |
| 1588 | Expression expr = null; |
| 1589 | Expression exprP = null; |
| 1590 | } |
| 1591 | { |
| 1592 | ( |
| 1593 | LOOKAHEAD(2) |
| 1594 | expr = OperatorExpr() |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame^] | 1595 | | expr = CaseExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1596 | | expr = QuantifiedExpression() |
| 1597 | ) |
| 1598 | { |
| 1599 | return (exprP==null) ? expr : exprP; |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | |
| 1604 | |
| 1605 | Expression OperatorExpr()throws ParseException: |
| 1606 | { |
| 1607 | OperatorExpr op = null; |
| 1608 | Expression operand = null; |
| 1609 | } |
| 1610 | { |
| 1611 | operand = AndExpr() |
| 1612 | ( |
| 1613 | |
| 1614 | <OR> |
| 1615 | { |
| 1616 | if (op == null) { |
| 1617 | op = new OperatorExpr(); |
| 1618 | op.addOperand(operand); |
| 1619 | op.setCurrentop(true); |
| 1620 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1621 | try{ |
| 1622 | op.addOperator(token.image.toLowerCase()); |
| 1623 | } catch (Exception e){ |
| 1624 | throw new ParseException(e.getMessage()); |
| 1625 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | operand = AndExpr() |
| 1629 | { |
| 1630 | op.addOperand(operand); |
| 1631 | } |
| 1632 | |
| 1633 | )* |
| 1634 | |
| 1635 | { |
| 1636 | return op==null? operand: op; |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | Expression AndExpr()throws ParseException: |
| 1641 | { |
| 1642 | OperatorExpr op = null; |
| 1643 | Expression operand = null; |
| 1644 | } |
| 1645 | { |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1646 | operand = NotExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1647 | ( |
| 1648 | |
| 1649 | <AND> |
| 1650 | { |
| 1651 | if (op == null) { |
| 1652 | op = new OperatorExpr(); |
| 1653 | op.addOperand(operand); |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1654 | op.setCurrentop(true); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1655 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1656 | try{ |
| 1657 | op.addOperator(token.image.toLowerCase()); |
| 1658 | } catch (AsterixException e){ |
| 1659 | throw new ParseException(e.getMessage()); |
| 1660 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1663 | operand = NotExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1664 | { |
| 1665 | op.addOperand(operand); |
| 1666 | } |
| 1667 | |
| 1668 | )* |
| 1669 | |
| 1670 | { |
| 1671 | return op==null? operand: op; |
| 1672 | } |
| 1673 | } |
| 1674 | |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1675 | Expression NotExpr()throws ParseException: |
| 1676 | { |
| 1677 | Expression inputExpr; |
| 1678 | boolean not = false; |
| 1679 | } |
| 1680 | { |
| 1681 | (<NOT> { not = true; } )? inputExpr = RelExpr() |
| 1682 | { |
| 1683 | if(not){ |
| 1684 | FunctionSignature signature = new FunctionSignature(null, "not", 1); |
| 1685 | return new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(inputExpr))); |
| 1686 | } else { |
| 1687 | return inputExpr; |
| 1688 | } |
| 1689 | } |
| 1690 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1691 | |
| 1692 | Expression RelExpr()throws ParseException: |
| 1693 | { |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1694 | boolean not = false; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1695 | OperatorExpr op = null; |
| 1696 | Expression operand = null; |
| 1697 | boolean broadcast = false; |
| 1698 | IExpressionAnnotation annotation = null; |
| 1699 | } |
| 1700 | { |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 1701 | operand = IsExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1702 | { |
| 1703 | if (operand instanceof VariableExpr) { |
| 1704 | String hint = getHint(token); |
| 1705 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1706 | broadcast = true; |
| 1707 | } |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | ( |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1712 | LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR> | (<NOT> { not = true; })? (<LIKE>|<IN>)) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1713 | { |
| 1714 | String mhint = getHint(token); |
| 1715 | if (mhint != null) { |
| 1716 | if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1717 | annotation = IndexedNLJoinExpressionAnnotation.INSTANCE; |
| 1718 | } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) { |
| 1719 | annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE; |
| 1720 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1721 | } |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1722 | String operator = token.image.toLowerCase(); |
| 1723 | if(not){ |
| 1724 | operator = "not_" + operator; |
| 1725 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1726 | if (op == null) { |
| 1727 | op = new OperatorExpr(); |
| 1728 | op.addOperand(operand, broadcast); |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1729 | op.setCurrentop(true); |
| 1730 | broadcast = false; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1731 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1732 | try{ |
| 1733 | op.addOperator(operator); |
| 1734 | } catch (AsterixException e){ |
| 1735 | throw new ParseException(e.getMessage()); |
| 1736 | } |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 1737 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1738 | |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 1739 | operand = IsExpr() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1740 | { |
| 1741 | broadcast = false; |
| 1742 | if (operand instanceof VariableExpr) { |
| 1743 | String hint = getHint(token); |
| 1744 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1745 | broadcast = true; |
| 1746 | } |
| 1747 | } |
| 1748 | op.addOperand(operand, broadcast); |
| 1749 | } |
| 1750 | )? |
| 1751 | |
| 1752 | { |
| 1753 | if (annotation != null) { |
| 1754 | op.addHint(annotation); |
| 1755 | } |
| 1756 | return op==null? operand: op; |
| 1757 | } |
| 1758 | } |
| 1759 | |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 1760 | Expression IsExpr() throws ParseException: |
| 1761 | { |
| 1762 | Expression expr = null; |
| 1763 | Expression operand = null; |
| 1764 | boolean not = false; |
| 1765 | } |
| 1766 | { |
| 1767 | operand = AddExpr() |
| 1768 | ( <IS> (<NOT> { not = true; })? (<NULL> | <MISSING> | <UNKOWN>) |
| 1769 | { |
| 1770 | String functionName = "is-" + token.image.toLowerCase(); |
| 1771 | FunctionSignature signature = new FunctionSignature(null, functionName, 1); |
| 1772 | expr = new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(operand))); |
| 1773 | if(not) { |
| 1774 | FunctionSignature notSignature = new FunctionSignature(null, "not", 1); |
| 1775 | expr = new CallExpr(notSignature, new ArrayList<Expression>(Collections.singletonList(expr))); |
| 1776 | } |
| 1777 | } |
| 1778 | )? |
| 1779 | { |
| 1780 | return expr = expr==null? operand : expr; |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1785 | Expression AddExpr()throws ParseException: |
| 1786 | { |
| 1787 | OperatorExpr op = null; |
| 1788 | Expression operand = null; |
| 1789 | } |
| 1790 | { |
| 1791 | operand = MultExpr() |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 1792 | ( |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1793 | LOOKAHEAD(1) |
| 1794 | (<PLUS> | <MINUS>) |
| 1795 | { |
| 1796 | if (op == null) { |
| 1797 | op = new OperatorExpr(); |
| 1798 | op.addOperand(operand); |
| 1799 | op.setCurrentop(true); |
| 1800 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1801 | try{ |
| 1802 | ((OperatorExpr)op).addOperator(token.image); |
| 1803 | } catch (Exception e){ |
| 1804 | throw new ParseException(e.getMessage()); |
| 1805 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | operand = MultExpr() |
| 1809 | { |
| 1810 | op.addOperand(operand); |
| 1811 | } |
| 1812 | )* |
| 1813 | |
| 1814 | { |
| 1815 | return op==null? operand: op; |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | Expression MultExpr()throws ParseException: |
| 1820 | { |
| 1821 | OperatorExpr op = null; |
| 1822 | Expression operand = null; |
| 1823 | } |
| 1824 | { |
| 1825 | operand = UnaryExpr() |
| 1826 | |
| 1827 | (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>) |
| 1828 | { |
| 1829 | if (op == null) { |
| 1830 | op = new OperatorExpr(); |
| 1831 | op.addOperand(operand); |
| 1832 | op.setCurrentop(true); |
| 1833 | } |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1834 | try{ |
| 1835 | op.addOperator(token.image); |
| 1836 | } catch (Exception e){ |
| 1837 | throw new ParseException(e.getMessage()); |
| 1838 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1839 | } |
| 1840 | operand = UnaryExpr() |
| 1841 | { |
| 1842 | op.addOperand(operand); |
| 1843 | } |
| 1844 | )* |
| 1845 | |
| 1846 | { |
| 1847 | return op==null?operand:op; |
| 1848 | } |
| 1849 | } |
| 1850 | |
| 1851 | Expression UnaryExpr() throws ParseException: |
| 1852 | { |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1853 | boolean not = false; |
| 1854 | UnaryExpr uexpr = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1855 | Expression expr = null; |
| 1856 | } |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 1857 | { |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1858 | ( (<PLUS> | <MINUS> | (<NOT> { not = true; } )? <EXISTS> ) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1859 | { |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1860 | String exprType = token.image.toLowerCase(); |
| 1861 | if(not){ |
| 1862 | exprType = "not_" + exprType; |
| 1863 | } |
| 1864 | uexpr = new UnaryExpr(); |
| 1865 | try{ |
| 1866 | uexpr.setExprType(exprType); |
| 1867 | } catch (AsterixException e){ |
| 1868 | throw new ParseException(e.getMessage()); |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 1869 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1870 | } |
| 1871 | )? |
| 1872 | |
| 1873 | expr = ValueExpr() |
| 1874 | { |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1875 | if(uexpr==null){ |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1876 | return expr; |
Yingyi Bu | 196db5d | 2016-07-15 19:07:20 -0700 | [diff] [blame] | 1877 | } |
| 1878 | uexpr.setExpr(expr); |
| 1879 | return uexpr; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | Expression ValueExpr()throws ParseException: |
| 1884 | { |
| 1885 | Expression expr = null; |
| 1886 | Identifier ident = null; |
| 1887 | AbstractAccessor fa = null; |
| 1888 | Expression indexExpr = null; |
| 1889 | } |
| 1890 | { |
| 1891 | expr = PrimaryExpr() ( |
| 1892 | ident = Field() |
| 1893 | { |
| 1894 | fa = (fa == null ? new FieldAccessor(expr, ident) |
| 1895 | : new FieldAccessor(fa, ident)); |
| 1896 | } |
| 1897 | | indexExpr = Index() |
| 1898 | { |
| 1899 | fa = (fa == null ? new IndexAccessor(expr, indexExpr) |
| 1900 | : new IndexAccessor(fa, indexExpr)); |
| 1901 | } |
| 1902 | )* |
| 1903 | { |
| 1904 | return fa == null ? expr : fa; |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | Identifier Field() throws ParseException: |
| 1909 | { |
| 1910 | String ident = null; |
| 1911 | } |
| 1912 | { |
| 1913 | <DOT> ident = Identifier() |
| 1914 | { |
| 1915 | return new Identifier(ident); |
| 1916 | } |
| 1917 | } |
| 1918 | |
| 1919 | Expression Index() throws ParseException: |
| 1920 | { |
| 1921 | Expression expr = null; |
| 1922 | } |
| 1923 | { |
| 1924 | <LEFTBRACKET> ( expr = Expression() |
| 1925 | { |
| 1926 | if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION) |
| 1927 | { |
| 1928 | Literal lit = ((LiteralExpr)expr).getValue(); |
| 1929 | if(lit.getLiteralType() != Literal.Type.INTEGER && |
| 1930 | lit.getLiteralType() != Literal.Type.LONG) { |
| 1931 | throw new ParseException("Index should be an INTEGER"); |
| 1932 | } |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | | <QUES> // ANY |
| 1937 | |
| 1938 | ) |
| 1939 | |
| 1940 | <RIGHTBRACKET> |
| 1941 | { |
| 1942 | return expr; |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | |
| 1947 | Expression PrimaryExpr()throws ParseException: |
| 1948 | { |
| 1949 | Expression expr = null; |
| 1950 | } |
| 1951 | { |
| 1952 | ( LOOKAHEAD(4) |
| 1953 | expr = FunctionCallExpr() |
| 1954 | | expr = Literal() |
| 1955 | | expr = VariableRef() |
| 1956 | | expr = ListConstructor() |
| 1957 | | expr = RecordConstructor() |
| 1958 | | expr = ParenthesizedExpression() |
| 1959 | ) |
| 1960 | { |
| 1961 | return expr; |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | Expression Literal() throws ParseException: |
| 1966 | { |
| 1967 | LiteralExpr lit = new LiteralExpr(); |
| 1968 | String str = null; |
| 1969 | } |
| 1970 | { |
| 1971 | ( str = StringLiteral() |
| 1972 | { |
| 1973 | lit.setValue(new StringLiteral(str)); |
| 1974 | } |
| 1975 | | <INTEGER_LITERAL> |
| 1976 | { |
| 1977 | lit.setValue(new LongIntegerLiteral(new Long(token.image))); |
| 1978 | } |
| 1979 | | <FLOAT_LITERAL> |
| 1980 | { |
| 1981 | lit.setValue(new FloatLiteral(new Float(token.image))); |
| 1982 | } |
| 1983 | | <DOUBLE_LITERAL> |
| 1984 | { |
| 1985 | lit.setValue(new DoubleLiteral(new Double(token.image))); |
| 1986 | } |
Yingyi Bu | 535d86b | 2016-05-23 16:44:25 -0700 | [diff] [blame] | 1987 | | <MISSING> |
| 1988 | { |
| 1989 | lit.setValue(MissingLiteral.INSTANCE); |
| 1990 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 1991 | | <NULL> |
| 1992 | { |
| 1993 | lit.setValue(NullLiteral.INSTANCE); |
| 1994 | } |
| 1995 | | <TRUE> |
| 1996 | { |
| 1997 | lit.setValue(TrueLiteral.INSTANCE); |
| 1998 | } |
| 1999 | | <FALSE> |
| 2000 | { |
| 2001 | lit.setValue(FalseLiteral.INSTANCE); |
| 2002 | } |
| 2003 | ) |
| 2004 | { |
| 2005 | return lit; |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | |
| 2010 | VariableExpr VariableRef() throws ParseException: |
| 2011 | { |
| 2012 | VariableExpr varExp = new VariableExpr(); |
| 2013 | VarIdentifier var = new VarIdentifier(); |
| 2014 | } |
| 2015 | { |
| 2016 | { String id = null; } |
| 2017 | (<IDENTIFIER> { id = token.image; } | id = QuotedString()) |
| 2018 | { |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 2019 | id = SqlppVariableUtil.toInternalVariableName(id); // Prefix user-defined variables with "$" |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2020 | Identifier ident = lookupSymbol(id); |
| 2021 | if (isInForbiddenScopes(id)) { |
| 2022 | 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."); |
| 2023 | } |
| 2024 | if(ident != null) { // exist such ident |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2025 | varExp.setVar((VarIdentifier)ident); |
| 2026 | } else { |
| 2027 | varExp.setVar(var); |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 2028 | varExp.setIsNewVar(false); |
| 2029 | var.setValue(id); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2030 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2031 | return varExp; |
| 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | |
| 2036 | VariableExpr Variable() throws ParseException: |
| 2037 | { |
| 2038 | VariableExpr varExp = new VariableExpr(); |
| 2039 | VarIdentifier var = new VarIdentifier(); |
| 2040 | } |
| 2041 | { |
| 2042 | { String id = null; } |
| 2043 | (<IDENTIFIER> { id = token.image; } | id = QuotedString()) |
| 2044 | { |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 2045 | id = SqlppVariableUtil.toInternalVariableName(id); // prefix user-defined variables with "$". |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2046 | Identifier ident = lookupSymbol(id); |
| 2047 | if(ident != null) { // exist such ident |
| 2048 | varExp.setIsNewVar(false); |
| 2049 | } |
| 2050 | varExp.setVar(var); |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 2051 | var.setValue(id); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2052 | return varExp; |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | Expression ListConstructor() throws ParseException: |
| 2057 | { |
| 2058 | Expression expr = null; |
| 2059 | } |
| 2060 | { |
| 2061 | ( |
| 2062 | expr = OrderedListConstructor() | expr = UnorderedListConstructor() |
| 2063 | ) |
| 2064 | |
| 2065 | { |
| 2066 | return expr; |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | |
| 2071 | ListConstructor OrderedListConstructor() throws ParseException: |
| 2072 | { |
| 2073 | ListConstructor expr = new ListConstructor(); |
| 2074 | List<Expression> exprList = null; |
| 2075 | expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR); |
| 2076 | } |
| 2077 | { |
| 2078 | <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET> |
| 2079 | { |
| 2080 | expr.setExprList(exprList); |
| 2081 | return expr; |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | ListConstructor UnorderedListConstructor() throws ParseException: |
| 2086 | { |
| 2087 | ListConstructor expr = new ListConstructor(); |
| 2088 | List<Expression> exprList = null; |
| 2089 | expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR); |
| 2090 | } |
| 2091 | { |
| 2092 | <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE> |
| 2093 | { |
| 2094 | expr.setExprList(exprList); |
| 2095 | return expr; |
| 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | List<Expression> ExpressionList() throws ParseException: |
| 2100 | { |
| 2101 | Expression expr = null; |
| 2102 | List<Expression> list = null; |
| 2103 | List<Expression> exprList = new ArrayList<Expression>(); |
| 2104 | } |
| 2105 | { |
| 2106 | ( |
| 2107 | expr = Expression() { exprList.add(expr); } |
| 2108 | (LOOKAHEAD(1) <COMMA> list = ExpressionList() { exprList.addAll(list); })? |
| 2109 | )? |
| 2110 | (LOOKAHEAD(1) Comma())? |
| 2111 | { |
| 2112 | return exprList; |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | void Comma(): |
| 2117 | {} |
| 2118 | { |
| 2119 | <COMMA> |
| 2120 | } |
| 2121 | |
| 2122 | RecordConstructor RecordConstructor() throws ParseException: |
| 2123 | { |
| 2124 | RecordConstructor expr = new RecordConstructor(); |
| 2125 | FieldBinding tmp = null; |
| 2126 | List<FieldBinding> fbList = new ArrayList<FieldBinding>(); |
| 2127 | } |
| 2128 | { |
| 2129 | <LEFTBRACE> (tmp = FieldBinding() |
| 2130 | { |
| 2131 | fbList.add(tmp); |
| 2132 | } |
| 2133 | (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE> |
| 2134 | { |
| 2135 | expr.setFbList(fbList); |
| 2136 | return expr; |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | FieldBinding FieldBinding() throws ParseException: |
| 2141 | { |
| 2142 | FieldBinding fb = new FieldBinding(); |
| 2143 | Expression left, right; |
| 2144 | } |
| 2145 | { |
| 2146 | left = Expression() <COLON> right = Expression() |
| 2147 | { |
| 2148 | fb.setLeftExpr(left); |
| 2149 | fb.setRightExpr(right); |
| 2150 | return fb; |
| 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | |
| 2155 | Expression FunctionCallExpr() throws ParseException: |
| 2156 | { |
| 2157 | CallExpr callExpr; |
| 2158 | List<Expression> argList = new ArrayList<Expression>(); |
| 2159 | Expression tmp; |
| 2160 | int arity = 0; |
| 2161 | FunctionName funcName = null; |
| 2162 | String hint = null; |
| 2163 | } |
| 2164 | { |
| 2165 | funcName = FunctionName() |
| 2166 | { |
| 2167 | hint = funcName.hint; |
| 2168 | } |
| 2169 | <LEFTPAREN> (tmp = Expression() |
| 2170 | { |
| 2171 | argList.add(tmp); |
| 2172 | arity ++; |
| 2173 | } |
| 2174 | (<COMMA> tmp = Expression() |
| 2175 | { |
| 2176 | argList.add(tmp); |
| 2177 | arity++; |
| 2178 | } |
| 2179 | )*)? <RIGHTPAREN> |
| 2180 | { |
| 2181 | // TODO use funcName.library |
| 2182 | String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function; |
| 2183 | FunctionSignature signature |
| 2184 | = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity); |
| 2185 | if (signature == null) { |
| 2186 | signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity); |
| 2187 | } |
| 2188 | callExpr = new CallExpr(signature,argList); |
| 2189 | if (hint != null) { |
| 2190 | if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 2191 | callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE); |
| 2192 | } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) { |
| 2193 | callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE); |
| 2194 | } |
| 2195 | } |
| 2196 | return callExpr; |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | Expression ParenthesizedExpression() throws ParseException: |
| 2201 | { |
| 2202 | Expression expr; |
| 2203 | } |
| 2204 | { |
| 2205 | ( |
| 2206 | LOOKAHEAD(2) |
| 2207 | <LEFTPAREN> expr = Expression() <RIGHTPAREN> |
| 2208 | | |
| 2209 | expr = Subquery() |
| 2210 | ) |
| 2211 | { |
| 2212 | return expr; |
| 2213 | } |
| 2214 | } |
| 2215 | |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame^] | 2216 | |
| 2217 | Expression CaseExpr() throws ParseException: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2218 | { |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame^] | 2219 | Expression conditionExpr = new LiteralExpr(TrueLiteral.INSTANCE); |
| 2220 | List<Expression> whenExprs = new ArrayList<Expression>(); |
| 2221 | List<Expression> thenExprs = new ArrayList<Expression>(); |
| 2222 | Expression elseExpr = null; |
| 2223 | |
| 2224 | Expression whenExpr = null; |
| 2225 | Expression thenExpr = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2226 | } |
| 2227 | { |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame^] | 2228 | <CASE> ( conditionExpr = Expression() )? |
| 2229 | ( |
| 2230 | <WHEN> whenExpr = Expression() |
| 2231 | { |
| 2232 | whenExprs.add(whenExpr); |
| 2233 | } |
| 2234 | <THEN> thenExpr = Expression() |
| 2235 | { |
| 2236 | thenExprs.add(thenExpr); |
| 2237 | } |
| 2238 | )* |
| 2239 | (<ELSE> elseExpr = Expression() )? |
| 2240 | <END> |
| 2241 | { |
| 2242 | return new CaseExpression(conditionExpr, whenExprs, thenExprs, elseExpr); |
| 2243 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | SelectExpression SelectExpression(boolean subquery) throws ParseException: { |
| 2247 | List<LetClause> letClauses = new ArrayList<LetClause>(); |
| 2248 | SelectSetOperation selectSetOperation; |
| 2249 | OrderbyClause orderbyClause = null; |
| 2250 | LimitClause limitClause = null; |
| 2251 | createNewScope(); |
| 2252 | } { |
| 2253 | ( letClauses = LetClause() )? |
| 2254 | selectSetOperation = SelectSetOperation() |
| 2255 | (orderbyClause = OrderbyClause() {})? |
| 2256 | (limitClause = LimitClause() {})? |
| 2257 | { |
| 2258 | return new SelectExpression(letClauses, selectSetOperation, orderbyClause, limitClause, subquery); |
| 2259 | } |
| 2260 | } |
| 2261 | |
| 2262 | SelectSetOperation SelectSetOperation() throws ParseException: { |
| 2263 | SetOperationInput setOperationInputLeft; |
| 2264 | List<SetOperationRight> setOperationRights = new ArrayList<SetOperationRight>(); |
| 2265 | } |
| 2266 | { |
| 2267 | { |
| 2268 | SelectBlock selectBlockLeft = null; |
| 2269 | SelectExpression subqueryLeft = null; |
| 2270 | Expression expr = null; |
| 2271 | } |
| 2272 | selectBlockLeft = SelectBlock() |
| 2273 | { |
| 2274 | setOperationInputLeft = new SetOperationInput(selectBlockLeft, subqueryLeft); |
| 2275 | } |
| 2276 | ( |
| 2277 | { |
| 2278 | SetOpType opType = SetOpType.UNION; |
| 2279 | boolean setSemantics = true; |
| 2280 | SelectBlock selectBlockRight = null; |
| 2281 | SelectExpression subqueryRight = null; |
| 2282 | } |
| 2283 | (<UNION> {opType = SetOpType.UNION;} |<INTERSECT> {opType = SetOpType.INTERSECT;} |<EXCEPT> {opType = SetOpType.EXCEPT;}) (<ALL> {setSemantics = false;} )? |
| 2284 | (selectBlockRight = SelectBlock()| subqueryRight = Subquery()) |
| 2285 | { |
| 2286 | setOperationRights.add(new SetOperationRight(opType, setSemantics, new SetOperationInput(selectBlockRight, subqueryRight))); |
| 2287 | } |
| 2288 | )* |
| 2289 | { |
| 2290 | return new SelectSetOperation(setOperationInputLeft, setOperationRights); |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | SelectExpression Subquery() throws ParseException: { |
| 2295 | SelectExpression selectExpr = null; |
| 2296 | } |
| 2297 | { |
| 2298 | <LEFTPAREN> selectExpr = SelectExpression(true) {} <RIGHTPAREN> |
| 2299 | { |
| 2300 | return selectExpr; |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | SelectBlock SelectBlock() throws ParseException: { |
| 2305 | SelectClause selectClause = null; |
| 2306 | FromClause fromClause = null; |
| 2307 | List<LetClause> fromLetClauses = null; |
| 2308 | WhereClause whereClause = null; |
| 2309 | GroupbyClause groupbyClause = null; |
| 2310 | List<LetClause> gbyLetClauses = null; |
| 2311 | HavingClause havingClause = null; |
| 2312 | } |
| 2313 | { |
| 2314 | ( |
| 2315 | selectClause = SelectClause() |
| 2316 | ( |
| 2317 | LOOKAHEAD(1) |
| 2318 | fromClause = FromClause() |
| 2319 | ( |
| 2320 | LOOKAHEAD(1) |
| 2321 | fromLetClauses = LetClause() |
| 2322 | )? |
| 2323 | )? |
| 2324 | (whereClause = WhereClause())? |
| 2325 | ( |
| 2326 | groupbyClause = GroupbyClause() |
| 2327 | ( |
| 2328 | LOOKAHEAD(1) |
| 2329 | gbyLetClauses = LetClause() |
| 2330 | )? |
| 2331 | (havingClause = HavingClause())? |
| 2332 | )? |
| 2333 | | |
| 2334 | fromClause = FromClause() |
| 2335 | ( |
| 2336 | LOOKAHEAD(1) |
| 2337 | fromLetClauses = LetClause() |
| 2338 | )? |
| 2339 | (whereClause = WhereClause())? |
| 2340 | ( |
| 2341 | groupbyClause = GroupbyClause() |
| 2342 | ( |
| 2343 | gbyLetClauses = LetClause() |
| 2344 | )? |
| 2345 | (havingClause = HavingClause())? |
| 2346 | )? |
| 2347 | selectClause = SelectClause() |
| 2348 | ) |
| 2349 | { |
| 2350 | return new SelectBlock(selectClause, fromClause, fromLetClauses, whereClause, groupbyClause, gbyLetClauses, havingClause); |
| 2351 | } |
| 2352 | } |
| 2353 | |
| 2354 | SelectClause SelectClause() throws ParseException: { |
| 2355 | SelectRegular selectRegular = null; |
| 2356 | SelectElement selectElement = null; |
| 2357 | boolean distinct = false; |
| 2358 | } |
| 2359 | { |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2360 | <SELECT> (<ALL>|<DISTINCT> {distinct = true; } )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2361 | ( |
| 2362 | selectRegular = SelectRegular() |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2363 | | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2364 | selectElement = SelectElement() |
Yingyi Bu | a89fae6 | 2016-07-06 07:58:55 -0700 | [diff] [blame] | 2365 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2366 | { |
Yingyi Bu | a89fae6 | 2016-07-06 07:58:55 -0700 | [diff] [blame] | 2367 | if(selectRegular == null && selectElement == null){ |
| 2368 | Projection projection = new Projection(null, null, true, false); |
| 2369 | List<Projection> projections = new ArrayList<Projection>(); |
| 2370 | projections.add(projection); |
| 2371 | selectRegular = new SelectRegular(projections); |
| 2372 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2373 | return new SelectClause(selectElement, selectRegular, distinct); |
| 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | SelectRegular SelectRegular() throws ParseException: { |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2378 | List<Projection> projections = new ArrayList<Projection>(); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2379 | } |
| 2380 | { |
| 2381 | { |
| 2382 | Projection projection = null; |
| 2383 | } |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2384 | projection = Projection() { projections.add(projection); } |
Yingyi Bu | a89fae6 | 2016-07-06 07:58:55 -0700 | [diff] [blame] | 2385 | ( LOOKAHEAD(2) <COMMA> |
| 2386 | projection = Projection() {projections.add(projection);} |
| 2387 | )* |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2388 | { |
| 2389 | return new SelectRegular(projections); |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | SelectElement SelectElement() throws ParseException: { |
| 2394 | Expression expr = null; |
| 2395 | String name = null; |
| 2396 | } |
| 2397 | { |
| 2398 | (<RAW>|<ELEMENT>|<VALUE>) expr = Expression() |
| 2399 | { |
| 2400 | return new SelectElement(expr); |
| 2401 | } |
| 2402 | } |
| 2403 | |
| 2404 | Projection Projection() throws ParseException: { |
| 2405 | Expression expr = null; |
| 2406 | Identifier identifier = null; |
| 2407 | String name = null; |
| 2408 | boolean star = false; |
| 2409 | boolean exprStar = false; |
| 2410 | } |
| 2411 | { |
| 2412 | ( |
| 2413 | LOOKAHEAD(2) |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2414 | expr = Expression() ((<AS>)? name = Identifier())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2415 | | expr = Expression() <DOT> <MUL> {exprStar = true; } |
| 2416 | | <MUL> {star = true; } |
| 2417 | ) |
| 2418 | { |
Yingyi Bu | a89fae6 | 2016-07-06 07:58:55 -0700 | [diff] [blame] | 2419 | if(!star && name == null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2420 | String generatedColumnIdentifier = ExpressionToVariableUtil.getGeneratedIdentifier(expr, false); |
| 2421 | if(generatedColumnIdentifier != null){ |
| 2422 | name = SqlppVariableUtil.toUserDefinedName(generatedColumnIdentifier); |
| 2423 | } |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2424 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2425 | return new Projection(expr, name, star, exprStar); |
| 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | FromClause FromClause() throws ParseException : |
| 2430 | { |
| 2431 | List<FromTerm> fromTerms = new ArrayList<FromTerm>(); |
| 2432 | extendCurrentScope(); |
| 2433 | } |
| 2434 | { |
| 2435 | { |
| 2436 | FromTerm fromTerm = null; |
| 2437 | } |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2438 | <FROM> fromTerm = FromTerm() { fromTerms.add(fromTerm); } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2439 | (LOOKAHEAD(2) <COMMA> fromTerm = FromTerm() { fromTerms.add(fromTerm); } )* |
| 2440 | { |
| 2441 | return new FromClause(fromTerms); |
| 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | FromTerm FromTerm() throws ParseException : |
| 2446 | { |
| 2447 | Expression leftExpr = null; |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2448 | VariableExpr leftVar = null; |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2449 | VariableExpr posVar = null; |
| 2450 | List<AbstractBinaryCorrelateClause> correlateClauses = new ArrayList<AbstractBinaryCorrelateClause>(); |
| 2451 | } |
| 2452 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2453 | leftExpr = Expression() ((<AS>)? leftVar = Variable())? (<AT> posVar = Variable())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2454 | ( |
| 2455 | {JoinType joinType = JoinType.INNER; } |
| 2456 | (joinType = JoinType())? |
| 2457 | { |
| 2458 | AbstractBinaryCorrelateClause correlateClause = null; |
| 2459 | } |
| 2460 | (correlateClause = JoinClause(joinType) |
Yingyi Bu | 6d999ed | 2016-07-13 11:59:06 -0700 | [diff] [blame] | 2461 | | correlateClause = UnnestClause(joinType) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2462 | ) |
| 2463 | { |
| 2464 | correlateClauses.add(correlateClause); |
| 2465 | } |
| 2466 | )* |
| 2467 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2468 | if(leftVar==null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2469 | leftVar = ExpressionToVariableUtil.getGeneratedVariable(leftExpr, true); |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2470 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2471 | return new FromTerm(leftExpr, leftVar, posVar, correlateClauses); |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | JoinClause JoinClause(JoinType joinType) throws ParseException : |
| 2476 | { |
| 2477 | Expression rightExpr = null; |
| 2478 | VariableExpr rightVar = null; |
| 2479 | VariableExpr posVar = null; |
| 2480 | Expression conditionExpr = null; |
| 2481 | } |
| 2482 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2483 | <JOIN> rightExpr = Expression() ((<AS>)? rightVar = Variable())? (<AT> posVar = Variable())? <ON> conditionExpr = Expression() |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2484 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2485 | if(rightVar==null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2486 | rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true); |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2487 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2488 | return new JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr); |
| 2489 | } |
| 2490 | } |
| 2491 | |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2492 | UnnestClause UnnestClause(JoinType joinType) throws ParseException : |
| 2493 | { |
| 2494 | Expression rightExpr; |
| 2495 | VariableExpr rightVar; |
| 2496 | VariableExpr posVar = null; |
| 2497 | } |
| 2498 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2499 | (<UNNEST>|<CORRELATE>|<FLATTEN>) rightExpr = Expression() ((<AS>)? rightVar = Variable()) (<AT> posVar = Variable())? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2500 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2501 | if(rightVar==null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2502 | rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true); |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2503 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2504 | return new UnnestClause(joinType, rightExpr, rightVar, posVar); |
| 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | |
| 2509 | JoinType JoinType() throws ParseException : |
| 2510 | { |
| 2511 | JoinType joinType = JoinType.INNER; |
| 2512 | } |
| 2513 | { |
| 2514 | (<INNER>|<LEFT> (<OUTER>)? {joinType = JoinType.LEFTOUTER; }) |
| 2515 | { |
| 2516 | return joinType; |
| 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | List<LetClause> LetClause() throws ParseException: |
| 2521 | { |
| 2522 | List<LetClause> letList = new ArrayList<LetClause>(); |
| 2523 | LetClause letClause; |
| 2524 | } |
| 2525 | { |
| 2526 | ( |
| 2527 | (<LET>|<LETTING>) letClause = LetElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = LetElement() { letList.add(letClause); })* |
| 2528 | | |
| 2529 | <WITH> letClause = WithElement() { letList.add(letClause); } (LOOKAHEAD(1) <COMMA> letClause = WithElement() { letList.add(letClause); })* |
| 2530 | ) |
| 2531 | { |
| 2532 | return letList; |
| 2533 | } |
| 2534 | } |
| 2535 | |
| 2536 | WhereClause WhereClause()throws ParseException : |
| 2537 | { |
| 2538 | WhereClause wc = new WhereClause(); |
| 2539 | Expression whereExpr; |
| 2540 | } |
| 2541 | { |
| 2542 | <WHERE> whereExpr = Expression() |
| 2543 | { |
| 2544 | wc.setWhereExpr(whereExpr); |
| 2545 | return wc; |
| 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | OrderbyClause OrderbyClause()throws ParseException : |
| 2550 | { |
| 2551 | OrderbyClause oc = new OrderbyClause(); |
| 2552 | Expression orderbyExpr; |
| 2553 | List<Expression> orderbyList = new ArrayList<Expression>(); |
| 2554 | List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >(); |
| 2555 | int numOfOrderby = 0; |
| 2556 | } |
| 2557 | { |
| 2558 | <ORDER> |
| 2559 | { |
| 2560 | String hint = getHint(token); |
| 2561 | if (hint != null) { |
| 2562 | if (hint.startsWith(INMEMORY_HINT)) { |
| 2563 | String splits[] = hint.split(" +"); |
| 2564 | int numFrames = Integer.parseInt(splits[1]); |
| 2565 | int numTuples = Integer.parseInt(splits[2]); |
| 2566 | oc.setNumFrames(numFrames); |
| 2567 | oc.setNumTuples(numTuples); |
| 2568 | } |
| 2569 | } |
| 2570 | } |
| 2571 | <BY> orderbyExpr = Expression() |
| 2572 | { |
| 2573 | orderbyList.add(orderbyExpr); |
| 2574 | OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC; |
| 2575 | } |
| 2576 | ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; }) |
| 2577 | | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 2578 | { |
| 2579 | modifierList.add(modif); |
| 2580 | } |
| 2581 | |
| 2582 | (LOOKAHEAD(2) <COMMA> orderbyExpr = Expression() |
| 2583 | { |
| 2584 | orderbyList.add(orderbyExpr); |
| 2585 | modif = OrderbyClause.OrderModifier.ASC; |
| 2586 | } |
| 2587 | ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; }) |
| 2588 | | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 2589 | { |
| 2590 | modifierList.add(modif); |
| 2591 | } |
| 2592 | )* |
| 2593 | |
| 2594 | { |
| 2595 | oc.setModifierList(modifierList); |
| 2596 | oc.setOrderbyList(orderbyList); |
| 2597 | return oc; |
| 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | GroupbyClause GroupbyClause()throws ParseException : |
| 2602 | { |
| 2603 | GroupbyClause gbc = new GroupbyClause(); |
| 2604 | List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>(); |
| 2605 | VariableExpr var = null; |
| 2606 | VariableExpr withVar = null; |
| 2607 | Expression expr = null; |
| 2608 | VariableExpr decorVar = null; |
| 2609 | Expression decorExpr = null; |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 2610 | |
| 2611 | VariableExpr groupVar = null; |
| 2612 | List<Pair<Expression, Identifier>> groupFieldList = new ArrayList<Pair<Expression, Identifier>>(); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2613 | } |
| 2614 | { |
| 2615 | { |
| 2616 | Scope newScope = extendCurrentScopeNoPush(true); |
| 2617 | // extendCurrentScope(true); |
| 2618 | } |
| 2619 | <GROUP> |
| 2620 | { |
| 2621 | String hint = getHint(token); |
| 2622 | if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) { |
| 2623 | gbc.setHashGroupByHint(true); |
| 2624 | } |
| 2625 | } |
| 2626 | <BY> ( |
| 2627 | expr = Expression() |
| 2628 | (LOOKAHEAD(1) (<AS>)? |
| 2629 | var = Variable() |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 2630 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2631 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2632 | if(var==null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2633 | var = ExpressionToVariableUtil.getGeneratedVariable(expr, false); |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2634 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2635 | GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr); |
| 2636 | vePairList.add(pair1); |
| 2637 | } |
| 2638 | ( LOOKAHEAD(1) <COMMA> |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2639 | { |
| 2640 | var = null; |
| 2641 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2642 | expr = Expression() |
| 2643 | (LOOKAHEAD(1) (<AS>)? |
| 2644 | var = Variable() |
Yingyi Bu | caea8f0 | 2015-11-16 15:12:15 -0800 | [diff] [blame] | 2645 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2646 | { |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2647 | if(var==null){ |
Yingyi Bu | 5b2d4c8 | 2016-07-13 17:56:48 -0700 | [diff] [blame] | 2648 | var = ExpressionToVariableUtil.getGeneratedVariable(expr, false); |
Yingyi Bu | 9e3f9be | 2016-07-01 10:07:37 -0700 | [diff] [blame] | 2649 | } |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2650 | GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr); |
| 2651 | vePairList.add(pair2); |
| 2652 | } |
| 2653 | )* |
| 2654 | ) |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 2655 | (<GROUP> <AS> groupVar = Variable() |
| 2656 | ( LOOKAHEAD(1) |
| 2657 | { |
| 2658 | VariableExpr fieldVarExpr = null; |
| 2659 | String fieldIdentifierStr = null; |
| 2660 | } |
| 2661 | <LEFTPAREN> |
| 2662 | fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier() |
| 2663 | { |
| 2664 | groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr))); |
| 2665 | } |
| 2666 | (<COMMA> |
| 2667 | fieldVarExpr = VariableRef() <AS> fieldIdentifierStr = Identifier() |
| 2668 | { |
| 2669 | groupFieldList.add(new Pair<Expression, Identifier>(fieldVarExpr, new Identifier(fieldIdentifierStr))); |
| 2670 | } |
| 2671 | )* |
| 2672 | <RIGHTPAREN> |
| 2673 | )? |
| 2674 | )? |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2675 | { |
| 2676 | gbc.setGbyPairList(vePairList); |
| 2677 | gbc.setDecorPairList(new ArrayList<GbyVariableExpressionPair>()); |
| 2678 | gbc.setWithVarList(new ArrayList<VariableExpr>()); |
Yingyi Bu | acc12a9 | 2016-03-26 17:25:05 -0700 | [diff] [blame] | 2679 | gbc.setGroupVar(groupVar); |
| 2680 | gbc.setGroupFieldList(groupFieldList); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2681 | replaceCurrentScope(newScope); |
| 2682 | return gbc; |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | HavingClause HavingClause() throws ParseException: |
| 2687 | { |
| 2688 | Expression filterExpr = null; |
| 2689 | } |
| 2690 | { |
| 2691 | <HAVING> filterExpr = Expression() |
| 2692 | { |
| 2693 | return new HavingClause(filterExpr); |
| 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | LimitClause LimitClause() throws ParseException: |
| 2698 | { |
| 2699 | LimitClause lc = new LimitClause(); |
| 2700 | Expression expr; |
| 2701 | pushForbiddenScope(getCurrentScope()); |
| 2702 | } |
| 2703 | { |
| 2704 | <LIMIT> expr = Expression() { lc.setLimitExpr(expr); } |
| 2705 | (<OFFSET> expr = Expression() { lc.setOffset(expr); })? |
| 2706 | |
| 2707 | { |
| 2708 | popForbiddenScope(); |
| 2709 | return lc; |
| 2710 | } |
| 2711 | } |
| 2712 | |
| 2713 | QuantifiedExpression QuantifiedExpression()throws ParseException: |
| 2714 | { |
| 2715 | QuantifiedExpression qc = new QuantifiedExpression(); |
| 2716 | List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>(); |
| 2717 | Expression satisfiesExpr; |
| 2718 | VariableExpr var; |
| 2719 | Expression inExpr; |
| 2720 | QuantifiedPair pair; |
| 2721 | } |
| 2722 | { |
| 2723 | { |
| 2724 | createNewScope(); |
| 2725 | } |
| 2726 | |
Michael Blow | d6cf641 | 2016-06-30 02:44:35 -0400 | [diff] [blame] | 2727 | ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }) |
| 2728 | | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); })) |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2729 | var = Variable() <IN> inExpr = Expression() |
| 2730 | { |
| 2731 | pair = new QuantifiedPair(var, inExpr); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2732 | quantifiedList.add(pair); |
| 2733 | } |
| 2734 | ( |
| 2735 | <COMMA> var = Variable() <IN> inExpr = Expression() |
| 2736 | { |
| 2737 | pair = new QuantifiedPair(var, inExpr); |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2738 | quantifiedList.add(pair); |
| 2739 | } |
| 2740 | )* |
| 2741 | <SATISFIES> satisfiesExpr = Expression() |
| 2742 | { |
| 2743 | qc.setSatisfiesExpr(satisfiesExpr); |
| 2744 | qc.setQuantifiedList(quantifiedList); |
| 2745 | removeCurrentScope(); |
| 2746 | return qc; |
| 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | LetClause LetElement() throws ParseException: |
| 2751 | { |
| 2752 | LetClause lc = new LetClause(); |
| 2753 | VariableExpr varExp; |
| 2754 | Expression beExp; |
| 2755 | extendCurrentScope(); |
| 2756 | } |
| 2757 | { |
| 2758 | varExp = Variable() <EQ> beExp = Expression() |
| 2759 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2760 | lc.setVarExpr(varExp); |
| 2761 | lc.setBindingExpr(beExp); |
| 2762 | return lc; |
| 2763 | } |
| 2764 | } |
| 2765 | |
| 2766 | LetClause WithElement() throws ParseException: |
| 2767 | { |
| 2768 | LetClause lc = new LetClause(); |
| 2769 | VariableExpr varExp; |
| 2770 | Expression beExp; |
| 2771 | extendCurrentScope(); |
| 2772 | } |
| 2773 | { |
| 2774 | varExp = Variable() <AS> beExp = Expression() |
| 2775 | { |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2776 | lc.setVarExpr(varExp); |
| 2777 | lc.setBindingExpr(beExp); |
| 2778 | return lc; |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | TOKEN_MGR_DECLS: |
| 2783 | { |
| 2784 | public int commentDepth = 0; |
| 2785 | public IntStack lexerStateStack = new IntStack(); |
| 2786 | |
| 2787 | public void pushState() { |
| 2788 | lexerStateStack.push( curLexState ); |
| 2789 | } |
| 2790 | |
| 2791 | public void popState(String token) { |
| 2792 | if (lexerStateStack.size() > 0) { |
| 2793 | SwitchTo( lexerStateStack.pop() ); |
| 2794 | } else { |
| 2795 | int errorLine = input_stream.getEndLine(); |
| 2796 | int errorColumn = input_stream.getEndColumn(); |
| 2797 | String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token |
| 2798 | + "\" but state stack is empty."; |
| 2799 | throw new TokenMgrError(msg, -1); |
| 2800 | } |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | <DEFAULT,IN_DBL_BRACE> |
| 2805 | TOKEN [IGNORE_CASE]: |
| 2806 | { |
| 2807 | <ALL : "all"> |
| 2808 | | <AND : "and"> |
| 2809 | | <APPLY : "apply"> |
| 2810 | | <AS : "as"> |
| 2811 | | <ASC : "asc"> |
| 2812 | | <AT : "at"> |
| 2813 | | <AUTOGENERATED : "autogenerated"> |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 2814 | | <BETWEEN : "between"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2815 | | <BTREE : "btree"> |
| 2816 | | <BY : "by"> |
| 2817 | | <CASE : "case"> |
| 2818 | | <CLOSED : "closed"> |
| 2819 | | <CREATE : "create"> |
| 2820 | | <COMPACTION : "compaction"> |
| 2821 | | <COMPACT : "compact"> |
| 2822 | | <CONNECT : "connect"> |
| 2823 | | <CORRELATE : "correlate"> |
| 2824 | | <DATASET : "table"> |
Yingyi Bu | 1c0fff5 | 2016-03-25 20:23:30 -0700 | [diff] [blame] | 2825 | | <COLLECTION : "collection"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2826 | | <DATAVERSE : "database"> |
| 2827 | | <DECLARE : "declare"> |
| 2828 | | <DEFINITION : "definition"> |
| 2829 | | <DELETE : "delete"> |
| 2830 | | <DESC : "desc"> |
| 2831 | | <DISCONNECT : "disconnect"> |
| 2832 | | <DISTINCT : "distinct"> |
| 2833 | | <DROP : "drop"> |
| 2834 | | <ELEMENT : "element"> |
| 2835 | | <ELSE : "else"> |
| 2836 | | <ENFORCED : "enforced"> |
Yingyi Bu | c8c067c | 2016-07-25 23:37:19 -0700 | [diff] [blame^] | 2837 | | <END : "end"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2838 | | <EVERY : "every"> |
| 2839 | | <EXCEPT : "except"> |
| 2840 | | <EXISTS : "exists"> |
| 2841 | | <EXTERNAL : "external"> |
| 2842 | | <FEED : "feed"> |
| 2843 | | <FILTER : "filter"> |
| 2844 | | <FLATTEN : "flatten"> |
| 2845 | | <FOR : "for"> |
| 2846 | | <FORMAT : "format"> |
| 2847 | | <FROM : "from"> |
| 2848 | | <FULL : "full"> |
| 2849 | | <FUNCTION : "function"> |
| 2850 | | <GROUP : "group"> |
| 2851 | | <HAVING : "having"> |
| 2852 | | <HINTS : "hints"> |
| 2853 | | <IF : "if"> |
| 2854 | | <INTO : "into"> |
| 2855 | | <IN : "in"> |
| 2856 | | <INDEX : "index"> |
| 2857 | | <INGESTION : "ingestion"> |
| 2858 | | <INNER : "inner"> |
| 2859 | | <INSERT : "insert"> |
| 2860 | | <INTERNAL : "internal"> |
| 2861 | | <INTERSECT : "intersect"> |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 2862 | | <IS : "is"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2863 | | <JOIN : "join"> |
| 2864 | | <KEYWORD : "keyword"> |
| 2865 | | <KEY : "key"> |
| 2866 | | <LEFT : "left"> |
| 2867 | | <LETTING : "letting"> |
| 2868 | | <LET : "let"> |
Yingyi Bu | a8baf6d | 2016-07-05 21:40:44 -0700 | [diff] [blame] | 2869 | | <LIKE : "like"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2870 | | <LIMIT : "limit"> |
| 2871 | | <LOAD : "load"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2872 | | <NODEGROUP : "nodegroup"> |
| 2873 | | <NGRAM : "ngram"> |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 2874 | | <NOT : "not"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2875 | | <OFFSET : "offset"> |
| 2876 | | <ON : "on"> |
| 2877 | | <OPEN : "open"> |
| 2878 | | <OR : "or"> |
| 2879 | | <ORDER : "order"> |
| 2880 | | <OUTER : "outer"> |
| 2881 | | <OUTPUT : "output"> |
| 2882 | | <PATH : "path"> |
| 2883 | | <POLICY : "policy"> |
| 2884 | | <PRESORTED : "pre-sorted"> |
| 2885 | | <PRIMARY : "primary"> |
| 2886 | | <RAW : "raw"> |
| 2887 | | <REFRESH : "refresh"> |
| 2888 | | <RETURN : "return"> |
| 2889 | | <RTREE : "rtree"> |
| 2890 | | <RUN : "run"> |
| 2891 | | <SATISFIES : "satisfies"> |
| 2892 | | <SECONDARY : "secondary"> |
| 2893 | | <SELECT : "select"> |
| 2894 | | <SET : "set"> |
| 2895 | | <SOME : "some"> |
| 2896 | | <TEMPORARY : "temporary"> |
| 2897 | | <THEN : "then"> |
| 2898 | | <TYPE : "type"> |
| 2899 | | <TO : "to"> |
| 2900 | | <UNION : "union"> |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 2901 | | <UNKOWN : "unknown"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2902 | | <UNNEST : "unnest"> |
Yingyi Bu | daa549c | 2016-06-28 22:30:52 -0700 | [diff] [blame] | 2903 | | <UPDATE : "update"> |
| 2904 | | <USE : "use"> |
| 2905 | | <USING : "using"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2906 | | <VALUE : "value"> |
| 2907 | | <WHEN : "when"> |
| 2908 | | <WHERE : "where"> |
| 2909 | | <WITH : "with"> |
| 2910 | | <WRITE : "write"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | <DEFAULT,IN_DBL_BRACE> |
| 2914 | TOKEN : |
| 2915 | { |
| 2916 | <CARET : "^"> |
| 2917 | | <DIV : "/"> |
| 2918 | | <IDIV : "idiv"> |
| 2919 | | <MINUS : "-"> |
| 2920 | | <MOD : "%"> |
| 2921 | | <MUL : "*"> |
| 2922 | | <PLUS : "+"> |
| 2923 | |
| 2924 | | <LEFTPAREN : "("> |
| 2925 | | <RIGHTPAREN : ")"> |
| 2926 | | <LEFTBRACKET : "["> |
| 2927 | | <RIGHTBRACKET : "]"> |
| 2928 | |
| 2929 | | <ATT : "@"> |
| 2930 | | <COLON : ":"> |
| 2931 | | <COMMA : ","> |
| 2932 | | <DOT : "."> |
| 2933 | | <QUES : "?"> |
| 2934 | | <SEMICOLON : ";"> |
| 2935 | | <SHARP : "#"> |
| 2936 | |
| 2937 | | <LT : "<"> |
| 2938 | | <GT : ">"> |
| 2939 | | <LE : "<="> |
| 2940 | | <GE : ">="> |
| 2941 | | <EQ : "="> |
| 2942 | | <NE : "!="> |
| 2943 | | <SIMILAR : "~="> |
| 2944 | } |
| 2945 | |
| 2946 | <DEFAULT,IN_DBL_BRACE> |
| 2947 | TOKEN : |
| 2948 | { |
| 2949 | <LEFTBRACE : "{"> { pushState(); } : DEFAULT |
| 2950 | } |
| 2951 | |
| 2952 | <DEFAULT> |
| 2953 | TOKEN : |
| 2954 | { |
| 2955 | <RIGHTBRACE : "}"> { popState("}"); } |
| 2956 | } |
| 2957 | |
| 2958 | <DEFAULT,IN_DBL_BRACE> |
| 2959 | TOKEN : |
| 2960 | { |
| 2961 | <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE |
| 2962 | } |
| 2963 | |
| 2964 | <IN_DBL_BRACE> |
| 2965 | TOKEN : |
| 2966 | { |
| 2967 | <RIGHTDBLBRACE : "}}"> { popState("}}"); } |
| 2968 | } |
| 2969 | |
| 2970 | <DEFAULT,IN_DBL_BRACE> |
| 2971 | TOKEN : |
| 2972 | { |
| 2973 | <INTEGER_LITERAL : (<DIGIT>)+ > |
| 2974 | } |
| 2975 | |
| 2976 | <DEFAULT,IN_DBL_BRACE> |
Yingyi Bu | e311a63 | 2016-06-07 18:23:16 -0700 | [diff] [blame] | 2977 | TOKEN [IGNORE_CASE]: |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2978 | { |
Yingyi Bu | 535d86b | 2016-05-23 16:44:25 -0700 | [diff] [blame] | 2979 | <MISSING : "missing"> |
| 2980 | | <NULL : "null"> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 2981 | | <TRUE : "true"> |
| 2982 | | <FALSE : "false"> |
| 2983 | } |
| 2984 | |
| 2985 | <DEFAULT,IN_DBL_BRACE> |
| 2986 | TOKEN : |
| 2987 | { |
| 2988 | <#DIGIT : ["0" - "9"]> |
| 2989 | } |
| 2990 | |
| 2991 | <DEFAULT,IN_DBL_BRACE> |
| 2992 | TOKEN: |
| 2993 | { |
| 2994 | < DOUBLE_LITERAL: <DIGITS> |
| 2995 | | <DIGITS> ( "." <DIGITS> )? |
| 2996 | | "." <DIGITS> |
| 2997 | > |
| 2998 | | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" ) |
| 2999 | | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )? |
| 3000 | | "." <DIGITS> ( "f" | "F" ) |
| 3001 | > |
| 3002 | | <DIGITS : (<DIGIT>)+ > |
| 3003 | } |
| 3004 | |
| 3005 | <DEFAULT,IN_DBL_BRACE> |
| 3006 | TOKEN : |
| 3007 | { |
| 3008 | <#LETTER : ["A" - "Z", "a" - "z"]> |
| 3009 | | <SPECIALCHARS : ["$", "_"]> |
| 3010 | } |
| 3011 | |
| 3012 | <DEFAULT,IN_DBL_BRACE> |
| 3013 | TOKEN : |
| 3014 | { |
| 3015 | // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 3016 | <QUOTED_STRING : "`" ( |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3017 | <EscapeQuot> |
| 3018 | | <EscapeBslash> |
| 3019 | | <EscapeSlash> |
| 3020 | | <EscapeBspace> |
| 3021 | | <EscapeFormf> |
| 3022 | | <EscapeNl> |
| 3023 | | <EscapeCr> |
| 3024 | | <EscapeTab> |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 3025 | | ~["`","\\"])* "`"> |
| 3026 | | <STRING_LITERAL : ("\"" ( |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3027 | <EscapeQuot> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3028 | | <EscapeBslash> |
| 3029 | | <EscapeSlash> |
| 3030 | | <EscapeBspace> |
| 3031 | | <EscapeFormf> |
| 3032 | | <EscapeNl> |
| 3033 | | <EscapeCr> |
| 3034 | | <EscapeTab> |
Yingyi Bu | 6d57e49 | 2016-06-06 21:24:42 -0700 | [diff] [blame] | 3035 | | ~["\"","\\"])* "\"") |
| 3036 | | ("\'"( |
| 3037 | <EscapeApos> |
| 3038 | | <EscapeBslash> |
| 3039 | | <EscapeSlash> |
| 3040 | | <EscapeBspace> |
| 3041 | | <EscapeFormf> |
| 3042 | | <EscapeNl> |
| 3043 | | <EscapeCr> |
| 3044 | | <EscapeTab> |
| 3045 | | ~["\'","\\"])* "\'")> |
Yingyi Bu | 391f09e | 2015-10-29 13:49:39 -0700 | [diff] [blame] | 3046 | | < #EscapeQuot: "\\\"" > |
| 3047 | | < #EscapeApos: "\\\'" > |
| 3048 | | < #EscapeBslash: "\\\\" > |
| 3049 | | < #EscapeSlash: "\\/" > |
| 3050 | | < #EscapeBspace: "\\b" > |
| 3051 | | < #EscapeFormf: "\\f" > |
| 3052 | | < #EscapeNl: "\\n" > |
| 3053 | | < #EscapeCr: "\\r" > |
| 3054 | | < #EscapeTab: "\\t" > |
| 3055 | } |
| 3056 | |
| 3057 | <DEFAULT,IN_DBL_BRACE> |
| 3058 | TOKEN : |
| 3059 | { |
| 3060 | <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*> |
| 3061 | } |
| 3062 | |
| 3063 | <DEFAULT,IN_DBL_BRACE> |
| 3064 | SKIP: |
| 3065 | { |
| 3066 | " " |
| 3067 | | "\t" |
| 3068 | | "\r" |
| 3069 | | "\n" |
| 3070 | } |
| 3071 | |
| 3072 | <DEFAULT,IN_DBL_BRACE> |
| 3073 | SKIP: |
| 3074 | { |
| 3075 | <"//" (~["\n"])* "\n"> |
| 3076 | } |
| 3077 | |
| 3078 | <DEFAULT,IN_DBL_BRACE> |
| 3079 | SKIP: |
| 3080 | { |
| 3081 | <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
| 3082 | } |
| 3083 | |
| 3084 | <DEFAULT,IN_DBL_BRACE> |
| 3085 | SKIP: |
| 3086 | { |
| 3087 | <"/*"> { pushState(); } : INSIDE_COMMENT |
| 3088 | } |
| 3089 | |
| 3090 | <INSIDE_COMMENT> |
| 3091 | SPECIAL_TOKEN: |
| 3092 | { |
| 3093 | <"+"(" ")*(~["*"])*> |
| 3094 | } |
| 3095 | |
| 3096 | <INSIDE_COMMENT> |
| 3097 | SKIP: |
| 3098 | { |
| 3099 | <"/*"> { pushState(); } |
| 3100 | } |
| 3101 | |
| 3102 | <INSIDE_COMMENT> |
| 3103 | SKIP: |
| 3104 | { |
| 3105 | <"*/"> { popState("*/"); } |
| 3106 | | <~[]> |
| 3107 | } |