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