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