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