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