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