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