Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.apache.druid.sql.calcite.parser.DruidSqlParserImpl Maven / Gradle / Ivy
/* Generated By:JavaCC: Do not edit this line. DruidSqlParserImpl.java */
package org.apache.druid.sql.calcite.parser;
import java.util.List;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlInsert;
import org.apache.calcite.sql.SqlNodeList;
import org.apache.calcite.sql.SqlBasicCall;
import org.apache.druid.java.util.common.granularity.Granularity;
import org.apache.druid.java.util.common.granularity.GranularityType;
import org.apache.druid.java.util.common.granularity.Granularities;
import org.apache.druid.sql.calcite.parser.DruidSqlInsert;
import org.apache.druid.sql.calcite.parser.DruidSqlParserUtils;
import org.apache.druid.sql.calcite.external.ExtendOperator;
import org.apache.druid.sql.calcite.external.ParameterizeOperator;
import org.apache.druid.sql.calcite.parser.ExternalDestinationSqlIdentifier;
import java.util.HashMap;
import org.apache.calcite.avatica.util.Casing;
import org.apache.calcite.avatica.util.TimeUnit;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.runtime.CalciteContextException;
import org.apache.calcite.sql.JoinConditionType;
import org.apache.calcite.sql.JoinType;
import org.apache.calcite.sql.SqlAlter;
import org.apache.calcite.sql.SqlBasicTypeNameSpec;
import org.apache.calcite.sql.SqlBinaryOperator;
import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlCharStringLiteral;
import org.apache.calcite.sql.SqlCollation;
import org.apache.calcite.sql.SqlCollectionTypeNameSpec;
import org.apache.calcite.sql.SqlDataTypeSpec;
import org.apache.calcite.sql.SqlDelete;
import org.apache.calcite.sql.SqlDescribeSchema;
import org.apache.calcite.sql.SqlDescribeTable;
import org.apache.calcite.sql.SqlDynamicParam;
import org.apache.calcite.sql.SqlExplain;
import org.apache.calcite.sql.SqlExplainFormat;
import org.apache.calcite.sql.SqlExplainLevel;
import org.apache.calcite.sql.SqlFunction;
import org.apache.calcite.sql.SqlFunctionCategory;
import org.apache.calcite.sql.SqlHint;
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlInsert;
import org.apache.calcite.sql.SqlInsertKeyword;
import org.apache.calcite.sql.SqlIntervalQualifier;
import org.apache.calcite.sql.SqlJdbcDataTypeName;
import org.apache.calcite.sql.SqlJdbcFunctionCall;
import org.apache.calcite.sql.SqlJoin;
import org.apache.calcite.sql.SqlJsonConstructorNullClause;
import org.apache.calcite.sql.SqlJsonEncoding;
import org.apache.calcite.sql.SqlJsonExistsErrorBehavior;
import org.apache.calcite.sql.SqlJsonEmptyOrError;
import org.apache.calcite.sql.SqlJsonQueryEmptyOrErrorBehavior;
import org.apache.calcite.sql.SqlJsonQueryWrapperBehavior;
import org.apache.calcite.sql.SqlJsonValueEmptyOrErrorBehavior;
import org.apache.calcite.sql.SqlJsonValueReturning;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.SqlLiteral;
import org.apache.calcite.sql.SqlMatchRecognize;
import org.apache.calcite.sql.SqlMerge;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlNodeList;
import org.apache.calcite.sql.SqlNumericLiteral;
import org.apache.calcite.sql.SqlOperator;
import org.apache.calcite.sql.SqlOrderBy;
import org.apache.calcite.sql.SqlPivot;
import org.apache.calcite.sql.SqlPostfixOperator;
import org.apache.calcite.sql.SqlPrefixOperator;
import org.apache.calcite.sql.SqlRowTypeNameSpec;
import org.apache.calcite.sql.SqlSampleSpec;
import org.apache.calcite.sql.SqlSelect;
import org.apache.calcite.sql.SqlSelectKeyword;
import org.apache.calcite.sql.SqlSetOption;
import org.apache.calcite.sql.SqlSnapshot;
import org.apache.calcite.sql.SqlTableRef;
import org.apache.calcite.sql.SqlTypeNameSpec;
import org.apache.calcite.sql.SqlUnnestOperator;
import org.apache.calcite.sql.SqlUnpivot;
import org.apache.calcite.sql.SqlUpdate;
import org.apache.calcite.sql.SqlUserDefinedTypeNameSpec;
import org.apache.calcite.sql.SqlUtil;
import org.apache.calcite.sql.SqlWindow;
import org.apache.calcite.sql.SqlWith;
import org.apache.calcite.sql.SqlWithItem;
import org.apache.calcite.sql.fun.SqlCase;
import org.apache.calcite.sql.fun.SqlInternalOperators;
import org.apache.calcite.sql.fun.SqlLibraryOperators;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.fun.SqlTrimFunction;
import org.apache.calcite.sql.parser.Span;
import org.apache.calcite.sql.parser.SqlAbstractParserImpl;
import org.apache.calcite.sql.parser.SqlParseException;
import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.parser.SqlParserImplFactory;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.sql.parser.SqlParserUtil;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.sql.validate.SqlConformance;
import org.apache.calcite.sql.validate.SqlConformanceEnum;
import org.apache.calcite.util.Glossary;
import org.apache.calcite.util.Pair;
import org.apache.calcite.util.SourceStringReader;
import org.apache.calcite.util.Util;
import org.apache.calcite.util.trace.CalciteTrace;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
import java.io.Reader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static org.apache.calcite.util.Static.RESOURCE;
/**
* SQL parser, generated from Parser.jj by JavaCC.
*
* The public wrapper for this parser is {@link SqlParser}.
*/
public class DruidSqlParserImpl extends SqlAbstractParserImpl implements DruidSqlParserImplConstants {
private static final Logger LOGGER = CalciteTrace.getParserTracer();
// Can't use quoted literal because of a bug in how JavaCC translates
// backslash-backslash.
private static final char BACKSLASH = 0x5c;
private static final char DOUBLE_QUOTE = 0x22;
private static final String DQ = DOUBLE_QUOTE + "";
private static final String DQDQ = DQ + DQ;
private static final SqlLiteral LITERAL_ZERO =
SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO);
private static final SqlLiteral LITERAL_ONE =
SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO);
private static final SqlLiteral LITERAL_MINUS_ONE =
SqlLiteral.createExactNumeric("-1", SqlParserPos.ZERO);
private static Metadata metadata;
private Casing unquotedCasing;
private Casing quotedCasing;
private int identifierMaxLength;
private SqlConformance conformance;
/**
* {@link SqlParserImplFactory} implementation for creating parser.
*/
public static final SqlParserImplFactory FACTORY = new SqlParserImplFactory() {
public SqlAbstractParserImpl getParser(Reader reader) {
final DruidSqlParserImpl parser = new DruidSqlParserImpl(reader);
if (reader instanceof SourceStringReader) {
final String sql =
((SourceStringReader) reader).getSourceString();
parser.setOriginalSql(sql);
}
return parser;
}
};
public SqlParseException normalizeException(Throwable ex) {
try {
if (ex instanceof ParseException) {
ex = cleanupParseException((ParseException) ex);
}
return convertException(ex);
} catch (ParseException e) {
throw new AssertionError(e);
}
}
public Metadata getMetadata() {
synchronized (DruidSqlParserImpl.class) {
if (metadata == null) {
metadata = new MetadataImpl(
new DruidSqlParserImpl(new java.io.StringReader("")));
}
return metadata;
}
}
public void setTabSize(int tabSize) {
jj_input_stream.setTabSize(tabSize);
}
public void switchTo(SqlAbstractParserImpl.LexicalState state) {
final int stateOrdinal =
Arrays.asList(DruidSqlParserImplTokenManager.lexStateNames)
.indexOf(state.name());
token_source.SwitchTo(stateOrdinal);
}
public void setQuotedCasing(Casing quotedCasing) {
this.quotedCasing = quotedCasing;
}
public void setUnquotedCasing(Casing unquotedCasing) {
this.unquotedCasing = unquotedCasing;
}
public void setIdentifierMaxLength(int identifierMaxLength) {
this.identifierMaxLength = identifierMaxLength;
}
public void setConformance(SqlConformance conformance) {
this.conformance = conformance;
}
public SqlNode parseSqlExpressionEof() throws Exception {
return SqlExpressionEof();
}
public SqlNode parseSqlStmtEof() throws Exception {
return SqlStmtEof();
}
public SqlNodeList parseSqlStmtList() throws Exception {
return SqlStmtList();
}
public SqlNode parseArray() throws SqlParseException {
switchTo(LexicalState.BQID);
try {
return ArrayLiteral();
} catch (ParseException ex) {
throw normalizeException(ex);
} catch (TokenMgrError ex) {
throw normalizeException(ex);
}
}
private SqlNode extend(SqlNode table, SqlNodeList extendList) {
return SqlStdOperatorTable.EXTEND.createCall(
Span.of(table, extendList).pos(), table, extendList);
}
/** Adds a warning that a token such as "HOURS" was used,
* whereas the SQL standard only allows "HOUR".
*
*
Currently, we silently add an exception to a list of warnings. In
* future, we may have better compliance checking, for example a strict
* compliance mode that throws if any non-standard features are used. */
private TimeUnit warn(TimeUnit timeUnit) throws ParseException {
final String token = getToken(0).image.toUpperCase(Locale.ROOT);
warnings.add(
SqlUtil.newContextException(getPos(),
RESOURCE.nonStandardFeatureUsed(token)));
return timeUnit;
}
void debug_message1() throws ParseException {
LOGGER.info("{} , {}", getToken(0).image, getToken(1).image);
}
String unquotedIdentifier() throws ParseException {
return SqlParserUtil.toCase(getToken(0).image, unquotedCasing);
}
/**
* Allows parser to be extended with new types of table references. The
* default implementation of this production is empty.
*/
final public SqlNode ExtendedTableRef() throws ParseException {
UnusedExtension();
{if (true) return null;}
throw new Error("Missing return statement in function");
}
/**
* Allows an OVER clause following a table expression as an extension to
* standard SQL syntax. The default implementation of this production is empty.
*/
final public SqlNode TableOverOpt() throws ParseException {
{if (true) return null;}
throw new Error("Missing return statement in function");
}
/*
* Parses dialect-specific keywords immediately following the SELECT keyword.
*/
final public void SqlSelectKeywords(List keywords) throws ParseException {
E();
}
/*
* Parses dialect-specific keywords immediately following the INSERT keyword.
*/
final public void SqlInsertKeywords(List keywords) throws ParseException {
E();
}
/*
* Parse Floor/Ceil function parameters
*/
final public SqlNode FloorCeilOptions(Span s, boolean floorFlag) throws ParseException {
SqlNode node;
node = StandardFloorCeilOptions(s, floorFlag);
{if (true) return node;}
throw new Error("Missing return statement in function");
}
void E() throws ParseException {
}
List startList(Object o) throws ParseException {
List list = new ArrayList();
list.add(o);
return list;
}
protected SqlParserPos getPos() throws ParseException {
return new SqlParserPos(
token.beginLine,
token.beginColumn,
token.endLine,
token.endColumn);
}
Span span() throws ParseException {
return Span.of(getPos());
}
void checkQueryExpression(ExprContext exprContext) throws ParseException {
switch (exprContext) {
case ACCEPT_NON_QUERY:
case ACCEPT_SUB_QUERY:
case ACCEPT_CURSOR:
throw SqlUtil.newContextException(getPos(),
RESOURCE.illegalQueryExpression());
}
}
void checkNonQueryExpression(ExprContext exprContext) throws ParseException {
switch (exprContext) {
case ACCEPT_QUERY:
throw SqlUtil.newContextException(getPos(),
RESOURCE.illegalNonQueryExpression());
}
}
SqlNode checkNotJoin(SqlNode e) throws ParseException {
if (e instanceof SqlJoin) {
throw SqlUtil.newContextException(e.getParserPosition(),
RESOURCE.illegalJoinExpression());
}
return e;
}
SqlParseException convertException(Throwable ex) throws ParseException {
if (ex instanceof SqlParseException) {
return (SqlParseException) ex;
}
SqlParserPos pos = null;
int[][] expectedTokenSequences = null;
String[] tokenImage = null;
if (ex instanceof ParseException) {
ParseException pex = (ParseException) ex;
expectedTokenSequences = pex.expectedTokenSequences;
tokenImage = pex.tokenImage;
if (pex.currentToken != null) {
final Token token = pex.currentToken.next;
// Checks token.image.equals("1") to avoid recursive call.
// The SqlAbstractParserImpl#MetadataImpl constructor uses constant "1" to
// throw intentionally to collect the expected tokens.
if (!token.image.equals("1")
&& getMetadata().isKeyword(token.image)
&& SqlParserUtil.allowsIdentifier(tokenImage, expectedTokenSequences)) {
// If the next token is a keyword, reformat the error message as:
// Incorrect syntax near the keyword '{keyword}' at line {line_number},
// column {column_number}.
final String expecting = ex.getMessage()
.substring(ex.getMessage().indexOf("Was expecting"));
final String errorMsg = String.format("Incorrect syntax near the keyword '%s' "
+ "at line %d, column %d.\n%s",
token.image,
token.beginLine,
token.beginColumn,
expecting);
// Replace the ParseException with explicit error message.
ex = new ParseException(errorMsg);
}
pos = new SqlParserPos(
token.beginLine,
token.beginColumn,
token.endLine,
token.endColumn);
}
} else if (ex instanceof TokenMgrError) {
expectedTokenSequences = null;
tokenImage = null;
// Example:
// Lexical error at line 3, column 24. Encountered "#" after "a".
final java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(
"(?s)Lexical error at line ([0-9]+), column ([0-9]+).*");
java.util.regex.Matcher matcher = pattern.matcher(ex.getMessage());
if (matcher.matches()) {
int line = Integer.parseInt(matcher.group(1));
int column = Integer.parseInt(matcher.group(2));
pos = new SqlParserPos(line, column, line, column);
}
} else if (ex instanceof CalciteContextException) {
// CalciteContextException is the standard wrapper for exceptions
// produced by the validator, but in the parser, the standard is
// SqlParseException; so, strip it away. In case you were wondering,
// the CalciteContextException appears because the parser
// occasionally calls into validator-style code such as
// SqlSpecialOperator.reduceExpr.
CalciteContextException ece =
(CalciteContextException) ex;
pos = new SqlParserPos(
ece.getPosLine(),
ece.getPosColumn(),
ece.getEndPosLine(),
ece.getEndPosColumn());
ex = ece.getCause();
}
return new SqlParseException(
ex.getMessage(), pos, expectedTokenSequences, tokenImage, ex);
}
ParseException cleanupParseException(ParseException ex) throws ParseException {
if (ex.expectedTokenSequences == null) {
return ex;
}
int iIdentifier = Arrays.asList(ex.tokenImage).indexOf("");
// Find all sequences in the error which contain identifier. For
// example,
// {}
// {A}
// {B, C}
// {D, }
// {D, A}
// {D, B}
//
// would yield
// {}
// {D}
final List prefixList = new ArrayList();
for (int i = 0; i < ex.expectedTokenSequences.length; ++i) {
int[] seq = ex.expectedTokenSequences[i];
int j = seq.length - 1;
int i1 = seq[j];
if (i1 == iIdentifier) {
int[] prefix = new int[j];
System.arraycopy(seq, 0, prefix, 0, j);
prefixList.add(prefix);
}
}
if (prefixList.isEmpty()) {
return ex;
}
int[][] prefixes = (int[][])
prefixList.toArray(new int[prefixList.size()][]);
// Since was one of the possible productions,
// we know that the parser will also have included all
// of the non-reserved keywords (which are treated as
// identifiers in non-keyword contexts). So, now we need
// to clean those out, since they're totally irrelevant.
final List list = new ArrayList();
Metadata metadata = getMetadata();
for (int i = 0; i < ex.expectedTokenSequences.length; ++i) {
int [] seq = ex.expectedTokenSequences[i];
String tokenImage = ex.tokenImage[seq[seq.length - 1]];
String token = SqlParserUtil.getTokenVal(tokenImage);
if (token == null || !metadata.isNonReservedKeyword(token)) {
list.add(seq);
continue;
}
boolean match = matchesPrefix(seq, prefixes);
if (!match) {
list.add(seq);
}
}
ex.expectedTokenSequences =
(int [][]) list.toArray(new int [list.size()][]);
return ex;
}
boolean matchesPrefix(int[] seq, int[][] prefixes) throws ParseException {
nextPrefix:
for (int[] prefix : prefixes) {
if (seq.length == prefix.length + 1) {
for (int k = 0; k < prefix.length; k++) {
if (prefix[k] != seq[k]) {
continue nextPrefix;
}
}
return true;
}
}
return false;
}
/*****************************************
* Syntactical Descriptions *
*****************************************/
final public SqlNode ExprOrJoinOrOrderedQuery(ExprContext exprContext) throws ParseException {
SqlNode e;
final List list = new ArrayList();
if (jj_2_3(2)) {
e = Query(exprContext);
e = OrderByLimitOpt(e);
{if (true) return e;}
} else if (jj_2_4(2)) {
e = TableRef1(ExprContext.ACCEPT_QUERY_OR_JOIN);
label_1:
while (true) {
if (jj_2_1(2)) {
;
} else {
break label_1;
}
e = JoinTable(e);
}
list.add(e);
label_2:
while (true) {
if (jj_2_2(2)) {
;
} else {
break label_2;
}
AddSetOpQuery(list, exprContext);
}
{if (true) return SqlParserUtil.toTree(list);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses either a row expression or a query expression with an optional
* ORDER BY.
*
* Postgres syntax for limit:
*
*
* [ LIMIT { count | ALL } ]
* [ OFFSET start ]
*
*
* Trino syntax for limit:
*
*
* [ OFFSET start ]
* [ LIMIT { count | ALL } ]
*
*
* MySQL syntax for limit:
*
*
* [ LIMIT { count | start, count } ]
*
*
* SQL:2008 syntax for limit:
*
*
* [ OFFSET start { ROW | ROWS } ]
* [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]
*
*/
final public SqlNode OrderedQueryOrExpr(ExprContext exprContext) throws ParseException {
SqlNode e;
e = QueryOrExpr(exprContext);
e = OrderByLimitOpt(e);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/** Reads optional "ORDER BY", "LIMIT", "OFFSET", "FETCH" following a query,
* {@code e}. If any of them are present, adds them to the query;
* otherwise returns the query unchanged.
* Throws if they are present and {@code e} is not a query. */
final public SqlNode OrderByLimitOpt(SqlNode e) throws ParseException {
final SqlNodeList orderBy;
final Span s = Span.of();
SqlNode[] offsetFetch = {null, null};
if (jj_2_5(2)) {
// use the syntactic type of the expression we just parsed
// to decide whether ORDER BY makes sense
orderBy = OrderBy(e.isA(SqlKind.QUERY));
} else {
orderBy = null;
}
if (jj_2_13(2)) {
if (jj_2_10(2)) {
LimitClause(s, offsetFetch);
if (jj_2_6(2)) {
OffsetClause(s, offsetFetch);
} else {
;
}
} else if (jj_2_11(2)) {
OffsetClause(s, offsetFetch);
if (jj_2_9(2)) {
if (jj_2_7(2)) {
LimitClause(s, offsetFetch);
if (!this.conformance.isOffsetLimitAllowed()) {
{if (true) throw SqlUtil.newContextException(s.end(this),
RESOURCE.offsetLimitNotAllowed());}
}
} else if (jj_2_8(2)) {
FetchClause(offsetFetch);
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
} else if (jj_2_12(2)) {
FetchClause(offsetFetch);
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
if (orderBy != null || offsetFetch[0] != null || offsetFetch[1] != null) {
{if (true) return new SqlOrderBy(getPos(), e,
Util.first(orderBy, SqlNodeList.EMPTY),
offsetFetch[0], offsetFetch[1]);}
}
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/**
* Parses an OFFSET clause in an ORDER BY expression.
*/
final public void OffsetClause(Span s, SqlNode[] offsetFetch) throws ParseException {
jj_consume_token(OFFSET);
s.add(this);
offsetFetch[0] = UnsignedNumericLiteralOrParam();
if (jj_2_16(2)) {
if (jj_2_14(2)) {
jj_consume_token(ROW);
} else if (jj_2_15(2)) {
jj_consume_token(ROWS);
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
}
/**
* Parses a FETCH clause in an ORDER BY expression.
*/
final public void FetchClause(SqlNode[] offsetFetch) throws ParseException {
jj_consume_token(FETCH);
if (jj_2_17(2)) {
jj_consume_token(FIRST);
} else if (jj_2_18(2)) {
jj_consume_token(NEXT);
} else {
jj_consume_token(-1);
throw new ParseException();
}
offsetFetch[1] = UnsignedNumericLiteralOrParam();
if (jj_2_19(2)) {
jj_consume_token(ROW);
} else if (jj_2_20(2)) {
jj_consume_token(ROWS);
} else {
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(ONLY);
}
/**
* Parses a LIMIT clause in an ORDER BY expression.
*/
final public void LimitClause(Span s, SqlNode[] offsetFetch) throws ParseException {
jj_consume_token(LIMIT);
s.add(this);
if (jj_2_21(2)) {
offsetFetch[0] = UnsignedNumericLiteralOrParam();
jj_consume_token(COMMA);
offsetFetch[1] = UnsignedNumericLiteralOrParam();
if (!this.conformance.isLimitStartCountAllowed()) {
{if (true) throw SqlUtil.newContextException(s.end(this),
RESOURCE.limitStartCountNotAllowed());}
}
} else if (jj_2_22(2)) {
offsetFetch[1] = UnsignedNumericLiteralOrParam();
} else if (jj_2_23(2)) {
jj_consume_token(ALL);
} else {
jj_consume_token(-1);
throw new ParseException();
}
}
/**
* Parses a leaf in a query expression (SELECT, VALUES or TABLE).
*/
final public SqlNode LeafQuery(ExprContext exprContext) throws ParseException {
SqlNode e;
if (jj_2_24(2)) {
// ensure a query is legal in this context
checkQueryExpression(exprContext);
e = SqlSelect();
{if (true) return e;}
} else if (jj_2_25(2)) {
e = TableConstructor();
{if (true) return e;}
} else if (jj_2_26(2)) {
e = ExplicitTable(getPos());
{if (true) return e;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses a parenthesized query or single row expression.
* Depending on {@code exprContext}, may also accept a join.
*/
final public SqlNode ParenthesizedExpression(ExprContext exprContext) throws ParseException {
SqlNode e;
jj_consume_token(LPAREN);
// we've now seen left paren, so queries inside should
// be allowed as sub-queries
switch (exprContext) {
case ACCEPT_SUB_QUERY:
exprContext = ExprContext.ACCEPT_NONCURSOR;
break;
case ACCEPT_CURSOR:
exprContext = ExprContext.ACCEPT_ALL;
break;
}
e = ExprOrJoinOrOrderedQuery(exprContext);
jj_consume_token(RPAREN);
exprContext.throwIfNotCompatible(e);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/**
* Parses a parenthesized query or comma-list of row expressions.
*
* REVIEW jvs 8-Feb-2004: There's a small hole in this production. It can be
* used to construct something like
*
*
* WHERE x IN (select count(*) from t where c=d,5)
*
*
* which should be illegal. The above is interpreted as equivalent to
*
*
* WHERE x IN ((select count(*) from t where c=d),5)
*
*
* which is a legal use of a sub-query. The only way to fix the hole is to
* be able to remember whether a subexpression was parenthesized or not, which
* means preserving parentheses in the SqlNode tree. This is probably
* desirable anyway for use in purely syntactic parsing applications (e.g. SQL
* pretty-printer). However, if this is done, it's important to also make
* isA() on the paren node call down to its operand so that we can
* always correctly discriminate a query from a row expression.
*/
final public SqlNodeList ParenthesizedQueryOrCommaList(ExprContext exprContext) throws ParseException {
SqlNode e;
final List list = new ArrayList();
ExprContext firstExprContext = exprContext;
final Span s;
jj_consume_token(LPAREN);
// we've now seen left paren, so a query by itself should
// be interpreted as a sub-query
s = span();
switch (exprContext) {
case ACCEPT_SUB_QUERY:
firstExprContext = ExprContext.ACCEPT_NONCURSOR;
break;
case ACCEPT_CURSOR:
firstExprContext = ExprContext.ACCEPT_ALL;
break;
}
e = OrderedQueryOrExpr(firstExprContext);
list.add(e);
label_3:
while (true) {
if (jj_2_27(2)) {
;
} else {
break label_3;
}
jj_consume_token(COMMA);
// a comma-list can't appear where only a query is expected
checkNonQueryExpression(exprContext);
AddExpression(list, exprContext);
}
jj_consume_token(RPAREN);
{if (true) return new SqlNodeList(list, s.end(this));}
throw new Error("Missing return statement in function");
}
/** As ParenthesizedQueryOrCommaList, but allows DEFAULT
* in place of any of the expressions. For example,
* {@code (x, DEFAULT, null, DEFAULT)}. */
final public SqlNodeList ParenthesizedQueryOrCommaListWithDefault(ExprContext exprContext) throws ParseException {
SqlNode e;
final List list = new ArrayList();
ExprContext firstExprContext = exprContext;
final Span s;
jj_consume_token(LPAREN);
// we've now seen left paren, so a query by itself should
// be interpreted as a sub-query
s = span();
switch (exprContext) {
case ACCEPT_SUB_QUERY:
firstExprContext = ExprContext.ACCEPT_NONCURSOR;
break;
case ACCEPT_CURSOR:
firstExprContext = ExprContext.ACCEPT_ALL;
break;
}
if (jj_2_28(2)) {
e = OrderedQueryOrExpr(firstExprContext);
list.add(e);
} else if (jj_2_29(2)) {
e = Default();
list.add(e);
} else {
jj_consume_token(-1);
throw new ParseException();
}
label_4:
while (true) {
if (jj_2_30(2)) {
;
} else {
break label_4;
}
jj_consume_token(COMMA);
// a comma-list can't appear where only a query is expected
checkNonQueryExpression(exprContext);
if (jj_2_31(2)) {
e = Expression(exprContext);
list.add(e);
} else if (jj_2_32(2)) {
e = Default();
list.add(e);
} else {
jj_consume_token(-1);
throw new ParseException();
}
}
jj_consume_token(RPAREN);
{if (true) return new SqlNodeList(list, s.end(this));}
throw new Error("Missing return statement in function");
}
/**
* Parses function parameter lists.
* If the list starts with DISTINCT or ALL, it is discarded.
*/
final public List UnquantifiedFunctionParameterList(ExprContext exprContext) throws ParseException {
final List args;
args = FunctionParameterList(exprContext);
args.remove(0); // remove DISTINCT or ALL, if present
{if (true) return args;}
throw new Error("Missing return statement in function");
}
/**
* Parses function parameter lists including DISTINCT keyword recognition,
* DEFAULT, and named argument assignment.
*/
final public List FunctionParameterList(ExprContext exprContext) throws ParseException {
final SqlLiteral qualifier;
final List list = new ArrayList();
jj_consume_token(LPAREN);
if (jj_2_33(2)) {
qualifier = AllOrDistinct();
list.add(qualifier);
} else {
list.add(null);
}
AddArg0(list, exprContext);
label_5:
while (true) {
if (jj_2_34(2)) {
;
} else {
break label_5;
}
jj_consume_token(COMMA);
// a comma-list can't appear where only a query is expected
checkNonQueryExpression(exprContext);
AddArg(list, exprContext);
}
jj_consume_token(RPAREN);
{if (true) return list;}
throw new Error("Missing return statement in function");
}
final public SqlLiteral AllOrDistinct() throws ParseException {
if (jj_2_35(2)) {
jj_consume_token(DISTINCT);
{if (true) return SqlSelectKeyword.DISTINCT.symbol(getPos());}
} else if (jj_2_36(2)) {
jj_consume_token(ALL);
{if (true) return SqlSelectKeyword.ALL.symbol(getPos());}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public void AddArg0(List list, ExprContext exprContext) throws ParseException {
final SqlIdentifier name;
SqlNode e;
final ExprContext firstExprContext;
{
// we've now seen left paren, so queries inside should
// be allowed as sub-queries
switch (exprContext) {
case ACCEPT_SUB_QUERY:
firstExprContext = ExprContext.ACCEPT_NONCURSOR;
break;
case ACCEPT_CURSOR:
firstExprContext = ExprContext.ACCEPT_ALL;
break;
default:
firstExprContext = exprContext;
break;
}
}
if (jj_2_37(2)) {
name = SimpleIdentifier();
jj_consume_token(NAMED_ARGUMENT_ASSIGNMENT);
} else {
name = null;
}
if (jj_2_38(2)) {
e = Default();
} else if (jj_2_39(3)) {
e = TableParam();
} else if (jj_2_40(2)) {
e = PartitionedQueryOrQueryOrExpr(firstExprContext);
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (name != null) {
e = SqlStdOperatorTable.ARGUMENT_ASSIGNMENT.createCall(
Span.of(name, e).pos(), e, name);
}
list.add(e);
}
final public void AddArg(List list, ExprContext exprContext) throws ParseException {
final SqlIdentifier name;
SqlNode e;
if (jj_2_41(2)) {
name = SimpleIdentifier();
jj_consume_token(NAMED_ARGUMENT_ASSIGNMENT);
} else {
name = null;
}
if (jj_2_42(2)) {
e = Default();
} else if (jj_2_43(2)) {
e = Expression(exprContext);
} else if (jj_2_44(2)) {
e = TableParam();
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (name != null) {
e = SqlStdOperatorTable.ARGUMENT_ASSIGNMENT.createCall(
Span.of(name, e).pos(), e, name);
}
list.add(e);
}
final public SqlNode Default() throws ParseException {
jj_consume_token(DEFAULT_);
{if (true) return SqlStdOperatorTable.DEFAULT.createCall(getPos());}
throw new Error("Missing return statement in function");
}
/**
* Parses a query (SELECT, UNION, INTERSECT, EXCEPT, VALUES, TABLE) followed by
* the end-of-file symbol.
*/
final public SqlNode SqlQueryEof() throws ParseException {
SqlNode query;
query = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY);
jj_consume_token(0);
{if (true) return query;}
throw new Error("Missing return statement in function");
}
/**
* Parses a list of SQL statements separated by semicolon.
* The semicolon is required between statements, but is
* optional at the end.
*/
final public SqlNodeList SqlStmtList() throws ParseException {
final List stmtList = new ArrayList();
SqlNode stmt;
stmt = SqlStmt();
stmtList.add(stmt);
label_6:
while (true) {
if (jj_2_45(2)) {
;
} else {
break label_6;
}
jj_consume_token(SEMICOLON);
if (jj_2_46(2)) {
stmt = SqlStmt();
stmtList.add(stmt);
} else {
;
}
}
jj_consume_token(0);
{if (true) return new SqlNodeList(stmtList, Span.of(stmtList).pos());}
throw new Error("Missing return statement in function");
}
/**
* Parses an SQL statement.
*/
final public SqlNode SqlStmt() throws ParseException {
SqlNode stmt;
if (jj_2_47(2)) {
stmt = DruidSqlInsertEof();
} else if (jj_2_48(2)) {
stmt = DruidSqlExplain();
} else if (jj_2_49(2)) {
stmt = DruidSqlReplaceEof();
} else if (jj_2_50(2)) {
stmt = SqlSetOption(Span.of(), null);
} else if (jj_2_51(2)) {
stmt = SqlAlter();
} else if (jj_2_52(2)) {
stmt = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY);
} else if (jj_2_53(2)) {
stmt = SqlExplain();
} else if (jj_2_54(2)) {
stmt = SqlDescribe();
} else if (jj_2_55(2)) {
stmt = SqlInsert();
} else if (jj_2_56(2)) {
stmt = SqlDelete();
} else if (jj_2_57(2)) {
stmt = SqlUpdate();
} else if (jj_2_58(2)) {
stmt = SqlMerge();
} else if (jj_2_59(2)) {
stmt = SqlProcedureCall();
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return stmt;}
throw new Error("Missing return statement in function");
}
/**
* Parses an SQL statement followed by the end-of-file symbol.
*/
final public SqlNode SqlStmtEof() throws ParseException {
SqlNode stmt;
stmt = SqlStmt();
jj_consume_token(0);
{if (true) return stmt;}
throw new Error("Missing return statement in function");
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
final public SqlGranularityLiteral PartitionGranularity() throws ParseException {
SqlNode e;
Granularity granularity;
String unparseString;
if (jj_2_61(2)) {
jj_consume_token(HOUR);
granularity = Granularities.HOUR;
unparseString = "HOUR";
} else if (jj_2_62(2)) {
jj_consume_token(DAY);
granularity = Granularities.DAY;
unparseString = "DAY";
} else if (jj_2_63(2)) {
jj_consume_token(MONTH);
granularity = Granularities.MONTH;
unparseString = "MONTH";
} else if (jj_2_64(2)) {
jj_consume_token(YEAR);
granularity = Granularities.YEAR;
unparseString = "YEAR";
} else if (jj_2_65(2)) {
jj_consume_token(ALL);
granularity = Granularities.ALL;
unparseString = "ALL";
if (jj_2_60(2)) {
jj_consume_token(TIME);
unparseString += " TIME";
} else {
;
}
} else if (jj_2_66(2)) {
e = Expression(ExprContext.ACCEPT_SUB_QUERY);
granularity = DruidSqlParserUtils.convertSqlNodeToGranularity(e);
unparseString = e.toString();
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return new SqlGranularityLiteral(granularity, unparseString, getPos());}
throw new Error("Missing return statement in function");
}
final public SqlNodeList ClusteredBy() throws ParseException {
final List list = new ArrayList();
final Span s;
SqlNode e;
jj_consume_token(CLUSTERED);
s = span();
jj_consume_token(BY);
AddOrderItem(list);
label_7:
while (true) {
if (jj_2_67(2)) {
;
} else {
break label_7;
}
jj_consume_token(COMMA);
AddOrderItem(list);
}
{if (true) return new SqlNodeList(list, s.addAll(list).pos());}
throw new Error("Missing return statement in function");
}
final public SqlTypeNameSpec DruidType() throws ParseException {
String typeName;
jj_consume_token(TYPE);
jj_consume_token(LPAREN);
jj_consume_token(QUOTED_STRING);
typeName = SqlParserUtil.trim(token.image, "'");
jj_consume_token(RPAREN);
{if (true) return new SqlUserDefinedTypeNameSpec(typeName, span().pos());}
throw new Error("Missing return statement in function");
}
// Parses the supported file formats for export.
final public SqlIdentifier FileFormat() throws ParseException {
SqlNode format;
format = SimpleIdentifier();
{if (true) return (SqlIdentifier) format;}
throw new Error("Missing return statement in function");
}
final public SqlIdentifier ExternalDestination() throws ParseException {
final Span s;
SqlIdentifier destinationType = null;
String destinationTypeString = null;
Map properties = new HashMap();
if (jj_2_68(2)) {
destinationType = SimpleIdentifier();
destinationTypeString = destinationType.toString();
} else if (jj_2_69(2)) {
jj_consume_token(LOCAL);
// local is a reserved keyword in calcite. However, local is also a supported input source / destination and
// keeping the name is preferred for consistency in other places, and so that permission checks are applied
// correctly, so this is handled as a special case.
destinationTypeString = "local";
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (jj_2_71(2)) {
jj_consume_token(LPAREN);
if (jj_2_70(2)) {
properties = ExternProperties();
} else {
;
}
jj_consume_token(RPAREN);
} else {
;
}
s = span();
{if (true) return new ExternalDestinationSqlIdentifier(
destinationTypeString,
s.pos(),
properties
);}
throw new Error("Missing return statement in function");
}
final public Map ExternProperties() throws ParseException {
final Span s;
final Map properties = new HashMap();
SqlIdentifier identifier;
String value;
SqlNodeList commaList = SqlNodeList.EMPTY;
identifier = SimpleIdentifier();
jj_consume_token(NAMED_ARGUMENT_ASSIGNMENT);
value = SimpleStringLiteral();
properties.put(identifier.toString(), value);
label_8:
while (true) {
if (jj_2_72(2)) {
;
} else {
break label_8;
}
jj_consume_token(COMMA);
identifier = SimpleIdentifier();
jj_consume_token(NAMED_ARGUMENT_ASSIGNMENT);
value = SimpleStringLiteral();
properties.put(identifier.toString(), value);
}
{if (true) return properties;}
throw new Error("Missing return statement in function");
}
final public SqlNode testRule() throws ParseException {
final SqlNode e;
e = SimpleIdentifier();
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Parses an INSERT statement. This function is copied from SqlInsert in core/src/main/codegen/templates/Parser.jj,
* with some changes to allow a custom error message if an OVERWRITE clause is present.
*/
// Using fully qualified name for Pair class, since Calcite also has a same class name being used in the Parser.jj
final public SqlNode DruidSqlInsertEof() throws ParseException {
SqlNode insertNode;
final List keywords = new ArrayList();
final SqlNodeList keywordList;
final SqlIdentifier destination;
SqlNode tableRef = null;
SqlNode source;
final SqlNodeList columnList;
final Span s;
final Pair p;
SqlGranularityLiteral partitionedBy = null;
SqlNodeList clusteredBy = null;
SqlIdentifier exportFileFormat = null;
if (jj_2_73(2)) {
jj_consume_token(INSERT);
} else if (jj_2_74(2)) {
jj_consume_token(UPSERT);
keywords.add(SqlInsertKeyword.UPSERT.symbol(getPos()));
} else {
jj_consume_token(-1);
throw new ParseException();
}
s = span();
SqlInsertKeywords(keywords);
keywordList = new SqlNodeList(keywords, s.addAll(keywords).pos());
jj_consume_token(INTO);
if (jj_2_77(2)) {
jj_consume_token(EXTERN);
jj_consume_token(LPAREN);
destination = ExternalDestination();
jj_consume_token(RPAREN);
} else if (jj_2_78(2)) {
destination = CompoundTableIdentifier();
if (jj_2_75(2)) {
tableRef = TableHints(destination);
} else {
tableRef = destination;
}
if (jj_2_76(5)) {
tableRef = ExtendTable(tableRef);
} else {
;
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (jj_2_79(2)) {
p = ParenthesizedCompoundIdentifierList();
if (p.right.size() > 0) {
tableRef = extend(tableRef, p.right);
}
if (p.left.size() > 0) {
columnList = p.left;
} else {
columnList = null;
}
} else {
columnList = null;
}
if (jj_2_80(2)) {
jj_consume_token(AS);
exportFileFormat = FileFormat();
} else {
;
}
if (jj_2_81(2)) {
jj_consume_token(OVERWRITE);
{if (true) throw org.apache.druid.sql.calcite.parser.DruidSqlParserUtils.problemParsing(
"An OVERWRITE clause is not allowed with INSERT statements. Use REPLACE statements if overwriting existing segments is required or remove the OVERWRITE clause."
);}
} else if (jj_2_82(2)) {
source = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY);
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (jj_2_83(2)) {
jj_consume_token(PARTITIONED);
jj_consume_token(BY);
partitionedBy = PartitionGranularity();
} else {
;
}
if (jj_2_84(2)) {
clusteredBy = ClusteredBy();
} else {
;
}
if (clusteredBy != null && partitionedBy == null) {
{if (true) throw org.apache.druid.sql.calcite.parser.DruidSqlParserUtils.problemParsing(
"CLUSTERED BY found before PARTITIONED BY, CLUSTERED BY must come after the PARTITIONED BY clause"
);}
}
jj_consume_token(0);
insertNode = new SqlInsert(s.end(source), keywordList, destination, source, columnList);
if (!(insertNode instanceof SqlInsert)) {
// This shouldn't be encountered, but done as a defensive practice. SqlInsert() always returns a node of type
// SqlInsert
{if (true) return insertNode;}
}
SqlInsert sqlInsert = (SqlInsert) insertNode;
{if (true) return DruidSqlInsert.create(sqlInsert, partitionedBy, clusteredBy, exportFileFormat);}
throw new Error("Missing return statement in function");
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Parses an EXPLAIN PLAN statement. Allows for custom druid's statements as well.
* The main change from SqlExplain() rule is that the statements that can occur in front of the explain's can now be
* custom druid statements as well reflected in the DruidQueryOrSqlQueryOrDml() production rule
*
* Since this copies directly from SqlExplain(), this would need to be modified while updating Calcite to allow for
* any changes and improvements (e.g. adding another format apart from json or xml in which one can
* specify the explain plan output)
*/
final public SqlNode DruidSqlExplain() throws ParseException {
SqlNode stmt;
SqlExplainLevel detailLevel = SqlExplainLevel.EXPPLAN_ATTRIBUTES;
SqlExplain.Depth depth;
final SqlExplainFormat format;
jj_consume_token(EXPLAIN);
jj_consume_token(PLAN);
if (jj_2_85(2)) {
detailLevel = ExplainDetailLevel();
} else {
;
}
depth = ExplainDepth();
if (jj_2_86(2)) {
jj_consume_token(AS);
jj_consume_token(XML);
format = SqlExplainFormat.XML;
} else if (jj_2_87(2)) {
jj_consume_token(AS);
jj_consume_token(JSON);
format = SqlExplainFormat.JSON;
} else {
format = SqlExplainFormat.TEXT;
}
jj_consume_token(FOR);
stmt = DruidQueryOrSqlQueryOrDml();
{if (true) return new SqlExplain(getPos(),
stmt,
detailLevel.symbol(SqlParserPos.ZERO),
depth.symbol(SqlParserPos.ZERO),
format.symbol(SqlParserPos.ZERO),
nDynamicParams);}
throw new Error("Missing return statement in function");
}
final public SqlNode DruidQueryOrSqlQueryOrDml() throws ParseException {
SqlNode stmt;
if (jj_2_88(2)) {
stmt = DruidSqlInsertEof();
} else if (jj_2_89(2)) {
stmt = DruidSqlReplaceEof();
} else if (jj_2_90(2)) {
stmt = SqlQueryOrDml();
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return stmt;}
throw new Error("Missing return statement in function");
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Taken from syntax of SqlInsert statement from calcite parser, edited for replace syntax
final public SqlNode DruidSqlReplaceEof() throws ParseException {
final SqlIdentifier destination;
SqlNode source;
SqlNodeList columnList = null;
final Span s;
SqlNode tableRef = null;
SqlInsert sqlInsert;
SqlGranularityLiteral partitionedBy = null;
SqlNodeList clusteredBy = null;
final Pair p;
SqlNode replaceTimeQuery = null;
SqlIdentifier exportFileFormat = null;
jj_consume_token(REPLACE);
s = span();
jj_consume_token(INTO);
if (jj_2_93(2)) {
jj_consume_token(EXTERN);
jj_consume_token(LPAREN);
destination = ExternalDestination();
jj_consume_token(RPAREN);
} else if (jj_2_94(2)) {
destination = CompoundTableIdentifier();
if (jj_2_91(2)) {
tableRef = TableHints(destination);
} else {
tableRef = destination;
}
if (jj_2_92(5)) {
tableRef = ExtendTable(tableRef);
} else {
;
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (jj_2_95(2)) {
p = ParenthesizedCompoundIdentifierList();
if (p.right.size() > 0) {
tableRef = extend(tableRef, p.right);
}
if (p.left.size() > 0) {
columnList = p.left;
} else {
columnList = null;
}
} else {
columnList = null;
}
if (jj_2_96(2)) {
jj_consume_token(AS);
exportFileFormat = FileFormat();
} else {
;
}
if (jj_2_98(2)) {
jj_consume_token(OVERWRITE);
if (jj_2_97(2)) {
replaceTimeQuery = ReplaceTimeQuery();
} else {
;
}
} else {
;
}
source = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY);
if (jj_2_99(2)) {
jj_consume_token(PARTITIONED);
jj_consume_token(BY);
partitionedBy = PartitionGranularity();
} else {
;
}
if (jj_2_100(2)) {
clusteredBy = ClusteredBy();
} else {
;
}
if (clusteredBy != null && partitionedBy == null) {
{if (true) throw org.apache.druid.sql.calcite.parser.DruidSqlParserUtils.problemParsing(
"CLUSTERED BY found before PARTITIONED BY, CLUSTERED BY must come after the PARTITIONED BY clause"
);}
}
jj_consume_token(0);
sqlInsert = new SqlInsert(s.end(source), SqlNodeList.EMPTY, destination, source, columnList);
{if (true) return DruidSqlReplace.create(sqlInsert, partitionedBy, clusteredBy, exportFileFormat, replaceTimeQuery);}
throw new Error("Missing return statement in function");
}
final public SqlNode ReplaceTimeQuery() throws ParseException {
SqlNode replaceQuery;
if (jj_2_101(2)) {
jj_consume_token(ALL);
replaceQuery = SqlLiteral.createCharString("ALL", getPos());
} else if (jj_2_102(2)) {
// We parse all types of conditions and throw an exception if it is not supported to keep the parsing simple
replaceQuery = Where();
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return replaceQuery;}
throw new Error("Missing return statement in function");
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Druid note: this file is copied from core/src/main/codegen/templates/Parser.jj in Calcite 1.35.0, with changes to
* to add two elements of Druid syntax to the FROM clause:
*
* id [ () ]
*
* And
*
* TABLE(()) ()
*
* These changes were originally in https://github.com/apache/druid/pull/13360 as a patch script (sql/edit-parser.py),
* then later moved to this copied-and-edited file in https://github.com/apache/druid/pull/13553.*
*
* This file prefixes the required production rules with 'Druid' so that the whole FROM production rule can be
* derived from this file itself. The production clause is injected in the grammar using the maven replace plugin in
* sql module's pom.
*/
/**
* Parses the FROM clause for a SELECT.
*
* FROM is mandatory in standard SQL, optional in dialects such as MySQL,
* PostgreSQL. The parser allows SELECT without FROM, but the validator fails
* if conformance is, say, STRICT_2003.
*/
final public SqlNode DruidFromClause() throws ParseException {
SqlNode e, e2;
SqlLiteral joinType;
e = DruidJoin();
label_9:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case COMMA:
;
break;
default:
jj_la1[0] = jj_gen;
break label_9;
}
jj_consume_token(COMMA);
joinType = JoinType.COMMA.symbol(getPos());
e2 = DruidJoin();
e = new SqlJoin(joinType.getParserPosition(),
e,
SqlLiteral.createBoolean(false, joinType.getParserPosition()),
joinType,
e2,
JoinConditionType.NONE.symbol(SqlParserPos.ZERO),
null);
}
{if (true) return e;}
throw new Error("Missing return statement in function");
}
final public SqlNode DruidJoin() throws ParseException {
SqlNode e;
e = DruidTableRef1(ExprContext.ACCEPT_QUERY_OR_JOIN);
label_10:
while (true) {
if (jj_2_103(2)) {
;
} else {
break label_10;
}
e = DruidJoinTable(e);
}
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/** Matches "LEFT JOIN t ON ...", "RIGHT JOIN t USING ...", "JOIN t". */
final public SqlNode DruidJoinTable(SqlNode e) throws ParseException {
SqlNode e2, condition;
final SqlLiteral natural, joinType, on, using;
SqlNodeList list;
if (jj_2_106(3)) {
natural = Natural();
joinType = JoinType();
e2 = DruidTableRef1(ExprContext.ACCEPT_QUERY_OR_JOIN);
if (jj_2_104(2)) {
jj_consume_token(ON);
on = JoinConditionType.ON.symbol(getPos());
condition = Expression(ExprContext.ACCEPT_SUB_QUERY);
{if (true) return new SqlJoin(joinType.getParserPosition(),
e,
natural,
joinType,
e2,
on,
condition);}
} else if (jj_2_105(2)) {
jj_consume_token(USING);
using = JoinConditionType.USING.symbol(getPos());
list = ParenthesizedSimpleIdentifierList();
{if (true) return new SqlJoin(joinType.getParserPosition(),
e,
natural,
joinType,
e2,
using,
new SqlNodeList(list, Span.of(using).end(this)));}
} else {
{if (true) return new SqlJoin(joinType.getParserPosition(),
e,
natural,
joinType,
e2,
JoinConditionType.NONE.symbol(joinType.getParserPosition()),
null);}
}
} else if (jj_2_107(2)) {
jj_consume_token(CROSS);
joinType = JoinType.CROSS.symbol(getPos());
jj_consume_token(APPLY);
e2 = DruidTableRef2(true);
if (!this.conformance.isApplyAllowed()) {
{if (true) throw SqlUtil.newContextException(getPos(), RESOURCE.applyNotAllowed());}
}
{if (true) return new SqlJoin(joinType.getParserPosition(),
e,
SqlLiteral.createBoolean(false, joinType.getParserPosition()),
joinType,
e2,
JoinConditionType.NONE.symbol(SqlParserPos.ZERO),
null);}
} else if (jj_2_108(2)) {
jj_consume_token(OUTER);
joinType = JoinType.LEFT.symbol(getPos());
jj_consume_token(APPLY);
e2 = DruidTableRef2(true);
if (!this.conformance.isApplyAllowed()) {
{if (true) throw SqlUtil.newContextException(getPos(), RESOURCE.applyNotAllowed());}
}
{if (true) return new SqlJoin(joinType.getParserPosition(),
e,
SqlLiteral.createBoolean(false, joinType.getParserPosition()),
joinType,
e2,
JoinConditionType.ON.symbol(SqlParserPos.ZERO),
SqlLiteral.createBoolean(true, joinType.getParserPosition()));}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses a table reference in a FROM clause, not lateral unless LATERAL
* is explicitly specified.
*/
final public SqlNode DruidTableRef() throws ParseException {
final SqlNode e;
e = DruidTableRef3(ExprContext.ACCEPT_QUERY, false);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
final public SqlNode DruidTableRef1(ExprContext exprContext) throws ParseException {
final SqlNode e;
e = DruidTableRef3(exprContext, false);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/**
* Parses a table reference in a FROM clause.
*/
final public SqlNode DruidTableRef2(boolean lateral) throws ParseException {
final SqlNode e;
e = DruidTableRef3(ExprContext.ACCEPT_QUERY, lateral);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
final public SqlNode DruidTableRef3(ExprContext exprContext, boolean lateral) throws ParseException {
final SqlIdentifier tableName;
SqlNode tableRef;
List paramList;
final SqlIdentifier alias;
final Span s;
SqlNodeList args;
final SqlNodeList columnAliasList;
SqlUnnestOperator unnestOp = SqlStdOperatorTable.UNNEST;
SqlNodeList extendList = null;
if (jj_2_119(2)) {
tableName = CompoundTableIdentifier();
if (jj_2_109(2)) {
tableRef = TableHints(tableName);
} else {
tableRef = tableName;
}
if (jj_2_110(2)) {
paramList = FunctionParameterList(ExprContext.ACCEPT_NONCURSOR);
tableRef = ParameterizeOperator.PARAM.createCall(tableRef, paramList);
} else {
;
}
// END: Druid-specific code
tableRef = Over(tableRef);
if (jj_2_111(2)) {
tableRef = Snapshot(tableRef);
} else {
;
}
if (jj_2_112(2)) {
tableRef = MatchRecognize(tableRef);
} else {
;
}
} else if (jj_2_120(2)) {
if (jj_2_113(2)) {
jj_consume_token(LATERAL);
lateral = true;
} else {
;
}
tableRef = ParenthesizedExpression(exprContext);
tableRef = Over(tableRef);
tableRef = addLateral(tableRef, lateral);
if (jj_2_114(2)) {
tableRef = MatchRecognize(tableRef);
} else {
;
}
} else if (jj_2_121(2)) {
jj_consume_token(UNNEST);
s = span();
args = ParenthesizedQueryOrCommaList(ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_115(2)) {
jj_consume_token(WITH);
jj_consume_token(ORDINALITY);
unnestOp = SqlStdOperatorTable.UNNEST_WITH_ORDINALITY;
} else {
;
}
tableRef = unnestOp.createCall(s.end(this), (List) args);
} else if (jj_2_122(2)) {
if (jj_2_116(2)) {
jj_consume_token(LATERAL);
lateral = true;
} else {
;
}
tableRef = TableFunctionCall();
if (jj_2_118(2)) {
if (jj_2_117(2)) {
jj_consume_token(EXTEND);
} else {
;
}
extendList = ExtendList();
tableRef = ExtendOperator.EXTEND.createCall(
Span.of(tableRef, extendList).pos(), tableRef, extendList);
} else {
;
}
// END: Druid-specific code
tableRef = addLateral(tableRef, lateral);
} else if (jj_2_123(2)) {
tableRef = ExtendedTableRef();
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (jj_2_124(2)) {
tableRef = Pivot(tableRef);
} else {
;
}
if (jj_2_125(2)) {
tableRef = Unpivot(tableRef);
} else {
;
}
if (jj_2_128(2)) {
if (jj_2_126(2)) {
jj_consume_token(AS);
} else {
;
}
alias = SimpleIdentifier();
if (jj_2_127(2)) {
columnAliasList = ParenthesizedSimpleIdentifierList();
} else {
columnAliasList = null;
}
// Standard SQL (and Postgres) allow applying "AS alias" to a JOIN,
// e.g. "FROM (a CROSS JOIN b) AS c". The new alias obscures the
// internal aliases, and columns cannot be referenced if they are
// not unique. TODO: Support this behavior; see
// [CALCITE-5168] Allow AS after parenthesized JOIN
checkNotJoin(tableRef);
if (columnAliasList == null) {
tableRef = SqlStdOperatorTable.AS.createCall(
Span.of(tableRef).end(this), tableRef, alias);
} else {
List idList = new ArrayList();
idList.add(tableRef);
idList.add(alias);
idList.addAll(columnAliasList.getList());
tableRef = SqlStdOperatorTable.AS.createCall(
Span.of(tableRef).end(this), idList);
}
} else {
;
}
if (jj_2_129(2)) {
tableRef = Tablesample(tableRef);
} else {
;
}
{if (true) return tableRef;}
throw new Error("Missing return statement in function");
}
final public SqlNodeList ParenthesizedKeyValueOptionCommaList() throws ParseException {
final Span s;
final List list = new ArrayList();
s = span();
jj_consume_token(LPAREN);
AddKeyValueOption(list);
label_11:
while (true) {
if (jj_2_130(2)) {
;
} else {
break label_11;
}
jj_consume_token(COMMA);
AddKeyValueOption(list);
}
jj_consume_token(RPAREN);
{if (true) return new SqlNodeList(list, s.end(this));}
throw new Error("Missing return statement in function");
}
/**
* Parses an option with format key=val whose key is a simple identifier or string literal
* and value is a string literal.
*/
final public void AddKeyValueOption(List list) throws ParseException {
final SqlNode key;
final SqlNode value;
if (jj_2_131(2)) {
key = SimpleIdentifier();
} else if (jj_2_132(2)) {
key = StringLiteral();
} else {
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(EQ);
value = StringLiteral();
list.add(key);
list.add(value);
}
/** Parses an option value (either a string or a numeric) and adds to a list. */
final public void AddOptionValue(List list) throws ParseException {
final SqlNode value;
if (jj_2_133(2)) {
value = NumericLiteral();
list.add(value);
} else if (jj_2_134(2)) {
value = StringLiteral();
list.add(value);
} else {
jj_consume_token(-1);
throw new ParseException();
}
}
/**
* Parses a literal list separated by comma. The literal is either a string or a numeric.
*/
final public SqlNodeList ParenthesizedLiteralOptionCommaList() throws ParseException {
final Span s;
final List list = new ArrayList();
s = span();
jj_consume_token(LPAREN);
AddOptionValue(list);
label_12:
while (true) {
if (jj_2_135(2)) {
;
} else {
break label_12;
}
jj_consume_token(COMMA);
AddOptionValue(list);
}
jj_consume_token(RPAREN);
{if (true) return new SqlNodeList(list, s.end(this));}
throw new Error("Missing return statement in function");
}
final public void AddHint(List hints) throws ParseException {
final SqlIdentifier hintName;
final SqlNodeList hintOptions;
final SqlHint.HintOptionFormat optionFormat;
hintName = SimpleIdentifier();
if (jj_2_137(5)) {
hintOptions = ParenthesizedKeyValueOptionCommaList();
optionFormat = SqlHint.HintOptionFormat.KV_LIST;
} else if (jj_2_138(3)) {
hintOptions = ParenthesizedSimpleIdentifierList();
optionFormat = SqlHint.HintOptionFormat.ID_LIST;
} else if (jj_2_139(3)) {
hintOptions = ParenthesizedLiteralOptionCommaList();
optionFormat = SqlHint.HintOptionFormat.LITERAL_LIST;
} else {
if (jj_2_136(2)) {
jj_consume_token(LPAREN);
jj_consume_token(RPAREN);
} else {
;
}
hintOptions = SqlNodeList.EMPTY;
optionFormat = SqlHint.HintOptionFormat.EMPTY;
}
hints.add(
new SqlHint(Span.of(hintOptions).end(this), hintName, hintOptions,
optionFormat));
}
/** Parses hints following a table reference,
* and returns the wrapped table reference. */
final public SqlNode TableHints(SqlIdentifier tableName) throws ParseException {
final List hints = new ArrayList();
jj_consume_token(HINT_BEG);
AddHint(hints);
label_13:
while (true) {
if (jj_2_140(2)) {
;
} else {
break label_13;
}
jj_consume_token(COMMA);
AddHint(hints);
}
jj_consume_token(COMMENT_END);
final SqlParserPos pos = Span.of(tableName).addAll(hints).end(this);
final SqlNodeList hintList = new SqlNodeList(hints, pos);
{if (true) return new SqlTableRef(pos, tableName, hintList);}
throw new Error("Missing return statement in function");
}
/**
* Parses a leaf SELECT expression without ORDER BY.
*/
final public SqlSelect SqlSelect() throws ParseException {
final List keywords = new ArrayList();
final SqlLiteral keyword;
final SqlNodeList keywordList;
final List selectList = new ArrayList();
final SqlNode fromClause;
final SqlNode where;
final SqlNodeList groupBy;
final SqlNode having;
final SqlNodeList windowDecls;
final SqlNode qualify;
final List hints = new ArrayList();
final Span s;
jj_consume_token(SELECT);
s = span();
if (jj_2_142(2)) {
jj_consume_token(HINT_BEG);
AddHint(hints);
label_14:
while (true) {
if (jj_2_141(2)) {
;
} else {
break label_14;
}
jj_consume_token(COMMA);
AddHint(hints);
}
jj_consume_token(COMMENT_END);
} else {
;
}
SqlSelectKeywords(keywords);
if (jj_2_143(2)) {
jj_consume_token(STREAM);
keywords.add(SqlSelectKeyword.STREAM.symbol(getPos()));
} else {
;
}
if (jj_2_144(2)) {
keyword = AllOrDistinct();
keywords.add(keyword);
} else {
;
}
keywordList = new SqlNodeList(keywords, s.addAll(keywords).pos());
AddSelectItem(selectList);
label_15:
while (true) {
if (jj_2_145(2)) {
;
} else {
break label_15;
}
jj_consume_token(COMMA);
AddSelectItem(selectList);
}
if (jj_2_151(2)) {
jj_consume_token(FROM);
fromClause = DruidFromClause();
if (jj_2_146(2)) {
where = Where();
} else {
where = null;
}
if (jj_2_147(2)) {
groupBy = GroupBy();
} else {
groupBy = null;
}
if (jj_2_148(2)) {
having = Having();
} else {
having = null;
}
if (jj_2_149(2)) {
windowDecls = Window();
} else {
windowDecls = null;
}
if (jj_2_150(2)) {
qualify = Qualify();
} else {
qualify = null;
}
} else {
E();
fromClause = null;
where = null;
groupBy = null;
having = null;
windowDecls = null;
qualify = null;
}
{if (true) return new SqlSelect(s.end(this), keywordList,
new SqlNodeList(selectList, Span.of(selectList).pos()),
fromClause, where, groupBy, having, windowDecls, qualify,
null, null, null, new SqlNodeList(hints, getPos()));}
throw new Error("Missing return statement in function");
}
/*
* Abstract production:
*
* void SqlSelectKeywords(List keywords)
*
* Parses dialect-specific keywords immediately following the SELECT keyword.
*/
/**
* Parses an EXPLAIN PLAN statement.
*/
final public SqlNode SqlExplain() throws ParseException {
SqlNode stmt;
SqlExplainLevel detailLevel = SqlExplainLevel.EXPPLAN_ATTRIBUTES;
SqlExplain.Depth depth;
final SqlExplainFormat format;
jj_consume_token(EXPLAIN);
jj_consume_token(PLAN);
if (jj_2_152(2)) {
detailLevel = ExplainDetailLevel();
} else {
;
}
depth = ExplainDepth();
if (jj_2_153(2)) {
jj_consume_token(AS);
jj_consume_token(XML);
format = SqlExplainFormat.XML;
} else if (jj_2_154(2)) {
jj_consume_token(AS);
jj_consume_token(JSON);
format = SqlExplainFormat.JSON;
} else if (jj_2_155(2)) {
jj_consume_token(AS);
jj_consume_token(DOT_FORMAT);
format = SqlExplainFormat.DOT;
} else {
format = SqlExplainFormat.TEXT;
}
jj_consume_token(FOR);
stmt = SqlQueryOrDml();
{if (true) return new SqlExplain(getPos(),
stmt,
detailLevel.symbol(SqlParserPos.ZERO),
depth.symbol(SqlParserPos.ZERO),
format.symbol(SqlParserPos.ZERO),
nDynamicParams);}
throw new Error("Missing return statement in function");
}
/** Parses a query (SELECT or VALUES)
* or DML statement (INSERT, UPDATE, DELETE, MERGE). */
final public SqlNode SqlQueryOrDml() throws ParseException {
SqlNode stmt;
if (jj_2_156(2)) {
stmt = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY);
} else if (jj_2_157(2)) {
stmt = SqlInsert();
} else if (jj_2_158(2)) {
stmt = SqlDelete();
} else if (jj_2_159(2)) {
stmt = SqlUpdate();
} else if (jj_2_160(2)) {
stmt = SqlMerge();
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return stmt;}
throw new Error("Missing return statement in function");
}
/**
* Parses WITH TYPE | WITH IMPLEMENTATION | WITHOUT IMPLEMENTATION modifier for
* EXPLAIN PLAN.
*/
final public SqlExplain.Depth ExplainDepth() throws ParseException {
if (jj_2_161(2)) {
jj_consume_token(WITH);
jj_consume_token(TYPE);
{if (true) return SqlExplain.Depth.TYPE;}
} else if (jj_2_162(2)) {
jj_consume_token(WITH);
jj_consume_token(IMPLEMENTATION);
{if (true) return SqlExplain.Depth.PHYSICAL;}
} else if (jj_2_163(2)) {
jj_consume_token(WITHOUT);
jj_consume_token(IMPLEMENTATION);
{if (true) return SqlExplain.Depth.LOGICAL;}
} else {
{if (true) return SqlExplain.Depth.PHYSICAL;}
}
throw new Error("Missing return statement in function");
}
/**
* Parses INCLUDING ALL ATTRIBUTES modifier for EXPLAIN PLAN.
*/
final public SqlExplainLevel ExplainDetailLevel() throws ParseException {
SqlExplainLevel level = SqlExplainLevel.EXPPLAN_ATTRIBUTES;
if (jj_2_165(2)) {
jj_consume_token(EXCLUDING);
jj_consume_token(ATTRIBUTES);
level = SqlExplainLevel.NO_ATTRIBUTES;
} else if (jj_2_166(2)) {
jj_consume_token(INCLUDING);
if (jj_2_164(2)) {
jj_consume_token(ALL);
level = SqlExplainLevel.ALL_ATTRIBUTES;
} else {
;
}
jj_consume_token(ATTRIBUTES);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return level;}
throw new Error("Missing return statement in function");
}
/**
* Parses a DESCRIBE statement.
*/
final public SqlNode SqlDescribe() throws ParseException {
final Span s;
final SqlIdentifier table;
final SqlIdentifier column;
final SqlIdentifier id;
final SqlNode stmt;
jj_consume_token(DESCRIBE);
s = span();
if (jj_2_172(2)) {
if (jj_2_167(2)) {
jj_consume_token(DATABASE);
} else if (jj_2_168(2)) {
jj_consume_token(CATALOG);
} else if (jj_2_169(2)) {
jj_consume_token(SCHEMA);
} else {
jj_consume_token(-1);
throw new ParseException();
}
id = CompoundIdentifier();
// DESCRIBE DATABASE and DESCRIBE CATALOG currently do the same as
// DESCRIBE SCHEMA but should be different. See
// [CALCITE-1221] Implement DESCRIBE DATABASE, CATALOG, STATEMENT
{if (true) return new SqlDescribeSchema(s.end(id), id);}
} else if (jj_2_173(2147483647)) {
if (jj_2_170(2)) {
jj_consume_token(TABLE);
} else {
;
}
table = CompoundIdentifier();
if (jj_2_171(2)) {
column = SimpleIdentifier();
} else {
column = null;
}
{if (true) return new SqlDescribeTable(s.add(table).addIf(column).pos(),
table, column);}
} else if (jj_2_174(2)) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case STATEMENT:
jj_consume_token(STATEMENT);
break;
default:
jj_la1[1] = jj_gen;
;
}
stmt = SqlQueryOrDml();
// DESCRIBE STATEMENT currently does the same as EXPLAIN. See
// [CALCITE-1221] Implement DESCRIBE DATABASE, CATALOG, STATEMENT
final SqlExplainLevel detailLevel = SqlExplainLevel.EXPPLAN_ATTRIBUTES;
final SqlExplain.Depth depth = SqlExplain.Depth.PHYSICAL;
final SqlExplainFormat format = SqlExplainFormat.TEXT;
{if (true) return new SqlExplain(s.end(stmt),
stmt,
detailLevel.symbol(SqlParserPos.ZERO),
depth.symbol(SqlParserPos.ZERO),
format.symbol(SqlParserPos.ZERO),
nDynamicParams);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses a CALL statement.
*/
final public SqlNode SqlProcedureCall() throws ParseException {
final Span s;
SqlNode routineCall;
jj_consume_token(CALL);
s = span();
routineCall = NamedRoutineCall(SqlFunctionCategory.USER_DEFINED_PROCEDURE,
ExprContext.ACCEPT_SUB_QUERY);
{if (true) return SqlStdOperatorTable.PROCEDURE_CALL.createCall(
s.end(routineCall), routineCall);}
throw new Error("Missing return statement in function");
}
final public SqlNode NamedRoutineCall(SqlFunctionCategory routineType,
ExprContext exprContext) throws ParseException {
final SqlIdentifier name;
final List list = new ArrayList();
final Span s;
name = CompoundIdentifier();
s = span();
jj_consume_token(LPAREN);
if (jj_2_176(2)) {
AddArg0(list, exprContext);
label_16:
while (true) {
if (jj_2_175(2)) {
;
} else {
break label_16;
}
jj_consume_token(COMMA);
// a comma-list can't appear where only a query is expected
checkNonQueryExpression(exprContext);
AddArg(list, exprContext);
}
} else {
;
}
jj_consume_token(RPAREN);
{if (true) return createCall(name, s.end(this), routineType, null, list);}
throw new Error("Missing return statement in function");
}
/**
* Table parameter of a table function.
* The input table with set semantics may be partitioned/ordered on one or more columns.
*/
final public SqlNode TableParam() throws ParseException {
final Span s;
final SqlNodeList partitionList;
final SqlNodeList orderList;
SqlNode tableRef;
s = span();
tableRef = ExplicitTable(getPos());
if (jj_2_177(2)) {
jj_consume_token(PARTITION);
jj_consume_token(BY);
partitionList = SimpleIdentifierOrList();
} else {
partitionList = SqlNodeList.EMPTY;
}
if (jj_2_178(2)) {
orderList = OrderByOfSetSemanticsTable();
} else {
orderList = SqlNodeList.EMPTY;
}
{if (true) return CreateSetSemanticsTableIfNeeded(s, tableRef, partitionList, orderList);}
throw new Error("Missing return statement in function");
}
final public SqlNode PartitionedQueryOrQueryOrExpr(ExprContext exprContext) throws ParseException {
SqlNode e;
e = OrderedQueryOrExpr(exprContext);
e = PartitionedByAndOrderBy(e);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
final public SqlNode PartitionedByAndOrderBy(SqlNode e) throws ParseException {
final Span s;
final SqlNodeList partitionList;
final SqlNodeList orderList;
s = span();
if (jj_2_179(2)) {
jj_consume_token(PARTITION);
jj_consume_token(BY);
partitionList = SimpleIdentifierOrList();
} else {
partitionList = SqlNodeList.EMPTY;
}
if (jj_2_180(2)) {
orderList = OrderByOfSetSemanticsTable();
} else {
orderList = SqlNodeList.EMPTY;
}
{if (true) return CreateSetSemanticsTableIfNeeded(s, e, partitionList, orderList);}
throw new Error("Missing return statement in function");
}
final public SqlNodeList OrderByOfSetSemanticsTable() throws ParseException {
final List list = new ArrayList();
final Span s;
jj_consume_token(ORDER);
s = span();
jj_consume_token(BY);
if (jj_2_182(2)) {
jj_consume_token(LPAREN);
AddOrderItem(list);
label_17:
while (true) {
if (jj_2_181(2)) {
;
} else {
break label_17;
}
jj_consume_token(COMMA);
AddOrderItem(list);
}
jj_consume_token(RPAREN);
{if (true) return new SqlNodeList(list, s.addAll(list).pos());}
} else if (jj_2_183(2)) {
AddOrderItem(list);
{if (true) return new SqlNodeList(list, s.addAll(list).pos());}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public SqlNode CreateSetSemanticsTableIfNeeded(final Span s,
final SqlNode e,
final SqlNodeList partitionList,
final SqlNodeList orderList) throws ParseException {
if (partitionList.isEmpty() && orderList.isEmpty()) {
{if (true) return e;}
} else {
{if (true) return SqlStdOperatorTable.SET_SEMANTICS_TABLE.createCall(
s.pos(), e, partitionList, orderList);}
}
throw new Error("Missing return statement in function");
}
/**
* Parses an INSERT statement.
*/
final public SqlNode SqlInsert() throws ParseException {
final List keywords = new ArrayList();
final SqlNodeList keywordList;
final SqlIdentifier tableName;
SqlNode tableRef;
SqlNode source;
final SqlNodeList columnList;
final Span s;
final Pair p;
if (jj_2_184(2)) {
jj_consume_token(INSERT);
} else if (jj_2_185(2)) {
jj_consume_token(UPSERT);
keywords.add(SqlInsertKeyword.UPSERT.symbol(getPos()));
} else {
jj_consume_token(-1);
throw new ParseException();
}
s = span();
SqlInsertKeywords(keywords);
keywordList = new SqlNodeList(keywords, s.addAll(keywords).pos());
jj_consume_token(INTO);
tableName = CompoundTableIdentifier();
if (jj_2_186(2)) {
tableRef = TableHints(tableName);
} else {
tableRef = tableName;
}
if (jj_2_187(5)) {
tableRef = ExtendTable(tableRef);
} else {
;
}
if (jj_2_188(2)) {
p = ParenthesizedCompoundIdentifierList();
if (p.right.size() > 0) {
tableRef = extend(tableRef, p.right);
}
if (p.left.size() > 0) {
columnList = p.left;
} else {
columnList = null;
}
} else {
columnList = null;
}
source = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY);
{if (true) return new SqlInsert(s.end(source), keywordList, tableRef, source,
columnList);}
throw new Error("Missing return statement in function");
}
/*
* Abstract production:
*
* void SqlInsertKeywords(List keywords)
*
* Parses dialect-specific keywords immediately following the INSERT keyword.
*/
/**
* Parses a DELETE statement.
*/
final public SqlNode SqlDelete() throws ParseException {
final SqlIdentifier tableName;
SqlNode tableRef;
final SqlIdentifier alias;
final SqlNode where;
final Span s;
jj_consume_token(DELETE);
s = span();
jj_consume_token(FROM);
tableName = CompoundTableIdentifier();
if (jj_2_189(2)) {
tableRef = TableHints(tableName);
} else {
tableRef = tableName;
}
if (jj_2_190(2)) {
tableRef = ExtendTable(tableRef);
} else {
;
}
if (jj_2_192(2)) {
if (jj_2_191(2)) {
jj_consume_token(AS);
} else {
;
}
alias = SimpleIdentifier();
} else {
alias = null;
}
if (jj_2_193(2)) {
where = Where();
} else {
where = null;
}
{if (true) return new SqlDelete(s.add(tableRef).addIf(alias).addIf(where).pos(),
tableRef, where, null, alias);}
throw new Error("Missing return statement in function");
}
/**
* Parses an UPDATE statement.
*/
final public SqlNode SqlUpdate() throws ParseException {
final SqlIdentifier tableName;
SqlNode tableRef;
final SqlIdentifier alias;
final SqlNode where;
final SqlNodeList sourceExpressionList;
final SqlNodeList targetColumnList;
SqlIdentifier id;
final Span s;
jj_consume_token(UPDATE);
s = span();
targetColumnList = new SqlNodeList(s.pos());
sourceExpressionList = new SqlNodeList(s.pos());
tableName = CompoundTableIdentifier();
if (jj_2_194(2)) {
tableRef = TableHints(tableName);
} else {
tableRef = tableName;
}
if (jj_2_195(2)) {
tableRef = ExtendTable(tableRef);
} else {
;
}
if (jj_2_197(2)) {
if (jj_2_196(2)) {
jj_consume_token(AS);
} else {
;
}
alias = SimpleIdentifier();
} else {
alias = null;
}
jj_consume_token(SET);
id = SimpleIdentifier();
targetColumnList.add(id);
jj_consume_token(EQ);
AddExpression(sourceExpressionList, ExprContext.ACCEPT_SUB_QUERY);
label_18:
while (true) {
if (jj_2_198(2)) {
;
} else {
break label_18;
}
jj_consume_token(COMMA);
id = SimpleIdentifier();
targetColumnList.add(id);
jj_consume_token(EQ);
AddExpression(sourceExpressionList, ExprContext.ACCEPT_SUB_QUERY);
}
if (jj_2_199(2)) {
where = Where();
} else {
where = null;
}
final SqlParserPos pos = s.addAll(targetColumnList)
.addAll(sourceExpressionList).addIf(where).pos();
{if (true) return new SqlUpdate(pos, tableRef, targetColumnList,
sourceExpressionList, where, null, alias);}
throw new Error("Missing return statement in function");
}
/**
* Parses a MERGE statement.
*/
final public SqlNode SqlMerge() throws ParseException {
final SqlIdentifier tableName;
SqlNode tableRef;
final SqlIdentifier alias;
final SqlNode sourceTableRef;
final SqlNode condition;
final SqlUpdate updateCall;
final SqlInsert insertCall;
final Span s;
jj_consume_token(MERGE);
s = span();
jj_consume_token(INTO);
tableName = CompoundTableIdentifier();
if (jj_2_200(2)) {
tableRef = TableHints(tableName);
} else {
tableRef = tableName;
}
if (jj_2_201(2)) {
tableRef = ExtendTable(tableRef);
} else {
;
}
if (jj_2_203(2)) {
if (jj_2_202(2)) {
jj_consume_token(AS);
} else {
;
}
alias = SimpleIdentifier();
} else {
alias = null;
}
jj_consume_token(USING);
sourceTableRef = TableRef();
jj_consume_token(ON);
condition = Expression(ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_205(2)) {
updateCall = WhenMatchedClause(tableRef, alias);
if (jj_2_204(2)) {
insertCall = WhenNotMatchedClause(tableRef);
} else {
insertCall = null;
}
} else if (jj_2_206(2)) {
updateCall = null;
insertCall = WhenNotMatchedClause(tableRef);
} else {
jj_consume_token(-1);
throw new ParseException();
}
final SqlParserPos pos = s.addIf(updateCall).addIf(insertCall).pos();
{if (true) return new SqlMerge(pos, tableRef, condition, sourceTableRef,
updateCall, insertCall, null, alias);}
throw new Error("Missing return statement in function");
}
final public SqlUpdate WhenMatchedClause(SqlNode table, SqlIdentifier alias) throws ParseException {
SqlIdentifier id;
final Span s;
final SqlNodeList updateColumnList = new SqlNodeList(SqlParserPos.ZERO);
final SqlNodeList updateExprList = new SqlNodeList(SqlParserPos.ZERO);
jj_consume_token(WHEN);
s = span();
jj_consume_token(MATCHED);
jj_consume_token(THEN);
jj_consume_token(UPDATE);
jj_consume_token(SET);
id = CompoundIdentifier();
updateColumnList.add(id);
jj_consume_token(EQ);
AddExpression(updateExprList, ExprContext.ACCEPT_SUB_QUERY);
label_19:
while (true) {
if (jj_2_207(2)) {
;
} else {
break label_19;
}
jj_consume_token(COMMA);
id = CompoundIdentifier();
updateColumnList.add(id);
jj_consume_token(EQ);
AddExpression(updateExprList, ExprContext.ACCEPT_SUB_QUERY);
}
{if (true) return new SqlUpdate(s.addAll(updateExprList).pos(), table,
updateColumnList, updateExprList, null, null, alias);}
throw new Error("Missing return statement in function");
}
final public SqlInsert WhenNotMatchedClause(SqlNode table) throws ParseException {
final Span insertSpan, valuesSpan;
final List keywords = new ArrayList();
final SqlNodeList keywordList;
final SqlNodeList insertColumnList;
SqlNode rowConstructor;
SqlNode insertValues;
jj_consume_token(WHEN);
jj_consume_token(NOT);
jj_consume_token(MATCHED);
jj_consume_token(THEN);
jj_consume_token(INSERT);
insertSpan = span();
SqlInsertKeywords(keywords);
keywordList = new SqlNodeList(keywords, insertSpan.end(this));
if (jj_2_208(2)) {
insertColumnList = ParenthesizedSimpleIdentifierList();
} else {
insertColumnList = null;
}
if (jj_2_209(2)) {
jj_consume_token(LPAREN);
jj_consume_token(VALUES);
valuesSpan = span();
rowConstructor = RowConstructor();
jj_consume_token(RPAREN);
} else if (jj_2_210(2)) {
jj_consume_token(VALUES);
valuesSpan = span();
rowConstructor = RowConstructor();
} else {
jj_consume_token(-1);
throw new ParseException();
}
// TODO zfong 5/26/06: note that extra parentheses are accepted above
// around the VALUES clause as a hack for unparse, but this is
// actually invalid SQL; should fix unparse
insertValues = SqlStdOperatorTable.VALUES.createCall(
valuesSpan.end(this), rowConstructor);
{if (true) return new SqlInsert(insertSpan.end(this), keywordList,
table, insertValues, insertColumnList);}
throw new Error("Missing return statement in function");
}
/**
* Parses one item in a select list.
*/
final public void AddSelectItem(List list) throws ParseException {
final SqlNode e;
final SqlIdentifier id;
e = SelectExpression();
if (jj_2_213(2)) {
if (jj_2_211(2)) {
jj_consume_token(AS);
} else {
;
}
if (jj_2_212(2)) {
id = SimpleIdentifier();
} else {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case QUOTED_STRING:
id = SimpleIdentifierFromStringLiteral();
break;
default:
jj_la1[2] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
list.add(SqlStdOperatorTable.AS.createCall(span().end(e), e, id));
} else {
list.add(e);
}
}
/**
* Parses one unaliased expression in a select list.
*/
final public SqlNode SelectExpression() throws ParseException {
SqlNode e;
if (jj_2_214(2)) {
jj_consume_token(STAR);
{if (true) return SqlIdentifier.star(getPos());}
} else if (jj_2_215(2)) {
e = Expression(ExprContext.ACCEPT_SUB_QUERY);
{if (true) return e;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public SqlLiteral Natural() throws ParseException {
if (jj_2_216(2)) {
jj_consume_token(NATURAL);
{if (true) return SqlLiteral.createBoolean(true, getPos());}
} else {
{if (true) return SqlLiteral.createBoolean(false, getPos());}
}
throw new Error("Missing return statement in function");
}
final public SqlLiteral JoinType() throws ParseException {
JoinType joinType;
if (jj_2_220(3)) {
jj_consume_token(JOIN);
joinType = JoinType.INNER;
} else if (jj_2_221(2)) {
jj_consume_token(INNER);
jj_consume_token(JOIN);
joinType = JoinType.INNER;
} else if (jj_2_222(2)) {
jj_consume_token(LEFT);
if (jj_2_217(2)) {
jj_consume_token(OUTER);
} else {
;
}
jj_consume_token(JOIN);
joinType = JoinType.LEFT;
} else if (jj_2_223(2)) {
jj_consume_token(RIGHT);
if (jj_2_218(2)) {
jj_consume_token(OUTER);
} else {
;
}
jj_consume_token(JOIN);
joinType = JoinType.RIGHT;
} else if (jj_2_224(2)) {
jj_consume_token(FULL);
if (jj_2_219(2)) {
jj_consume_token(OUTER);
} else {
;
}
jj_consume_token(JOIN);
joinType = JoinType.FULL;
} else if (jj_2_225(2)) {
jj_consume_token(CROSS);
jj_consume_token(JOIN);
joinType = JoinType.CROSS;
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return joinType.symbol(getPos());}
throw new Error("Missing return statement in function");
}
/**
* Parses the FROM clause for a SELECT.
*
* FROM is mandatory in standard SQL, optional in dialects such as MySQL,
* PostgreSQL. The parser allows SELECT without FROM, but the validator fails
* if conformance is, say, STRICT_2003.
*/
final public SqlNode FromClause() throws ParseException {
SqlNode e, e2;
SqlLiteral joinType;
e = Join();
label_20:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case COMMA:
;
break;
default:
jj_la1[3] = jj_gen;
break label_20;
}
jj_consume_token(COMMA);
joinType = JoinType.COMMA.symbol(getPos());
e2 = Join();
e = new SqlJoin(joinType.getParserPosition(),
e,
SqlLiteral.createBoolean(false, joinType.getParserPosition()),
joinType,
e2,
JoinConditionType.NONE.symbol(SqlParserPos.ZERO),
null);
}
{if (true) return e;}
throw new Error("Missing return statement in function");
}
final public SqlNode Join() throws ParseException {
SqlNode e;
e = TableRef1(ExprContext.ACCEPT_QUERY_OR_JOIN);
label_21:
while (true) {
if (jj_2_226(2)) {
;
} else {
break label_21;
}
e = JoinTable(e);
}
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/** Matches "LEFT JOIN t ON ...", "RIGHT JOIN t USING ...", "JOIN t". */
final public SqlNode JoinTable(SqlNode e) throws ParseException {
SqlNode e2, condition;
final SqlLiteral natural, joinType, on, using;
SqlNodeList list;
if (jj_2_229(3)) {
natural = Natural();
joinType = JoinType();
e2 = TableRef1(ExprContext.ACCEPT_QUERY_OR_JOIN);
if (jj_2_227(2)) {
jj_consume_token(ON);
on = JoinConditionType.ON.symbol(getPos());
condition = Expression(ExprContext.ACCEPT_SUB_QUERY);
{if (true) return new SqlJoin(joinType.getParserPosition(),
e,
natural,
joinType,
e2,
on,
condition);}
} else if (jj_2_228(2)) {
jj_consume_token(USING);
using = JoinConditionType.USING.symbol(getPos());
list = ParenthesizedSimpleIdentifierList();
{if (true) return new SqlJoin(joinType.getParserPosition(),
e,
natural,
joinType,
e2,
using,
new SqlNodeList(list, Span.of(using).end(this)));}
} else {
{if (true) return new SqlJoin(joinType.getParserPosition(),
e,
natural,
joinType,
e2,
JoinConditionType.NONE.symbol(joinType.getParserPosition()),
null);}
}
} else if (jj_2_230(2)) {
jj_consume_token(CROSS);
joinType = JoinType.CROSS.symbol(getPos());
jj_consume_token(APPLY);
e2 = TableRef2(true);
if (!this.conformance.isApplyAllowed()) {
{if (true) throw SqlUtil.newContextException(getPos(), RESOURCE.applyNotAllowed());}
}
{if (true) return new SqlJoin(joinType.getParserPosition(),
e,
SqlLiteral.createBoolean(false, joinType.getParserPosition()),
joinType,
e2,
JoinConditionType.NONE.symbol(SqlParserPos.ZERO),
null);}
} else if (jj_2_231(2)) {
jj_consume_token(OUTER);
joinType = JoinType.LEFT.symbol(getPos());
jj_consume_token(APPLY);
e2 = TableRef2(true);
if (!this.conformance.isApplyAllowed()) {
{if (true) throw SqlUtil.newContextException(getPos(), RESOURCE.applyNotAllowed());}
}
{if (true) return new SqlJoin(joinType.getParserPosition(),
e,
SqlLiteral.createBoolean(false, joinType.getParserPosition()),
joinType,
e2,
JoinConditionType.ON.symbol(SqlParserPos.ZERO),
SqlLiteral.createBoolean(true, joinType.getParserPosition()));}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses a table reference in a FROM clause, not lateral unless LATERAL
* is explicitly specified.
*/
final public SqlNode TableRef() throws ParseException {
final SqlNode e;
e = TableRef3(ExprContext.ACCEPT_QUERY, false);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
final public SqlNode TableRef1(ExprContext exprContext) throws ParseException {
final SqlNode e;
e = TableRef3(exprContext, false);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/**
* Parses a table reference in a FROM clause.
*/
final public SqlNode TableRef2(boolean lateral) throws ParseException {
final SqlNode e;
e = TableRef3(ExprContext.ACCEPT_QUERY, lateral);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
final public SqlNode TableRef3(ExprContext exprContext, boolean lateral) throws ParseException {
final SqlIdentifier tableName;
SqlNode tableRef;
final SqlIdentifier alias;
final Span s;
SqlNodeList args;
final SqlNodeList columnAliasList;
SqlUnnestOperator unnestOp = SqlStdOperatorTable.UNNEST;
if (jj_2_240(2)) {
tableName = CompoundTableIdentifier();
if (jj_2_232(2)) {
tableRef = TableHints(tableName);
} else {
tableRef = tableName;
}
if (jj_2_233(2)) {
tableRef = ExtendTable(tableRef);
} else {
;
}
tableRef = Over(tableRef);
if (jj_2_234(2)) {
tableRef = Snapshot(tableRef);
} else {
;
}
if (jj_2_235(2)) {
tableRef = MatchRecognize(tableRef);
} else {
;
}
} else if (jj_2_241(2)) {
if (jj_2_236(2)) {
jj_consume_token(LATERAL);
lateral = true;
} else {
;
}
tableRef = ParenthesizedExpression(exprContext);
tableRef = Over(tableRef);
tableRef = addLateral(tableRef, lateral);
if (jj_2_237(2)) {
tableRef = MatchRecognize(tableRef);
} else {
;
}
} else if (jj_2_242(2)) {
jj_consume_token(UNNEST);
s = span();
args = ParenthesizedQueryOrCommaList(ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_238(2)) {
jj_consume_token(WITH);
jj_consume_token(ORDINALITY);
unnestOp = SqlStdOperatorTable.UNNEST_WITH_ORDINALITY;
} else {
;
}
tableRef = unnestOp.createCall(s.end(this), (List) args);
} else if (jj_2_243(2)) {
if (jj_2_239(2)) {
jj_consume_token(LATERAL);
lateral = true;
} else {
;
}
tableRef = TableFunctionCall();
tableRef = addLateral(tableRef, lateral);
} else if (jj_2_244(2)) {
tableRef = ExtendedTableRef();
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (jj_2_245(2)) {
tableRef = Pivot(tableRef);
} else {
;
}
if (jj_2_246(2)) {
tableRef = Unpivot(tableRef);
} else {
;
}
if (jj_2_249(2)) {
if (jj_2_247(2)) {
jj_consume_token(AS);
} else {
;
}
alias = SimpleIdentifier();
if (jj_2_248(2)) {
columnAliasList = ParenthesizedSimpleIdentifierList();
} else {
columnAliasList = null;
}
// Standard SQL (and Postgres) allow applying "AS alias" to a JOIN,
// e.g. "FROM (a CROSS JOIN b) AS c". The new alias obscures the
// internal aliases, and columns cannot be referenced if they are
// not unique. TODO: Support this behavior; see
// [CALCITE-5168] Allow AS after parenthesized JOIN
checkNotJoin(tableRef);
if (columnAliasList == null) {
tableRef = SqlStdOperatorTable.AS.createCall(
Span.of(tableRef).end(this), tableRef, alias);
} else {
List idList = new ArrayList();
idList.add(tableRef);
idList.add(alias);
idList.addAll(columnAliasList.getList());
tableRef = SqlStdOperatorTable.AS.createCall(
Span.of(tableRef).end(this), idList);
}
} else {
;
}
if (jj_2_250(2)) {
tableRef = Tablesample(tableRef);
} else {
;
}
{if (true) return tableRef;}
throw new Error("Missing return statement in function");
}
final public SqlNode Tablesample(SqlNode tableRef) throws ParseException {
final Span s;
final SqlNode sample;
final boolean isBernoulli;
final SqlNumericLiteral samplePercentage;
boolean isRepeatable = false;
int repeatableSeed = 0;
jj_consume_token(TABLESAMPLE);
s = span(); checkNotJoin(tableRef);
if (jj_2_254(2)) {
jj_consume_token(SUBSTITUTE);
jj_consume_token(LPAREN);
sample = StringLiteral();
jj_consume_token(RPAREN);
String sampleName =
SqlLiteral.unchain(sample).getValueAs(String.class);
SqlSampleSpec sampleSpec = SqlSampleSpec.createNamed(sampleName);
final SqlLiteral sampleLiteral =
SqlLiteral.createSample(sampleSpec, s.end(this));
tableRef = SqlStdOperatorTable.TABLESAMPLE.createCall(
s.add(tableRef).end(this), tableRef, sampleLiteral);
} else if (jj_2_255(2)) {
if (jj_2_251(2)) {
jj_consume_token(BERNOULLI);
isBernoulli = true;
} else if (jj_2_252(2)) {
jj_consume_token(SYSTEM);
isBernoulli = false;
} else {
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(LPAREN);
samplePercentage = UnsignedNumericLiteral();
jj_consume_token(RPAREN);
if (jj_2_253(2)) {
jj_consume_token(REPEATABLE);
jj_consume_token(LPAREN);
repeatableSeed = IntLiteral();
jj_consume_token(RPAREN);
isRepeatable = true;
} else {
;
}
final BigDecimal ONE_HUNDRED = BigDecimal.valueOf(100L);
BigDecimal rate = samplePercentage.bigDecimalValue();
if (rate.compareTo(BigDecimal.ZERO) < 0
|| rate.compareTo(ONE_HUNDRED) > 0)
{
{if (true) throw SqlUtil.newContextException(getPos(), RESOURCE.invalidSampleSize());}
}
// Treat TABLESAMPLE(0) and TABLESAMPLE(100) as no table
// sampling at all. Not strictly correct: TABLESAMPLE(0)
// should produce no output, but it simplifies implementation
// to know that some amount of sampling will occur.
// In practice values less than ~1E-43% are treated as 0.0 and
// values greater than ~99.999997% are treated as 1.0
float fRate = rate.divide(ONE_HUNDRED).floatValue();
if (fRate > 0.0f && fRate < 1.0f) {
SqlSampleSpec tableSampleSpec =
isRepeatable
? SqlSampleSpec.createTableSample(
isBernoulli, fRate, repeatableSeed)
: SqlSampleSpec.createTableSample(isBernoulli, fRate);
SqlLiteral tableSampleLiteral =
SqlLiteral.createSample(tableSampleSpec, s.end(this));
tableRef = SqlStdOperatorTable.TABLESAMPLE.createCall(
s.end(this), tableRef, tableSampleLiteral);
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return tableRef;}
throw new Error("Missing return statement in function");
}
/** Wraps a table reference in a call to EXTEND if an optional "EXTEND" clause
* is present. */
final public SqlNode ExtendTable(SqlNode tableRef) throws ParseException {
final SqlNodeList extendList;
if (jj_2_256(2)) {
jj_consume_token(EXTEND);
} else {
;
}
extendList = ExtendList();
{if (true) return extend(tableRef, extendList);}
throw new Error("Missing return statement in function");
}
final public SqlNodeList ExtendList() throws ParseException {
final Span s;
List list = new ArrayList();
jj_consume_token(LPAREN);
s = span();
AddColumnType(list);
label_22:
while (true) {
if (jj_2_257(2)) {
;
} else {
break label_22;
}
jj_consume_token(COMMA);
AddColumnType(list);
}
jj_consume_token(RPAREN);
{if (true) return new SqlNodeList(list, s.end(this));}
throw new Error("Missing return statement in function");
}
final public void AddColumnType(List list) throws ParseException {
final SqlIdentifier name;
final SqlDataTypeSpec type;
final boolean nullable;
name = CompoundIdentifier();
type = DataType();
nullable = NotNullOpt();
list.add(name);
list.add(type.withNullable(nullable, getPos()));
}
/**
* Parses a compound identifier with optional type.
*/
final public void AddCompoundIdentifierType(List list, List extendList) throws ParseException {
final SqlIdentifier name;
final SqlDataTypeSpec type;
final boolean nullable;
name = CompoundIdentifier();
if (jj_2_258(2)) {
type = DataType();
nullable = NotNullOpt();
} else {
type = null; nullable = true;
}
if (type != null) {
if (!this.conformance.allowExtend()) {
{if (true) throw SqlUtil.newContextException(type.getParserPosition(),
RESOURCE.extendNotAllowed());}
}
extendList.add(name);
extendList.add(type.withNullable(nullable, getPos()));
}
list.add(name);
}
final public SqlNode TableFunctionCall() throws ParseException {
final Span s;
final SqlNode call;
SqlFunctionCategory funcType = SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION;
jj_consume_token(TABLE);
s = span();
jj_consume_token(LPAREN);
if (jj_2_259(2)) {
jj_consume_token(SPECIFIC);
funcType = SqlFunctionCategory.USER_DEFINED_TABLE_SPECIFIC_FUNCTION;
} else {
;
}
call = NamedRoutineCall(funcType, ExprContext.ACCEPT_CURSOR);
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.COLLECTION_TABLE.createCall(s.end(this), call);}
throw new Error("Missing return statement in function");
}
/**
* Abstract production:
* SqlNode ExtendedTableRef()
*
* Allows parser to be extended with new types of table references. The
* default implementation of this production is empty.
*/
/*
* Abstract production:
*
* SqlNode TableOverOpt()
*
* Allows an OVER clause following a table expression as an extension to
* standard SQL syntax. The default implementation of this production is empty.
*/
/**
* Parses an explicit TABLE t reference.
*/
final public SqlNode ExplicitTable(SqlParserPos pos) throws ParseException {
SqlNode tableRef;
jj_consume_token(TABLE);
tableRef = CompoundIdentifier();
{if (true) return SqlStdOperatorTable.EXPLICIT_TABLE.createCall(pos, tableRef);}
throw new Error("Missing return statement in function");
}
/**
* Parses a VALUES leaf query expression.
*/
final public SqlNode TableConstructor() throws ParseException {
final List list = new ArrayList();
final Span s;
if (jj_2_260(2)) {
jj_consume_token(VALUES);
s = span();
} else if (jj_2_261(2)) {
jj_consume_token(VALUE);
s = span();
if (!this.conformance.isValueAllowed()) {
{if (true) throw SqlUtil.newContextException(getPos(), RESOURCE.valueNotAllowed());}
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
AddRowConstructor(list);
label_23:
while (true) {
if (jj_2_262(2)) {
;
} else {
break label_23;
}
jj_consume_token(COMMA);
AddRowConstructor(list);
}
{if (true) return SqlStdOperatorTable.VALUES.createCall(s.end(this), list);}
throw new Error("Missing return statement in function");
}
/** Parses a row constructor and adds it to a list. */
final public void AddRowConstructor(List list) throws ParseException {
SqlNode e;
e = RowConstructor();
list.add(e);
}
/**
* Parses a row constructor in the context of a VALUES expression.
*/
final public SqlNode RowConstructor() throws ParseException {
final SqlNodeList valueList;
final SqlNode value;
final Span s;
if (jj_2_264(3)) {
jj_consume_token(LPAREN);
s = span();
jj_consume_token(ROW);
valueList = ParenthesizedQueryOrCommaListWithDefault(ExprContext.ACCEPT_NONCURSOR);
jj_consume_token(RPAREN);
s.add(this);
} else if (jj_2_265(3)) {
if (jj_2_263(2)) {
jj_consume_token(ROW);
s = span();
} else {
s = Span.of();
}
valueList = ParenthesizedQueryOrCommaListWithDefault(ExprContext.ACCEPT_NONCURSOR);
} else if (jj_2_266(2)) {
value = Expression(ExprContext.ACCEPT_NONCURSOR);
// NOTE: A bare value here is standard SQL syntax, believe it or
// not. Taken together with multi-row table constructors, it leads
// to very easy mistakes if you forget the parentheses on a
// single-row constructor. This is also the reason for the
// LOOKAHEAD in TableConstructor(). It would be so much more
// reasonable to require parentheses. Sigh.
s = Span.of(value);
valueList = new SqlNodeList(ImmutableList.of(value),
value.getParserPosition());
} else {
jj_consume_token(-1);
throw new ParseException();
}
// REVIEW jvs 8-Feb-2004: Should we discriminate between scalar
// sub-queries inside of ROW and row sub-queries? The standard does,
// but the distinction seems to be purely syntactic.
{if (true) return SqlStdOperatorTable.ROW.createCall(s.end(valueList),
(List) valueList);}
throw new Error("Missing return statement in function");
}
/** Parses a WHERE clause for SELECT, DELETE, and UPDATE. */
final public SqlNode Where() throws ParseException {
SqlNode condition;
jj_consume_token(WHERE);
condition = Expression(ExprContext.ACCEPT_SUB_QUERY);
{if (true) return condition;}
throw new Error("Missing return statement in function");
}
/** Parses a GROUP BY clause for SELECT. */
final public SqlNodeList GroupBy() throws ParseException {
final List list;
final boolean distinct;
final Span s;
jj_consume_token(GROUP);
s = span();
jj_consume_token(BY);
if (jj_2_267(2)) {
jj_consume_token(DISTINCT);
distinct = true;
} else if (jj_2_268(2)) {
jj_consume_token(ALL);
distinct = false;
} else {
distinct = false;
}
list = GroupingElementList();
final SqlParserPos pos = s.end(this);
final List list2 = distinct
? ImmutableList.of(
SqlInternalOperators.GROUP_BY_DISTINCT.createCall(pos, list))
: list;
{if (true) return new SqlNodeList(list2, pos);}
throw new Error("Missing return statement in function");
}
final public List GroupingElementList() throws ParseException {
final List list = new ArrayList();
AddGroupingElement(list);
label_24:
while (true) {
if (jj_2_269(2)) {
;
} else {
break label_24;
}
jj_consume_token(COMMA);
AddGroupingElement(list);
}
{if (true) return list;}
throw new Error("Missing return statement in function");
}
final public void AddGroupingElement(List list) throws ParseException {
final List subList;
final SqlNodeList nodes;
final Span s;
if (jj_2_270(2)) {
jj_consume_token(GROUPING);
s = span();
jj_consume_token(SETS);
jj_consume_token(LPAREN);
subList = GroupingElementList();
jj_consume_token(RPAREN);
list.add(
SqlStdOperatorTable.GROUPING_SETS.createCall(s.end(this), subList));
} else if (jj_2_271(2)) {
jj_consume_token(ROLLUP);
s = span();
jj_consume_token(LPAREN);
nodes = ExpressionCommaList(s, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(RPAREN);
list.add(
SqlStdOperatorTable.ROLLUP.createCall(s.end(this), nodes.getList()));
} else if (jj_2_272(2)) {
jj_consume_token(CUBE);
s = span();
jj_consume_token(LPAREN);
nodes = ExpressionCommaList(s, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(RPAREN);
list.add(
SqlStdOperatorTable.CUBE.createCall(s.end(this), nodes.getList()));
} else if (jj_2_273(3)) {
jj_consume_token(LPAREN);
s = span();
jj_consume_token(RPAREN);
list.add(new SqlNodeList(s.end(this)));
} else if (jj_2_274(2)) {
AddExpression(list, ExprContext.ACCEPT_SUB_QUERY);
} else {
jj_consume_token(-1);
throw new ParseException();
}
}
/**
* Parses a list of expressions separated by commas.
*/
final public SqlNodeList ExpressionCommaList(final Span s,
ExprContext exprContext) throws ParseException {
final List list = new ArrayList();
AddExpressions(list, exprContext);
{if (true) return new SqlNodeList(list, s.addAll(list).pos());}
throw new Error("Missing return statement in function");
}
/**
* Parses a list of expressions separated by commas,
* appending expressions to a given list.
*/
final public void AddExpressions(List list, ExprContext exprContext) throws ParseException {
AddExpression(list, exprContext);
label_25:
while (true) {
if (jj_2_275(2)) {
;
} else {
break label_25;
}
jj_consume_token(COMMA);
AddExpression(list, ExprContext.ACCEPT_SUB_QUERY);
}
}
/** Parses a HAVING clause for SELECT. */
final public SqlNode Having() throws ParseException {
SqlNode e;
jj_consume_token(HAVING);
e = Expression(ExprContext.ACCEPT_SUB_QUERY);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/** Parses a WINDOW clause for SELECT. */
final public SqlNodeList Window() throws ParseException {
final List list = new ArrayList();
final Span s;
jj_consume_token(WINDOW);
s = span();
AddWindowSpec(list);
label_26:
while (true) {
if (jj_2_276(2)) {
;
} else {
break label_26;
}
jj_consume_token(COMMA);
AddWindowSpec(list);
}
{if (true) return new SqlNodeList(list, s.addAll(list).pos());}
throw new Error("Missing return statement in function");
}
final public void AddWindowSpec(List list) throws ParseException {
final SqlIdentifier id;
final SqlWindow e;
id = SimpleIdentifier();
jj_consume_token(AS);
e = WindowSpecification();
e.setDeclName(id);
list.add(e);
}
/**
* Parses a window specification.
*/
final public SqlWindow WindowSpecification() throws ParseException {
final SqlIdentifier id;
final SqlNodeList partitionList;
final SqlNodeList orderList;
final SqlLiteral isRows;
final SqlNode lowerBound, upperBound;
final Span s, s1, s2;
final SqlLiteral allowPartial;
jj_consume_token(LPAREN);
s = span();
if (jj_2_277(2)) {
id = SimpleIdentifier();
} else {
id = null;
}
if (jj_2_278(2)) {
jj_consume_token(PARTITION);
s1 = span();
jj_consume_token(BY);
partitionList = ExpressionCommaList(s1, ExprContext.ACCEPT_NON_QUERY);
} else {
partitionList = SqlNodeList.EMPTY;
}
if (jj_2_279(2)) {
orderList = OrderBy(true);
} else {
orderList = SqlNodeList.EMPTY;
}
if (jj_2_284(2)) {
if (jj_2_280(2)) {
jj_consume_token(ROWS);
isRows = SqlLiteral.createBoolean(true, getPos());
} else if (jj_2_281(2)) {
jj_consume_token(RANGE);
isRows = SqlLiteral.createBoolean(false, getPos());
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (jj_2_282(2)) {
jj_consume_token(BETWEEN);
lowerBound = WindowRange();
jj_consume_token(AND);
upperBound = WindowRange();
} else if (jj_2_283(2)) {
lowerBound = WindowRange();
upperBound = null;
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
isRows = SqlLiteral.createBoolean(false, SqlParserPos.ZERO);
lowerBound = upperBound = null;
}
if (jj_2_285(2)) {
jj_consume_token(ALLOW);
s2 = span();
jj_consume_token(PARTIAL);
allowPartial = SqlLiteral.createBoolean(true, s2.end(this));
} else if (jj_2_286(2)) {
jj_consume_token(DISALLOW);
s2 = span();
jj_consume_token(PARTIAL);
allowPartial = SqlLiteral.createBoolean(false, s2.end(this));
} else {
allowPartial = null;
}
jj_consume_token(RPAREN);
{if (true) return SqlWindow.create(null, id, partitionList, orderList,
isRows, lowerBound, upperBound, allowPartial, s.end(this));}
throw new Error("Missing return statement in function");
}
final public SqlNode WindowRange() throws ParseException {
final SqlNode e;
final Span s;
if (jj_2_291(2)) {
jj_consume_token(CURRENT);
s = span();
jj_consume_token(ROW);
{if (true) return SqlWindow.createCurrentRow(s.end(this));}
} else if (jj_2_292(2)) {
jj_consume_token(UNBOUNDED);
s = span();
if (jj_2_287(2)) {
jj_consume_token(PRECEDING);
{if (true) return SqlWindow.createUnboundedPreceding(s.end(this));}
} else if (jj_2_288(2)) {
jj_consume_token(FOLLOWING);
{if (true) return SqlWindow.createUnboundedFollowing(s.end(this));}
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else if (jj_2_293(2)) {
e = Expression(ExprContext.ACCEPT_NON_QUERY);
if (jj_2_289(2)) {
jj_consume_token(PRECEDING);
{if (true) return SqlWindow.createPreceding(e, getPos());}
} else if (jj_2_290(2)) {
jj_consume_token(FOLLOWING);
{if (true) return SqlWindow.createFollowing(e, getPos());}
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/** Parses a QUALIFY clause for SELECT. */
final public SqlNode Qualify() throws ParseException {
SqlNode e;
jj_consume_token(QUALIFY);
e = Expression(ExprContext.ACCEPT_SUB_QUERY);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/**
* Parses an ORDER BY clause.
*/
final public SqlNodeList OrderBy(boolean accept) throws ParseException {
final List list = new ArrayList();
final Span s;
jj_consume_token(ORDER);
s = span();
if (!accept) {
// Someone told us ORDER BY wasn't allowed here. So why
// did they bother calling us? To get the correct
// parser position for error reporting.
{if (true) throw SqlUtil.newContextException(s.pos(), RESOURCE.illegalOrderBy());}
}
jj_consume_token(BY);
AddOrderItem(list);
label_27:
while (true) {
if (jj_2_294(2)) {
;
} else {
break label_27;
}
jj_consume_token(COMMA);
AddOrderItem(list);
}
{if (true) return new SqlNodeList(list, s.addAll(list).pos());}
throw new Error("Missing return statement in function");
}
/**
* Parses one item in an ORDER BY clause, and adds it to a list.
*/
final public void AddOrderItem(List list) throws ParseException {
SqlNode e;
e = Expression(ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_297(2)) {
if (jj_2_295(2)) {
jj_consume_token(ASC);
} else if (jj_2_296(2)) {
jj_consume_token(DESC);
e = SqlStdOperatorTable.DESC.createCall(getPos(), e);
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
if (jj_2_300(2)) {
if (jj_2_298(2)) {
jj_consume_token(NULLS);
jj_consume_token(FIRST);
e = SqlStdOperatorTable.NULLS_FIRST.createCall(getPos(), e);
} else if (jj_2_299(2)) {
jj_consume_token(NULLS);
jj_consume_token(LAST);
e = SqlStdOperatorTable.NULLS_LAST.createCall(getPos(), e);
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
list.add(e);
}
/** Wraps a table reference in a call to OVER if an optional "OVER" clause
* is present (if the dialect supports OVER for table expressions). */
final public SqlNode Over(SqlNode tableRef) throws ParseException {
final SqlNode over;
over = TableOverOpt();
if (over != null) {
{if (true) return SqlStdOperatorTable.OVER.createCall(
getPos(), checkNotJoin(tableRef), over);}
} else {
{if (true) return tableRef;}
}
throw new Error("Missing return statement in function");
}
SqlNode addLateral(SqlNode tableRef, boolean lateral) throws ParseException {
return lateral
? SqlStdOperatorTable.LATERAL.createCall(getPos(),
checkNotJoin(tableRef))
: tableRef;
}
/**
* Parses a FOR SYSTEM_TIME clause following a table expression.
*/
final public SqlSnapshot Snapshot(SqlNode tableRef) throws ParseException {
final Span s;
final SqlNode e;
s = span();
jj_consume_token(FOR);
jj_consume_token(SYSTEM_TIME);
jj_consume_token(AS);
jj_consume_token(OF);
// Syntax for temporal table in
// standard SQL 2011 IWD 9075-2:201?(E) 7.6
// supports grammar as following:
// 1. datetime literal
// 2. datetime value function, i.e. CURRENT_TIMESTAMP
// 3. datetime term in 1 or 2 +(or -) interval term
// We extend to support column reference, use Expression
// to simplify the parsing code.
e = Expression(ExprContext.ACCEPT_NON_QUERY);
{if (true) return new SqlSnapshot(s.end(this), tableRef, e);}
throw new Error("Missing return statement in function");
}
/** Parses a PIVOT clause following a table expression. */
final public SqlNode Pivot(SqlNode tableRef) throws ParseException {
final Span s;
final Span s2;
final List aggList = new ArrayList();
final List valueList = new ArrayList();
final SqlNodeList axisList;
final SqlNodeList inList;
jj_consume_token(PIVOT);
s = span(); checkNotJoin(tableRef);
jj_consume_token(LPAREN);
AddPivotAgg(aggList);
label_28:
while (true) {
if (jj_2_301(2)) {
;
} else {
break label_28;
}
jj_consume_token(COMMA);
AddPivotAgg(aggList);
}
jj_consume_token(FOR);
axisList = SimpleIdentifierOrList();
jj_consume_token(IN);
jj_consume_token(LPAREN);
s2 = span();
if (jj_2_303(2)) {
AddPivotValue(valueList);
label_29:
while (true) {
if (jj_2_302(2)) {
;
} else {
break label_29;
}
jj_consume_token(COMMA);
AddPivotValue(valueList);
}
} else {
;
}
jj_consume_token(RPAREN);
inList = new SqlNodeList(valueList, s2.end(this));
jj_consume_token(RPAREN);
{if (true) return new SqlPivot(s.end(this), tableRef,
new SqlNodeList(aggList, SqlParserPos.sum(aggList)),
axisList, inList);}
throw new Error("Missing return statement in function");
}
final public void AddPivotAgg(List list) throws ParseException {
final SqlNode e;
final SqlIdentifier alias;
e = NamedFunctionCall();
if (getToken(1).kind != COMMA && getToken(1).kind != FOR) {
if (jj_2_304(2)) {
jj_consume_token(AS);
} else {
;
}
alias = SimpleIdentifier();
list.add(
SqlStdOperatorTable.AS.createCall(Span.of(e).end(this), e,
alias));
} else {
list.add(e);
}
}
final public void AddPivotValue(List list) throws ParseException {
final SqlNode e;
final SqlNodeList tuple;
final SqlIdentifier alias;
e = RowConstructor();
tuple = SqlParserUtil.stripRow(e);
if (jj_2_306(2)) {
if (jj_2_305(2)) {
jj_consume_token(AS);
} else {
;
}
alias = SimpleIdentifier();
list.add(
SqlStdOperatorTable.AS.createCall(Span.of(tuple).end(this),
tuple, alias));
} else {
list.add(tuple);
}
}
/** Parses an UNPIVOT clause following a table expression. */
final public SqlNode Unpivot(SqlNode tableRef) throws ParseException {
final Span s;
final boolean includeNulls;
final SqlNodeList measureList;
final SqlNodeList axisList;
final Span s2;
final List values = new ArrayList();
final SqlNodeList inList;
jj_consume_token(UNPIVOT);
s = span(); checkNotJoin(tableRef);
if (jj_2_307(2)) {
jj_consume_token(INCLUDE);
jj_consume_token(NULLS);
includeNulls = true;
} else if (jj_2_308(2)) {
jj_consume_token(EXCLUDE);
jj_consume_token(NULLS);
includeNulls = false;
} else {
includeNulls = false;
}
jj_consume_token(LPAREN);
measureList = SimpleIdentifierOrList();
jj_consume_token(FOR);
axisList = SimpleIdentifierOrList();
jj_consume_token(IN);
jj_consume_token(LPAREN);
s2 = span();
AddUnpivotValue(values);
label_30:
while (true) {
if (jj_2_309(2)) {
;
} else {
break label_30;
}
jj_consume_token(COMMA);
AddUnpivotValue(values);
}
jj_consume_token(RPAREN);
inList = new SqlNodeList(values, s2.end(this));
jj_consume_token(RPAREN);
{if (true) return new SqlUnpivot(s.end(this), tableRef, includeNulls, measureList,
axisList, inList);}
throw new Error("Missing return statement in function");
}
final public void AddUnpivotValue(List list) throws ParseException {
final SqlNodeList columnList;
final SqlNode values;
columnList = SimpleIdentifierOrList();
if (jj_2_310(2)) {
jj_consume_token(AS);
values = RowConstructor();
final SqlNodeList valueList = SqlParserUtil.stripRow(values);
list.add(
SqlStdOperatorTable.AS.createCall(Span.of(columnList).end(this),
columnList, valueList));
} else {
list.add(columnList);
}
}
/**
* Parses a MATCH_RECOGNIZE clause following a table expression.
*/
final public SqlMatchRecognize MatchRecognize(SqlNode tableRef) throws ParseException {
final Span s, s0, s1, s2;
final SqlNodeList measureList;
final SqlNodeList partitionList;
final SqlNodeList orderList;
final SqlNode pattern;
final SqlLiteral interval;
final SqlNodeList patternDefList;
final SqlNode after;
final SqlNode var;
final SqlLiteral rowsPerMatch;
final SqlNodeList subsetList;
final SqlLiteral isStrictStarts;
final SqlLiteral isStrictEnds;
jj_consume_token(MATCH_RECOGNIZE);
s = span(); checkNotJoin(tableRef);
jj_consume_token(LPAREN);
if (jj_2_311(2)) {
jj_consume_token(PARTITION);
s2 = span();
jj_consume_token(BY);
partitionList = ExpressionCommaList(s2, ExprContext.ACCEPT_NON_QUERY);
} else {
partitionList = SqlNodeList.EMPTY;
}
if (jj_2_312(2)) {
orderList = OrderBy(true);
} else {
orderList = SqlNodeList.EMPTY;
}
if (jj_2_313(2)) {
jj_consume_token(MEASURES);
measureList = MeasureColumnCommaList(span());
} else {
measureList = SqlNodeList.EMPTY;
}
if (jj_2_314(2)) {
jj_consume_token(ONE);
s0 = span();
jj_consume_token(ROW);
jj_consume_token(PER);
jj_consume_token(MATCH);
rowsPerMatch = SqlMatchRecognize.RowsPerMatchOption.ONE_ROW.symbol(s0.end(this));
} else if (jj_2_315(2)) {
jj_consume_token(ALL);
s0 = span();
jj_consume_token(ROWS);
jj_consume_token(PER);
jj_consume_token(MATCH);
rowsPerMatch = SqlMatchRecognize.RowsPerMatchOption.ALL_ROWS.symbol(s0.end(this));
} else {
rowsPerMatch = null;
}
if (jj_2_321(2)) {
jj_consume_token(AFTER);
s1 = span();
jj_consume_token(MATCH);
jj_consume_token(SKIP_);
if (jj_2_319(2)) {
jj_consume_token(TO);
if (jj_2_317(2)) {
jj_consume_token(NEXT);
jj_consume_token(ROW);
after = SqlMatchRecognize.AfterOption.SKIP_TO_NEXT_ROW
.symbol(s1.end(this));
} else if (jj_2_318(2)) {
jj_consume_token(FIRST);
var = SimpleIdentifier();
after = SqlMatchRecognize.SKIP_TO_FIRST.createCall(
s1.end(var), var);
} else if (true) {
if (jj_2_316(2)) {
jj_consume_token(LAST);
} else {
;
}
var = SimpleIdentifier();
after = SqlMatchRecognize.SKIP_TO_LAST.createCall(
s1.end(var), var);
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else if (jj_2_320(2)) {
jj_consume_token(PAST);
jj_consume_token(LAST);
jj_consume_token(ROW);
after = SqlMatchRecognize.AfterOption.SKIP_PAST_LAST_ROW
.symbol(s1.end(this));
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
after = null;
}
jj_consume_token(PATTERN);
jj_consume_token(LPAREN);
if (jj_2_322(2)) {
jj_consume_token(CARET);
isStrictStarts = SqlLiteral.createBoolean(true, getPos());
} else {
isStrictStarts = SqlLiteral.createBoolean(false, getPos());
}
pattern = PatternExpression();
if (jj_2_323(2)) {
jj_consume_token(DOLLAR);
isStrictEnds = SqlLiteral.createBoolean(true, getPos());
} else {
isStrictEnds = SqlLiteral.createBoolean(false, getPos());
}
jj_consume_token(RPAREN);
if (jj_2_324(2)) {
jj_consume_token(WITHIN);
interval = IntervalLiteral();
} else {
interval = null;
}
if (jj_2_325(2)) {
jj_consume_token(SUBSET);
subsetList = SubsetDefinitionCommaList(span());
} else {
subsetList = SqlNodeList.EMPTY;
}
jj_consume_token(DEFINE);
patternDefList = PatternDefinitionCommaList(span());
jj_consume_token(RPAREN);
{if (true) return new SqlMatchRecognize(s.end(this), tableRef,
pattern, isStrictStarts, isStrictEnds, patternDefList, measureList,
after, subsetList, rowsPerMatch, partitionList, orderList, interval);}
throw new Error("Missing return statement in function");
}
final public SqlNodeList MeasureColumnCommaList(Span s) throws ParseException {
final List list = new ArrayList();
AddMeasureColumn(list);
label_31:
while (true) {
if (jj_2_326(2)) {
;
} else {
break label_31;
}
jj_consume_token(COMMA);
AddMeasureColumn(list);
}
{if (true) return new SqlNodeList(list, s.addAll(list).pos());}
throw new Error("Missing return statement in function");
}
final public void AddMeasureColumn(List list) throws ParseException {
final SqlNode e;
final SqlIdentifier alias;
e = Expression(ExprContext.ACCEPT_NON_QUERY);
jj_consume_token(AS);
alias = SimpleIdentifier();
list.add(SqlStdOperatorTable.AS.createCall(Span.of(e).end(this), e, alias));
}
final public SqlNode PatternExpression() throws ParseException {
SqlNode left;
SqlNode right;
left = PatternTerm();
label_32:
while (true) {
if (jj_2_327(2)) {
;
} else {
break label_32;
}
jj_consume_token(VERTICAL_BAR);
right = PatternTerm();
left = SqlStdOperatorTable.PATTERN_ALTER.createCall(
Span.of(left).end(right), left, right);
}
{if (true) return left;}
throw new Error("Missing return statement in function");
}
final public SqlNode PatternTerm() throws ParseException {
SqlNode left;
SqlNode right;
left = PatternFactor();
label_33:
while (true) {
if (jj_2_328(2)) {
;
} else {
break label_33;
}
right = PatternFactor();
left = SqlStdOperatorTable.PATTERN_CONCAT.createCall(
Span.of(left).end(right), left, right);
}
{if (true) return left;}
throw new Error("Missing return statement in function");
}
final public SqlNode PatternFactor() throws ParseException {
final SqlNode e;
final SqlNode extra;
final SqlLiteral startNum;
final SqlLiteral endNum;
final SqlLiteral reluctant;
e = PatternPrimary();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case LBRACE:
case HOOK:
case PLUS:
case STAR:
if (jj_2_334(2)) {
jj_consume_token(STAR);
startNum = LITERAL_ZERO;
endNum = LITERAL_MINUS_ONE;
} else if (jj_2_335(2)) {
jj_consume_token(PLUS);
startNum = LITERAL_ONE;
endNum = LITERAL_MINUS_ONE;
} else if (jj_2_336(2)) {
jj_consume_token(HOOK);
startNum = LITERAL_ZERO;
endNum = LITERAL_ONE;
} else if (jj_2_337(2)) {
jj_consume_token(LBRACE);
if (jj_2_331(2)) {
startNum = UnsignedNumericLiteral();
if (jj_2_330(2)) {
jj_consume_token(COMMA);
if (jj_2_329(2)) {
endNum = UnsignedNumericLiteral();
} else {
endNum = LITERAL_MINUS_ONE;
}
} else {
endNum = startNum;
}
jj_consume_token(RBRACE);
} else if (jj_2_332(2)) {
jj_consume_token(COMMA);
endNum = UnsignedNumericLiteral();
jj_consume_token(RBRACE);
startNum = LITERAL_MINUS_ONE;
} else if (jj_2_333(2)) {
jj_consume_token(MINUS);
extra = PatternExpression();
jj_consume_token(MINUS);
jj_consume_token(RBRACE);
{if (true) return SqlStdOperatorTable.PATTERN_CONCAT.createCall(
Span.of(e).end(this), e,
SqlStdOperatorTable.PATTERN_EXCLUDE.createCall(
Span.of(extra).end(this), extra));}
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (jj_2_338(2)) {
jj_consume_token(HOOK);
reluctant = SqlLiteral.createBoolean(
startNum.intValue(true) != endNum.intValue(true),
SqlParserPos.ZERO);
} else {
reluctant = SqlLiteral.createBoolean(false, SqlParserPos.ZERO);
}
break;
default:
jj_la1[4] = jj_gen;
{if (true) return e;}
}
{if (true) return SqlStdOperatorTable.PATTERN_QUANTIFIER.createCall(
span().end(e), e, startNum, endNum, reluctant);}
throw new Error("Missing return statement in function");
}
final public SqlNode PatternPrimary() throws ParseException {
final Span s;
SqlNode e;
final List list;
if (jj_2_340(2)) {
e = SimpleIdentifier();
{if (true) return e;}
} else if (jj_2_341(2)) {
jj_consume_token(LPAREN);
e = PatternExpression();
jj_consume_token(RPAREN);
{if (true) return e;}
} else if (jj_2_342(2)) {
jj_consume_token(LBRACE);
s = span();
jj_consume_token(MINUS);
e = PatternExpression();
jj_consume_token(MINUS);
jj_consume_token(RBRACE);
{if (true) return SqlStdOperatorTable.PATTERN_EXCLUDE.createCall(s.end(this), e);}
} else if (jj_2_343(2)) {
jj_consume_token(PERMUTE);
s = span(); list = new ArrayList();
jj_consume_token(LPAREN);
e = PatternExpression();
list.add(e);
label_34:
while (true) {
if (jj_2_339(2)) {
;
} else {
break label_34;
}
jj_consume_token(COMMA);
e = PatternExpression();
list.add(e);
}
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.PATTERN_PERMUTE.createCall(
s.end(this), list);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public SqlNodeList SubsetDefinitionCommaList(Span s) throws ParseException {
final List list = new ArrayList();
AddSubsetDefinition(list);
label_35:
while (true) {
if (jj_2_344(2)) {
;
} else {
break label_35;
}
jj_consume_token(COMMA);
AddSubsetDefinition(list);
}
{if (true) return new SqlNodeList(list, s.addAll(list).pos());}
throw new Error("Missing return statement in function");
}
final public void AddSubsetDefinition(List list) throws ParseException {
final SqlNode var;
final SqlNodeList varList;
var = SimpleIdentifier();
jj_consume_token(EQ);
jj_consume_token(LPAREN);
varList = ExpressionCommaList(span(), ExprContext.ACCEPT_NON_QUERY);
jj_consume_token(RPAREN);
list.add(
SqlStdOperatorTable.EQUALS.createCall(span().end(var), var,
varList));
}
final public SqlNodeList PatternDefinitionCommaList(Span s) throws ParseException {
SqlNode e;
final List eList = new ArrayList();
e = PatternDefinition();
eList.add(e);
label_36:
while (true) {
if (jj_2_345(2)) {
;
} else {
break label_36;
}
jj_consume_token(COMMA);
e = PatternDefinition();
eList.add(e);
}
{if (true) return new SqlNodeList(eList, s.addAll(eList).pos());}
throw new Error("Missing return statement in function");
}
final public SqlNode PatternDefinition() throws ParseException {
final SqlNode var;
final SqlNode e;
var = SimpleIdentifier();
jj_consume_token(AS);
e = Expression(ExprContext.ACCEPT_SUB_QUERY);
{if (true) return SqlStdOperatorTable.AS.createCall(Span.of(var, e).pos(), e, var);}
throw new Error("Missing return statement in function");
}
// ----------------------------------------------------------------------------
// Expressions
/**
* Parses a SQL expression (such as might occur in a WHERE clause) followed by
* the end-of-file symbol.
*/
final public SqlNode SqlExpressionEof() throws ParseException {
SqlNode e;
e = Expression(ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(0);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/**
* Parses either a row expression or a query expression without ORDER BY.
*
* Examples of valid queries:
*
* {@code SELECT c FROM t}
* {@code SELECT c} (valid in some dialects)
* {@code SELECT c FROM t UNION SELECT c2 FROM t2}
* {@code WITH q AS (SELECT 1) SELECT * FROM q}
* {@code VALUES (1, 2)}
* {@code TABLE t}
*
*
* Non-examples:
*
* {@code emp CROSS JOIN dept}
* {@code SELECT c FROM t ORDER BY c}
* {@code (SELECT c FROM t)}
*
*/
final public SqlNode QueryOrExpr(ExprContext exprContext) throws ParseException {
SqlNodeList withList = null;
final SqlNode e;
final List list = new ArrayList();
if (jj_2_346(2)) {
withList = WithList();
} else {
;
}
e = LeafQueryOrExpr(exprContext);
list.add(e);
label_37:
while (true) {
if (jj_2_347(2)) {
;
} else {
break label_37;
}
AddSetOpQuery(list, exprContext);
}
{if (true) return addWith(withList, SqlParserUtil.toTree(list));}
throw new Error("Missing return statement in function");
}
final public SqlNode Query(ExprContext exprContext) throws ParseException {
SqlNodeList withList = null;
final SqlNode e;
final List list = new ArrayList();
if (jj_2_348(2)) {
withList = WithList();
} else {
;
}
e = LeafQuery(exprContext);
list.add(e);
label_38:
while (true) {
if (jj_2_349(2)) {
;
} else {
break label_38;
}
AddSetOpQuery(list, exprContext);
}
{if (true) return addWith(withList, SqlParserUtil.toTree(list));}
throw new Error("Missing return statement in function");
}
SqlNode addWith(SqlNodeList withList, SqlNode e) throws ParseException {
return withList == null
? e
: new SqlWith(withList.getParserPosition(), withList, e);
}
/** Parses a set operator (e.g. UNION or INTERSECT)
* followed by a query or expression,
* and adds both to {@code list}. */
final public void AddSetOpQueryOrExpr(List list, ExprContext exprContext) throws ParseException {
final SqlOperator op;
final SqlParserPos pos;
final SqlNode e;
if (list.size() == 1 && !((SqlNode) list.get(0)).isA(SqlKind.QUERY)) {
// whoops, expression we just parsed wasn't a query,
// but we're about to see something like UNION, so
// force an exception retroactively
checkNonQueryExpression(ExprContext.ACCEPT_QUERY);
}
op = BinaryQueryOperator();
// ensure a query is legal in this context
pos = getPos();
checkQueryExpression(exprContext);
e = LeafQueryOrExpr(ExprContext.ACCEPT_QUERY);
list.add(new SqlParserUtil.ToTreeListItem(op, pos));
list.add(e);
}
/** Parses a set operator (e.g. UNION or INTERSECT)
* followed by a query,
* and adds both to {@code list}. */
final public void AddSetOpQuery(List list, ExprContext exprContext) throws ParseException {
final SqlOperator op;
final SqlParserPos pos;
final SqlNode e;
if (list.size() == 1 && !((SqlNode) list.get(0)).isA(SqlKind.QUERY)) {
// whoops, expression we just parsed wasn't a query,
// but we're about to see something like UNION, so
// force an exception retroactively
checkNonQueryExpression(ExprContext.ACCEPT_QUERY);
}
op = BinaryQueryOperator();
// ensure a query is legal in this context
pos = getPos();
checkQueryExpression(exprContext);
e = LeafQueryOrExpr(ExprContext.ACCEPT_QUERY);
list.add(new SqlParserUtil.ToTreeListItem(op, pos));
list.add(e);
}
final public SqlNodeList WithList() throws ParseException {
final Span s;
final List list = new ArrayList();
jj_consume_token(WITH);
s = span();
AddWithItem(list);
label_39:
while (true) {
if (jj_2_350(2)) {
;
} else {
break label_39;
}
jj_consume_token(COMMA);
AddWithItem(list);
}
{if (true) return new SqlNodeList(list, s.end(this));}
throw new Error("Missing return statement in function");
}
final public void AddWithItem(List list) throws ParseException {
final SqlIdentifier id;
final SqlNodeList columnList;
final SqlNode definition;
id = SimpleIdentifier();
if (jj_2_351(2)) {
columnList = ParenthesizedSimpleIdentifierList();
} else {
columnList = null;
}
jj_consume_token(AS);
definition = ParenthesizedExpression(ExprContext.ACCEPT_QUERY);
list.add(new SqlWithItem(id.getParserPosition(), id, columnList, definition));
}
/**
* Parses either a row expression, a leaf query expression, or
* a parenthesized expression of any kind.
*/
final public SqlNode LeafQueryOrExpr(ExprContext exprContext) throws ParseException {
SqlNode e;
if (jj_2_352(2)) {
e = LeafQuery(exprContext);
{if (true) return e;}
} else if (jj_2_353(2)) {
e = Expression(exprContext);
{if (true) return e;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/** As {@link #Expression} but appends to a list. */
final public void AddExpression(List list, ExprContext exprContext) throws ParseException {
final SqlNode e;
e = Expression(exprContext);
list.add(e);
}
/**
* Parses a row expression or a parenthesized expression of any kind.
*/
final public SqlNode Expression(ExprContext exprContext) throws ParseException {
final List list;
list = Expression2(exprContext);
{if (true) return SqlParserUtil.toTree(list);}
throw new Error("Missing return statement in function");
}
final public void AddExpression2b(List list, ExprContext exprContext) throws ParseException {
SqlNode e;
SqlOperator op;
SqlNode ext;
label_40:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case EXISTS:
case NOT:
case UNIQUE:
case PLUS:
case MINUS:
;
break;
default:
jj_la1[5] = jj_gen;
break label_40;
}
op = PrefixRowOperator();
checkNonQueryExpression(exprContext);
list.add(new SqlParserUtil.ToTreeListItem(op, getPos()));
}
e = Expression3(exprContext);
list.add(e);
label_41:
while (true) {
if (jj_2_354(2)) {
;
} else {
break label_41;
}
jj_consume_token(DOT);
ext = RowExpressionExtension();
list.add(
new SqlParserUtil.ToTreeListItem(
SqlStdOperatorTable.DOT, getPos()));
list.add(ext);
}
}
/**
* Parses a binary row expression, or a parenthesized expression of any
* kind.
*
* The result is as a flat list of operators and operands. The top-level
* call to get an expression should call {@link #Expression}, but lower-level
* calls should call this, to give the parser the opportunity to associate
* operator calls.
*
*
For example 'a = b like c = d' should come out '((a = b) like c) = d'
* because LIKE and '=' have the same precedence, but tends to come out as '(a
* = b) like (c = d)' because (a = b) and (c = d) are parsed as separate
* expressions.
*/
final public List Expression2(ExprContext exprContext) throws ParseException {
final List list = new ArrayList();
List list2;
final List list3 = new ArrayList();
SqlNodeList nodeList;
SqlNode e;
SqlOperator itemOp;
SqlOperator op;
SqlIdentifier p;
final Span s = span();
AddExpression2b(list, exprContext);
if (jj_2_387(2)) {
label_42:
while (true) {
if (jj_2_380(2)) {
checkNonQueryExpression(exprContext);
if (jj_2_358(2)) {
jj_consume_token(NOT);
jj_consume_token(IN);
op = SqlStdOperatorTable.NOT_IN;
} else if (jj_2_359(2)) {
jj_consume_token(IN);
op = SqlStdOperatorTable.IN;
} else if (jj_2_360(2)) {
final SqlKind k;
k = comp();
if (jj_2_355(2)) {
jj_consume_token(SOME);
op = SqlStdOperatorTable.some(k);
} else if (jj_2_356(2)) {
jj_consume_token(ANY);
op = SqlStdOperatorTable.some(k);
} else if (jj_2_357(2)) {
jj_consume_token(ALL);
op = SqlStdOperatorTable.all(k);
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
s.clear().add(this);
nodeList = ParenthesizedQueryOrCommaList(ExprContext.ACCEPT_NONCURSOR);
list.add(new SqlParserUtil.ToTreeListItem(op, s.pos()));
s.add(nodeList);
// special case for stuff like IN (s1 UNION s2)
if (nodeList.size() == 1) {
SqlNode item = nodeList.get(0);
if (item.isA(SqlKind.QUERY)) {
list.add(item);
} else {
list.add(nodeList);
}
} else {
list.add(nodeList);
}
} else if (jj_2_381(2)) {
checkNonQueryExpression(exprContext);
if (jj_2_367(2)) {
jj_consume_token(NOT);
jj_consume_token(BETWEEN);
op = SqlStdOperatorTable.NOT_BETWEEN;
s.clear().add(this);
if (jj_2_363(2)) {
if (jj_2_361(2)) {
jj_consume_token(SYMMETRIC);
op = SqlStdOperatorTable.SYMMETRIC_NOT_BETWEEN;
} else if (jj_2_362(2)) {
jj_consume_token(ASYMMETRIC);
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
} else if (jj_2_368(2)) {
jj_consume_token(BETWEEN);
op = SqlStdOperatorTable.BETWEEN;
s.clear().add(this);
if (jj_2_366(2)) {
if (jj_2_364(2)) {
jj_consume_token(SYMMETRIC);
op = SqlStdOperatorTable.SYMMETRIC_BETWEEN;
} else if (jj_2_365(2)) {
jj_consume_token(ASYMMETRIC);
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
AddExpression2b(list3, ExprContext.ACCEPT_SUB_QUERY);
list.add(new SqlParserUtil.ToTreeListItem(op, s.pos()));
list.addAll(list3);
list3.clear();
} else if (jj_2_382(2)) {
checkNonQueryExpression(exprContext);
s.clear().add(this);
if (jj_2_373(2)) {
jj_consume_token(NOT);
if (jj_2_369(2)) {
jj_consume_token(LIKE);
op = SqlStdOperatorTable.NOT_LIKE;
} else if (jj_2_370(2)) {
jj_consume_token(ILIKE);
op = SqlLibraryOperators.NOT_ILIKE;
} else if (jj_2_371(2)) {
jj_consume_token(RLIKE);
op = SqlLibraryOperators.NOT_RLIKE;
} else if (jj_2_372(2)) {
jj_consume_token(SIMILAR);
jj_consume_token(TO);
op = SqlStdOperatorTable.NOT_SIMILAR_TO;
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else if (jj_2_374(2)) {
jj_consume_token(LIKE);
op = SqlStdOperatorTable.LIKE;
} else if (jj_2_375(2)) {
jj_consume_token(ILIKE);
op = SqlLibraryOperators.ILIKE;
} else if (jj_2_376(2)) {
jj_consume_token(RLIKE);
op = SqlLibraryOperators.RLIKE;
} else if (jj_2_377(2)) {
jj_consume_token(SIMILAR);
jj_consume_token(TO);
op = SqlStdOperatorTable.SIMILAR_TO;
} else {
jj_consume_token(-1);
throw new ParseException();
}
list2 = Expression2(ExprContext.ACCEPT_SUB_QUERY);
list.add(new SqlParserUtil.ToTreeListItem(op, s.pos()));
list.addAll(list2);
if (jj_2_378(2)) {
jj_consume_token(ESCAPE);
e = Expression3(ExprContext.ACCEPT_SUB_QUERY);
s.clear().add(this);
list.add(
new SqlParserUtil.ToTreeListItem(
SqlStdOperatorTable.ESCAPE, s.pos()));
list.add(e);
} else {
;
}
} else if (jj_2_383(3)) {
op = BinaryRowOperator();
checkNonQueryExpression(exprContext);
list.add(new SqlParserUtil.ToTreeListItem(op, getPos()));
AddExpression2b(list, ExprContext.ACCEPT_SUB_QUERY);
} else if (jj_2_384(2)) {
jj_consume_token(LBRACKET);
itemOp = getItemOp();
e = Expression(ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(RBRACKET);
list.add(
new SqlParserUtil.ToTreeListItem(
itemOp, getPos()));
list.add(e);
label_43:
while (true) {
if (jj_2_379(2)) {
;
} else {
break label_43;
}
jj_consume_token(DOT);
p = SimpleIdentifier();
list.add(
new SqlParserUtil.ToTreeListItem(
SqlStdOperatorTable.DOT, getPos()));
list.add(p);
}
} else if (jj_2_385(2)) {
checkNonQueryExpression(exprContext);
op = PostfixRowOperator();
list.add(new SqlParserUtil.ToTreeListItem(op, getPos()));
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (jj_2_386(2)) {
;
} else {
break label_42;
}
}
{if (true) return list;}
} else {
{if (true) return list;}
}
throw new Error("Missing return statement in function");
}
/** Returns the appropriate ITEM operator for indexing arrays. */
final public SqlOperator getItemOp() throws ParseException {
if (jj_2_388(2)) {
jj_consume_token(OFFSET);
{if (true) return SqlLibraryOperators.OFFSET;}
} else if (jj_2_389(2)) {
jj_consume_token(ORDINAL);
{if (true) return SqlLibraryOperators.ORDINAL;}
} else if (jj_2_390(2)) {
jj_consume_token(SAFE_OFFSET);
{if (true) return SqlLibraryOperators.SAFE_OFFSET;}
} else if (jj_2_391(2)) {
jj_consume_token(SAFE_ORDINAL);
{if (true) return SqlLibraryOperators.SAFE_ORDINAL;}
} else {
{if (true) return SqlStdOperatorTable.ITEM;}
}
throw new Error("Missing return statement in function");
}
/** Parses a comparison operator inside a SOME / ALL predicate. */
final public SqlKind comp() throws ParseException {
if (jj_2_392(2)) {
jj_consume_token(LT);
{if (true) return SqlKind.LESS_THAN;}
} else if (jj_2_393(2)) {
jj_consume_token(LE);
{if (true) return SqlKind.LESS_THAN_OR_EQUAL;}
} else if (jj_2_394(2)) {
jj_consume_token(GT);
{if (true) return SqlKind.GREATER_THAN;}
} else if (jj_2_395(2)) {
jj_consume_token(GE);
{if (true) return SqlKind.GREATER_THAN_OR_EQUAL;}
} else if (jj_2_396(2)) {
jj_consume_token(EQ);
{if (true) return SqlKind.EQUALS;}
} else if (jj_2_397(2)) {
jj_consume_token(NE);
{if (true) return SqlKind.NOT_EQUALS;}
} else if (jj_2_398(2)) {
jj_consume_token(NE2);
if (!this.conformance.isBangEqualAllowed()) {
{if (true) throw SqlUtil.newContextException(getPos(), RESOURCE.bangEqualNotAllowed());}
}
{if (true) return SqlKind.NOT_EQUALS;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses a unary row expression, or a parenthesized expression of any
* kind.
*/
final public SqlNode Expression3(ExprContext exprContext) throws ParseException {
final SqlNode e;
final SqlNodeList list;
final SqlNodeList list1;
final Span s;
final Span rowSpan;
if (jj_2_401(2)) {
e = AtomicRowExpression();
checkNonQueryExpression(exprContext);
{if (true) return e;}
} else if (jj_2_402(2)) {
e = CursorExpression(exprContext);
{if (true) return e;}
} else if (jj_2_403(3)) {
jj_consume_token(ROW);
s = span();
list = ParenthesizedQueryOrCommaList(exprContext);
if (exprContext != ExprContext.ACCEPT_ALL
&& exprContext != ExprContext.ACCEPT_CURSOR
&& !this.conformance.allowExplicitRowValueConstructor())
{
{if (true) throw SqlUtil.newContextException(s.end(list),
RESOURCE.illegalRowExpression());}
}
{if (true) return SqlStdOperatorTable.ROW.createCall(list);}
} else if (jj_2_404(2)) {
if (jj_2_399(2)) {
jj_consume_token(ROW);
rowSpan = span();
} else {
rowSpan = null;
}
list1 = ParenthesizedQueryOrCommaList(exprContext);
if (rowSpan != null) {
// interpret as row constructor
{if (true) return SqlStdOperatorTable.ROW.createCall(rowSpan.end(list1),
(List) list1);}
}
if (jj_2_400(2)) {
e = IntervalQualifier();
if ((list1.size() == 1)
&& list1.get(0) instanceof SqlCall)
{
final SqlCall call = (SqlCall) list1.get(0);
if (call.getKind() == SqlKind.MINUS
&& call.operandCount() == 2) {
{if (true) return SqlStdOperatorTable.MINUS_DATE.createCall(
Span.of(list1).end(this), call.operand(0),
call.operand(1), e);}
}
}
{if (true) throw SqlUtil.newContextException(span().end(list1),
RESOURCE.illegalMinusDate());}
} else {
;
}
if (list1.size() == 1) {
// interpret as single value or query
{if (true) return list1.get(0);}
} else {
// interpret as row constructor
{if (true) return SqlStdOperatorTable.ROW.createCall(span().end(list1),
(List) list1);}
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public SqlOperator periodOperator() throws ParseException {
if (jj_2_405(2)) {
jj_consume_token(OVERLAPS);
{if (true) return SqlStdOperatorTable.OVERLAPS;}
} else if (jj_2_406(2)) {
jj_consume_token(IMMEDIATELY);
jj_consume_token(PRECEDES);
{if (true) return SqlStdOperatorTable.IMMEDIATELY_PRECEDES;}
} else if (jj_2_407(2)) {
jj_consume_token(PRECEDES);
{if (true) return SqlStdOperatorTable.PRECEDES;}
} else if (jj_2_408(2)) {
jj_consume_token(IMMEDIATELY);
jj_consume_token(SUCCEEDS);
{if (true) return SqlStdOperatorTable.IMMEDIATELY_SUCCEEDS;}
} else if (jj_2_409(2)) {
jj_consume_token(SUCCEEDS);
{if (true) return SqlStdOperatorTable.SUCCEEDS;}
} else if (jj_2_410(2)) {
jj_consume_token(EQUALS);
{if (true) return SqlStdOperatorTable.PERIOD_EQUALS;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses a COLLATE clause
*/
final public SqlCollation CollateClause() throws ParseException {
jj_consume_token(COLLATE);
jj_consume_token(COLLATION_ID);
{if (true) return new SqlCollation(
getToken(0).image, SqlCollation.Coercibility.EXPLICIT);}
throw new Error("Missing return statement in function");
}
/**
* Numeric literal or parameter; used in LIMIT, OFFSET and FETCH clauses.
*/
final public SqlNode UnsignedNumericLiteralOrParam() throws ParseException {
final SqlNode e;
if (jj_2_411(2)) {
e = UnsignedNumericLiteral();
} else if (jj_2_412(2)) {
e = DynamicParam();
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/**
* Parses a row expression extension, it can be either an identifier,
* or a call to a named function.
*/
final public SqlNode RowExpressionExtension() throws ParseException {
final SqlFunctionCategory funcType = SqlFunctionCategory.USER_DEFINED_FUNCTION;
final SqlIdentifier p;
final Span s;
final List args;
final SqlLiteral quantifier;
p = SimpleIdentifier();
if (jj_2_416(2147483647)) {
s = span();
if (jj_2_413(2)) {
jj_consume_token(LPAREN);
jj_consume_token(STAR);
quantifier = null;
args = ImmutableList.of(SqlIdentifier.star(getPos()));
jj_consume_token(RPAREN);
} else if (jj_2_414(2)) {
jj_consume_token(LPAREN);
jj_consume_token(RPAREN);
quantifier = null;
args = ImmutableList.of();
} else if (jj_2_415(2)) {
args = FunctionParameterList(ExprContext.ACCEPT_SUB_QUERY);
quantifier = (SqlLiteral) args.get(0);
args.remove(0);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return createCall(p, s.end(this), funcType, quantifier, args);}
} else {
{if (true) return p;}
}
throw new Error("Missing return statement in function");
}
/**
* Parses a call to the STRING_AGG aggregate function (or to an aggregate
* function with similar syntax: ARRAY_AGG, ARRAY_CONCAT_AGG, GROUP_CONCAT).
*/
final public SqlCall StringAggFunctionCall() throws ParseException {
final Span s, s2;
final SqlOperator op;
final List args = new ArrayList();
final SqlLiteral qualifier;
final SqlNodeList orderBy;
final Pair nullTreatment;
final SqlNode separator;
if (jj_2_417(2)) {
jj_consume_token(ARRAY_AGG);
s = span(); op = SqlLibraryOperators.ARRAY_AGG;
} else if (jj_2_418(2)) {
jj_consume_token(ARRAY_CONCAT_AGG);
s = span(); op = SqlLibraryOperators.ARRAY_CONCAT_AGG;
} else if (jj_2_419(2)) {
jj_consume_token(GROUP_CONCAT);
s = span(); op = SqlLibraryOperators.GROUP_CONCAT;
} else if (jj_2_420(2)) {
jj_consume_token(STRING_AGG);
s = span(); op = SqlLibraryOperators.STRING_AGG;
} else {
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(LPAREN);
if (jj_2_421(2)) {
qualifier = AllOrDistinct();
} else {
qualifier = null;
}
AddArg(args, ExprContext.ACCEPT_SUB_QUERY);
label_44:
while (true) {
if (jj_2_422(2)) {
;
} else {
break label_44;
}
jj_consume_token(COMMA);
// a comma-list can't appear where only a query is expected
// TODO: the following line is a no-op; remove it?
checkNonQueryExpression(ExprContext.ACCEPT_SUB_QUERY);
AddArg(args, ExprContext.ACCEPT_SUB_QUERY);
}
if (jj_2_423(2)) {
nullTreatment = NullTreatment();
} else {
nullTreatment = null;
}
if (jj_2_424(2)) {
orderBy = OrderBy(true);
args.add(orderBy);
} else {
;
}
if (jj_2_425(2)) {
jj_consume_token(SEPARATOR);
s2 = span();
separator = StringLiteral();
args.add(SqlInternalOperators.SEPARATOR.createCall(s2.end(this), separator));
} else {
;
}
jj_consume_token(RPAREN);
SqlCall call = op.createCall(qualifier, s.end(this), args);
if (nullTreatment != null) {
// Wrap in RESPECT_NULLS or IGNORE_NULLS.
call = nullTreatment.right.createCall(nullTreatment.left, call);
}
{if (true) return call;}
throw new Error("Missing return statement in function");
}
/**
* Parses both the standard and the BigQuery PERCENTILE_CONT/PERCENTILE_DISC
* functions.
*
* The standard is of the form "PERCENTILE_CONT(fraction)" while BigQuery is
* of the form "PERCENTILE_CONT(value, fraction [ {RESPECT | IGNORE} NULLS ] )".
* Handles the parsing of the operator and its operands but not the WITHIN GROUP
* (for the standard) or OVER (for BigQuery) clauses.
*/
final public SqlCall PercentileFunctionCall() throws ParseException {
final Span s;
SqlOperator op;
final SqlNode e;
final List args = new ArrayList();
final Pair nullTreatment;
if (jj_2_426(2)) {
jj_consume_token(PERCENTILE_CONT);
op = SqlStdOperatorTable.PERCENTILE_CONT;
} else if (jj_2_427(2)) {
jj_consume_token(PERCENTILE_DISC);
op = SqlStdOperatorTable.PERCENTILE_DISC;
} else {
jj_consume_token(-1);
throw new ParseException();
}
s = span();
jj_consume_token(LPAREN);
AddArg(args, ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_429(2)) {
jj_consume_token(RPAREN);
{if (true) return op.createCall(s.end(this), args);}
} else if (jj_2_430(2)) {
jj_consume_token(COMMA);
e = NumericLiteral();
args.add(e);
if (jj_2_428(2)) {
nullTreatment = NullTreatment();
} else {
nullTreatment = null;
}
jj_consume_token(RPAREN);
op =
op == SqlStdOperatorTable.PERCENTILE_CONT
? SqlLibraryOperators.PERCENTILE_CONT2
: SqlLibraryOperators.PERCENTILE_DISC2;
SqlCall call = op.createCall(s.end(this), args);
if (nullTreatment != null) {
// Wrap in RESPECT_NULLS or IGNORE_NULLS.
call = nullTreatment.right.createCall(nullTreatment.left, call);
}
{if (true) return call;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses an atomic row expression.
*/
final public SqlNode AtomicRowExpression() throws ParseException {
final SqlNode e;
if (jj_2_431(2)) {
e = LiteralOrIntervalExpression();
} else if (jj_2_432(2)) {
e = DynamicParam();
} else if (jj_2_433(2)) {
e = BuiltinFunctionCall();
} else if (jj_2_434(2)) {
e = JdbcFunctionCall();
} else if (jj_2_435(2)) {
e = MultisetConstructor();
} else if (jj_2_436(2)) {
e = ArrayConstructor();
} else if (jj_2_437(3)) {
e = MapConstructor();
} else if (jj_2_438(2)) {
e = PeriodConstructor();
} else if (jj_2_439(2147483647)) {
e = NamedFunctionCall();
} else if (jj_2_440(2)) {
e = ContextVariable();
} else if (jj_2_441(2)) {
e = CompoundIdentifier();
} else if (jj_2_442(2)) {
e = NewSpecification();
} else if (jj_2_443(2)) {
e = CaseExpression();
} else if (jj_2_444(2)) {
e = SequenceExpression();
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return e;}
throw new Error("Missing return statement in function");
}
final public SqlNode CaseExpression() throws ParseException {
final Span whenSpan = Span.of();
final Span thenSpan = Span.of();
final Span s;
SqlNode e;
final SqlNode caseIdentifier;
final SqlNode elseClause;
final List whenList = new ArrayList();
final List thenList = new ArrayList();
jj_consume_token(CASE);
s = span();
if (jj_2_445(2)) {
caseIdentifier = Expression(ExprContext.ACCEPT_SUB_QUERY);
} else {
caseIdentifier = null;
}
label_45:
while (true) {
jj_consume_token(WHEN);
whenSpan.add(this);
e = ExpressionCommaList(s, ExprContext.ACCEPT_SUB_QUERY);
if (((SqlNodeList) e).size() == 1) {
e = ((SqlNodeList) e).get(0);
}
whenList.add(e);
jj_consume_token(THEN);
thenSpan.add(this);
e = Expression(ExprContext.ACCEPT_SUB_QUERY);
thenList.add(e);
if (jj_2_446(2)) {
;
} else {
break label_45;
}
}
if (jj_2_447(2)) {
jj_consume_token(ELSE);
elseClause = Expression(ExprContext.ACCEPT_SUB_QUERY);
} else {
elseClause = null;
}
jj_consume_token(END);
{if (true) return SqlCase.createSwitched(s.end(this), caseIdentifier,
new SqlNodeList(whenList, whenSpan.addAll(whenList).pos()),
new SqlNodeList(thenList, thenSpan.addAll(thenList).pos()),
elseClause);}
throw new Error("Missing return statement in function");
}
final public SqlCall SequenceExpression() throws ParseException {
final Span s;
final SqlOperator f;
final SqlNode sequenceRef;
if (jj_2_448(2)) {
jj_consume_token(NEXT);
f = SqlStdOperatorTable.NEXT_VALUE; s = span();
} else if (jj_2_449(3)) {
jj_consume_token(CURRENT);
f = SqlStdOperatorTable.CURRENT_VALUE; s = span();
} else {
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(VALUE);
jj_consume_token(FOR);
sequenceRef = CompoundIdentifier();
{if (true) return f.createCall(s.end(sequenceRef), sequenceRef);}
throw new Error("Missing return statement in function");
}
/**
* Parses "SET <NAME> = VALUE" or "RESET <NAME>", without a leading
* "ALTER <SCOPE>".
*/
final public SqlSetOption SqlSetOption(Span s, String scope) throws ParseException {
SqlIdentifier name;
final SqlNode val;
if (jj_2_455(2)) {
jj_consume_token(SET);
s.add(this);
name = CompoundIdentifier();
jj_consume_token(EQ);
if (jj_2_450(2)) {
val = Literal();
} else if (jj_2_451(2)) {
val = SimpleIdentifier();
} else if (jj_2_452(2)) {
jj_consume_token(ON);
// OFF is handled by SimpleIdentifier, ON handled here.
val = new SqlIdentifier(token.image.toUpperCase(Locale.ROOT),
getPos());
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return new SqlSetOption(s.end(val), scope, name, val);}
} else if (jj_2_456(2)) {
jj_consume_token(RESET);
s.add(this);
if (jj_2_453(2)) {
name = CompoundIdentifier();
} else if (jj_2_454(2)) {
jj_consume_token(ALL);
name = new SqlIdentifier(token.image.toUpperCase(Locale.ROOT),
getPos());
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return new SqlSetOption(s.end(name), scope, name, null);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses an expression for setting or resetting an option in SQL, such as QUOTED_IDENTIFIERS,
* or explain plan level (physical/logical).
*/
final public SqlAlter SqlAlter() throws ParseException {
final Span s;
final String scope;
final SqlAlter alterNode;
jj_consume_token(ALTER);
s = span();
scope = Scope();
alterNode = SqlSetOption(s, scope);
{if (true) return alterNode;}
throw new Error("Missing return statement in function");
}
final public String Scope() throws ParseException {
if (jj_2_457(2)) {
jj_consume_token(SYSTEM);
} else if (jj_2_458(2)) {
jj_consume_token(SESSION);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return token.image.toUpperCase(Locale.ROOT);}
throw new Error("Missing return statement in function");
}
/**
* Parses a literal expression, allowing continued string literals.
* Usually returns an SqlLiteral, but a continued string literal
* is an SqlCall expression, which concatenates 2 or more string
* literals; the validator reduces this.
*
* If the context allows both literals and expressions,
* use {@link #LiteralOrIntervalExpression}, which requires less
* lookahead.
*/
final public SqlNode Literal() throws ParseException {
SqlNode e;
if (jj_2_459(2)) {
e = NonIntervalLiteral();
} else if (jj_2_460(2)) {
e = IntervalLiteral();
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/** Parses a literal that is not an interval literal. */
final public SqlNode NonIntervalLiteral() throws ParseException {
final SqlNode e;
if (jj_2_461(2)) {
e = NumericLiteral();
} else if (jj_2_462(2)) {
e = StringLiteral();
} else if (jj_2_463(2)) {
e = SpecialLiteral();
} else if (jj_2_464(2)) {
e = DateTimeLiteral();
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/** Parses a literal or an interval expression.
*
*
We include them in the same production because it is difficult to
* distinguish interval literals from interval expression (both of which
* start with the {@code INTERVAL} keyword); this way, we can use less
* LOOKAHEAD. */
final public SqlNode LiteralOrIntervalExpression() throws ParseException {
final SqlNode e;
if (jj_2_465(2)) {
e = IntervalLiteralOrExpression();
} else if (jj_2_466(2)) {
e = NonIntervalLiteral();
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return e;}
throw new Error("Missing return statement in function");
}
/** Parses a unsigned numeric literal */
final public SqlNumericLiteral UnsignedNumericLiteral() throws ParseException {
if (jj_2_467(2)) {
jj_consume_token(UNSIGNED_INTEGER_LITERAL);
{if (true) return SqlLiteral.createExactNumeric(token.image, getPos());}
} else if (jj_2_468(2)) {
jj_consume_token(DECIMAL_NUMERIC_LITERAL);
{if (true) return SqlLiteral.createExactNumeric(token.image, getPos());}
} else if (jj_2_469(2)) {
jj_consume_token(APPROX_NUMERIC_LITERAL);
{if (true) return SqlLiteral.createApproxNumeric(token.image, getPos());}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/** Parses a numeric literal (can be signed) */
final public SqlLiteral NumericLiteral() throws ParseException {
final SqlNumericLiteral num;
final Span s;
if (jj_2_470(2)) {
jj_consume_token(PLUS);
num = UnsignedNumericLiteral();
{if (true) return num;}
} else if (jj_2_471(2)) {
jj_consume_token(MINUS);
s = span();
num = UnsignedNumericLiteral();
{if (true) return SqlLiteral.createNegative(num, s.end(this));}
} else if (jj_2_472(2)) {
num = UnsignedNumericLiteral();
{if (true) return num;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/** Parse a special literal keyword */
final public SqlLiteral SpecialLiteral() throws ParseException {
if (jj_2_473(2)) {
jj_consume_token(TRUE);
{if (true) return SqlLiteral.createBoolean(true, getPos());}
} else if (jj_2_474(2)) {
jj_consume_token(FALSE);
{if (true) return SqlLiteral.createBoolean(false, getPos());}
} else if (jj_2_475(2)) {
jj_consume_token(UNKNOWN);
{if (true) return SqlLiteral.createUnknown(getPos());}
} else if (jj_2_476(2)) {
jj_consume_token(NULL);
{if (true) return SqlLiteral.createNull(getPos());}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses a string literal. The literal may be continued onto several
* lines. For a simple literal, the result is an SqlLiteral. For a continued
* literal, the result is an SqlCall expression, which concatenates 2 or more
* string literals; the validator reduces this.
*
* @see SqlLiteral#unchain(SqlNode)
* @see SqlLiteral#stringValue(SqlNode)
*
* @return a literal expression
*/
final public SqlNode StringLiteral() throws ParseException {
String p;
final List frags;
char unicodeEscapeChar = 0;
String charSet = null;
SqlCharStringLiteral literal;
if (jj_2_481(2)) {
jj_consume_token(BINARY_STRING_LITERAL);
frags = new ArrayList();
try {
p = SqlParserUtil.trim(token.image, "xX'");
frags.add(SqlLiteral.createBinaryString(p, getPos()));
} catch (NumberFormatException ex) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.illegalBinaryString(token.image));}
}
label_46:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case QUOTED_STRING:
;
break;
default:
jj_la1[6] = jj_gen;
break label_46;
}
jj_consume_token(QUOTED_STRING);
try {
p = SqlParserUtil.trim(token.image, "'"); // no embedded quotes
frags.add(SqlLiteral.createBinaryString(p, getPos()));
} catch (NumberFormatException ex) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.illegalBinaryString(token.image));}
}
}
assert !frags.isEmpty();
if (frags.size() == 1) {
{if (true) return frags.get(0);} // just the head fragment
} else {
SqlParserPos pos2 = SqlParserPos.sum(frags);
{if (true) return SqlStdOperatorTable.LITERAL_CHAIN.createCall(pos2, frags);}
}
} else if (jj_2_482(2)) {
if (jj_2_477(2)) {
jj_consume_token(PREFIXED_STRING_LITERAL);
charSet = SqlParserUtil.getCharacterSet(token.image);
} else if (jj_2_478(2)) {
jj_consume_token(QUOTED_STRING);
} else if (jj_2_479(2)) {
jj_consume_token(UNICODE_STRING_LITERAL);
// TODO jvs 2-Feb-2009: support the explicit specification of
// a character set for Unicode string literals, per SQL:2003
unicodeEscapeChar = BACKSLASH;
charSet = "UTF16";
} else {
jj_consume_token(-1);
throw new ParseException();
}
frags = new ArrayList();
p = SqlParserUtil.parseString(token.image);
try {
literal = SqlLiteral.createCharString(p, charSet, getPos());
frags.add(literal);
} catch (java.nio.charset.UnsupportedCharsetException e) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.unknownCharacterSet(charSet));}
}
label_47:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case QUOTED_STRING:
;
break;
default:
jj_la1[7] = jj_gen;
break label_47;
}
jj_consume_token(QUOTED_STRING);
p = SqlParserUtil.parseString(token.image);
try {
literal = SqlLiteral.createCharString(p, charSet, getPos());
frags.add(literal);
} catch (java.nio.charset.UnsupportedCharsetException e) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.unknownCharacterSet(charSet));}
}
}
if (jj_2_480(2)) {
jj_consume_token(UESCAPE);
jj_consume_token(QUOTED_STRING);
if (unicodeEscapeChar == 0) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.unicodeEscapeUnexpected());}
}
String s = SqlParserUtil.parseString(token.image);
unicodeEscapeChar = SqlParserUtil.checkUnicodeEscapeChar(s);
} else {
;
}
assert !frags.isEmpty();
if (frags.size() == 1) {
// just the head fragment
SqlLiteral lit = (SqlLiteral) frags.get(0);
{if (true) return lit.unescapeUnicode(unicodeEscapeChar);}
} else {
SqlNode[] rands = (SqlNode[]) frags.toArray(new SqlNode[0]);
for (int i = 0; i < rands.length; ++i) {
rands[i] = ((SqlLiteral) rands[i]).unescapeUnicode(
unicodeEscapeChar);
}
SqlParserPos pos2 = SqlParserPos.sum(rands);
{if (true) return SqlStdOperatorTable.LITERAL_CHAIN.createCall(pos2, rands);}
}
} else if (jj_2_483(2)) {
jj_consume_token(C_STYLE_ESCAPED_STRING_LITERAL);
try {
p = SqlParserUtil.parseCString(getToken(0).image);
} catch (SqlParserUtil.MalformedUnicodeEscape e) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.unicodeEscapeMalformed(e.i));}
}
{if (true) return SqlLiteral.createCharString(p, "UTF16", getPos());}
} else if (jj_2_484(2)) {
jj_consume_token(BIG_QUERY_DOUBLE_QUOTED_STRING);
p = SqlParserUtil.stripQuotes(getToken(0).image, DQ, DQ, "\\\"",
Casing.UNCHANGED);
try {
{if (true) return SqlLiteral.createCharString(p, charSet, getPos());}
} catch (java.nio.charset.UnsupportedCharsetException e) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.unknownCharacterSet(charSet));}
}
} else if (jj_2_485(2)) {
jj_consume_token(BIG_QUERY_QUOTED_STRING);
p = SqlParserUtil.stripQuotes(getToken(0).image, "'", "'", "\\'",
Casing.UNCHANGED);
try {
{if (true) return SqlLiteral.createCharString(p, charSet, getPos());}
} catch (java.nio.charset.UnsupportedCharsetException e) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.unknownCharacterSet(charSet));}
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/** Parses a character literal.
* Matches a single-quoted string, such as 'foo';
* on BigQuery also matches a double-quoted string, such as "foo".
* Returns the value of the string with quotes removed. */
final public String SimpleStringLiteral() throws ParseException {
if (jj_2_486(2)) {
jj_consume_token(QUOTED_STRING);
{if (true) return SqlParserUtil.parseString(token.image);}
} else if (jj_2_487(2)) {
jj_consume_token(BIG_QUERY_QUOTED_STRING);
{if (true) return SqlParserUtil.stripQuotes(token.image, "'", "'", "\\'", Casing.UNCHANGED);}
} else if (jj_2_488(2)) {
jj_consume_token(BIG_QUERY_DOUBLE_QUOTED_STRING);
{if (true) return SqlParserUtil.stripQuotes(token.image, DQ, DQ, "\\\"", Casing.UNCHANGED);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses a date/time literal.
*/
final public SqlLiteral DateTimeLiteral() throws ParseException {
final String p;
final Span s;
if (jj_2_489(2)) {
jj_consume_token(LBRACE_D);
jj_consume_token(QUOTED_STRING);
p = SqlParserUtil.parseString(token.image);
jj_consume_token(RBRACE);
{if (true) return SqlParserUtil.parseDateLiteral(p, getPos());}
} else if (jj_2_490(2)) {
jj_consume_token(LBRACE_T);
jj_consume_token(QUOTED_STRING);
p = SqlParserUtil.parseString(token.image);
jj_consume_token(RBRACE);
{if (true) return SqlParserUtil.parseTimeLiteral(p, getPos());}
} else if (jj_2_491(2)) {
jj_consume_token(LBRACE_TS);
s = span();
jj_consume_token(QUOTED_STRING);
p = SqlParserUtil.parseString(token.image);
jj_consume_token(RBRACE);
{if (true) return SqlParserUtil.parseTimestampLiteral(p, s.end(this));}
} else if (jj_2_492(2)) {
jj_consume_token(DATE);
s = span();
p = SimpleStringLiteral();
{if (true) return SqlLiteral.createUnknown("DATE", p, s.end(this));}
} else if (jj_2_493(2)) {
jj_consume_token(DATETIME);
s = span();
p = SimpleStringLiteral();
{if (true) return SqlLiteral.createUnknown("DATETIME", p, s.end(this));}
} else if (jj_2_494(2)) {
jj_consume_token(TIME);
s = span();
p = SimpleStringLiteral();
{if (true) return SqlLiteral.createUnknown("TIME", p, s.end(this));}
} else if (jj_2_495(2)) {
jj_consume_token(TIMESTAMP);
s = span();
p = SimpleStringLiteral();
{if (true) return SqlLiteral.createUnknown("TIMESTAMP", p, s.end(this));}
} else if (jj_2_496(2)) {
jj_consume_token(TIMESTAMP);
s = span();
jj_consume_token(WITH);
jj_consume_token(LOCAL);
jj_consume_token(TIME);
jj_consume_token(ZONE);
p = SimpleStringLiteral();
{if (true) return SqlLiteral.createUnknown("TIMESTAMP WITH LOCAL TIME ZONE", p, s.end(this));}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/** Parses a Date/Time constructor function, for example "DATE(1969, 7, 21)"
* or "DATETIME(d, t)". Enabled in some libraries (e.g. BigQuery). */
final public SqlNode DateTimeConstructorCall() throws ParseException {
final SqlFunctionCategory funcType = SqlFunctionCategory.TIMEDATE;
final SqlIdentifier qualifiedName;
final Span s;
final SqlLiteral quantifier;
final List extends SqlNode> args;
if (jj_2_497(2)) {
jj_consume_token(DATE);
} else if (jj_2_498(2)) {
jj_consume_token(TIME);
} else if (jj_2_499(2)) {
jj_consume_token(DATETIME);
} else if (jj_2_500(2)) {
jj_consume_token(TIMESTAMP);
} else {
jj_consume_token(-1);
throw new ParseException();
}
s = span();
qualifiedName = new SqlIdentifier(unquotedIdentifier(), getPos());
args = FunctionParameterList(ExprContext.ACCEPT_SUB_QUERY);
quantifier = (SqlLiteral) args.get(0);
args.remove(0);
{if (true) return createCall(qualifiedName, s.end(this), funcType, quantifier, args);}
throw new Error("Missing return statement in function");
}
/** Parses a MULTISET constructor */
final public SqlNode MultisetConstructor() throws ParseException {
final List args = new ArrayList();
SqlNode e;
final Span s;
jj_consume_token(MULTISET);
s = span();
if (jj_2_502(2)) {
jj_consume_token(LPAREN);
// by sub query "MULTISET(SELECT * FROM T)"
e = LeafQueryOrExpr(ExprContext.ACCEPT_QUERY);
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.MULTISET_QUERY.createCall(
s.end(this), e);}
} else if (jj_2_503(2)) {
jj_consume_token(LBRACKET);
AddExpression(args, ExprContext.ACCEPT_NON_QUERY);
label_48:
while (true) {
if (jj_2_501(2)) {
;
} else {
break label_48;
}
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_NON_QUERY);
}
jj_consume_token(RBRACKET);
{if (true) return SqlStdOperatorTable.MULTISET_VALUE.createCall(
s.end(this), args);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/** Parses an ARRAY constructor */
final public SqlNode ArrayConstructor() throws ParseException {
final SqlNodeList args;
SqlNode e;
final Span s;
final String p;
jj_consume_token(ARRAY);
s = span();
if (jj_2_507(2)) {
if (jj_2_504(2)) {
jj_consume_token(LPAREN);
jj_consume_token(RPAREN);
args = SqlNodeList.EMPTY;
} else if (jj_2_505(2)) {
args = ParenthesizedQueryOrCommaList(ExprContext.ACCEPT_ALL);
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (args.size() == 1 && args.get(0).isA(SqlKind.QUERY)) {
// Array query constructor, 'ARRAY (SELECT * FROM t)'
{if (true) return SqlStdOperatorTable.ARRAY_QUERY.createCall(s.end(this), args.get(0));}
} else {
// Spark ARRAY function, 'ARRAY(1, 2)',
// equivalent to standard 'ARRAY [1, 2]'
{if (true) return SqlLibraryOperators.ARRAY.createCall(s.end(this), args.getList());}
}
} else if (jj_2_508(2)) {
jj_consume_token(LBRACKET);
if (jj_2_506(2)) {
args = ExpressionCommaList(s, ExprContext.ACCEPT_NON_QUERY);
} else {
args = SqlNodeList.EMPTY;
}
jj_consume_token(RBRACKET);
{if (true) return SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR.createCall(
s.end(this), args.getList());}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public SqlCall ArrayLiteral() throws ParseException {
final List list;
SqlNode e;
final Span s;
jj_consume_token(LBRACE);
s = span();
if (jj_2_511(2)) {
e = Literal();
list = startList(e);
label_49:
while (true) {
if (jj_2_509(2)) {
;
} else {
break label_49;
}
jj_consume_token(COMMA);
e = Literal();
list.add(e);
}
} else if (jj_2_512(2)) {
e = ArrayLiteral();
list = startList(e);
label_50:
while (true) {
if (jj_2_510(2)) {
;
} else {
break label_50;
}
jj_consume_token(COMMA);
e = ArrayLiteral();
list.add(e);
}
} else {
list = Collections.emptyList();
}
jj_consume_token(RBRACE);
{if (true) return SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR.createCall(s.end(this), list);}
throw new Error("Missing return statement in function");
}
/** Parses a MAP constructor */
final public SqlNode MapConstructor() throws ParseException {
SqlNodeList args;
SqlNode e;
final Span s;
jj_consume_token(MAP);
s = span();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case LPAREN:
jj_consume_token(LPAREN);
// by sub query "MAP (SELECT empno, deptno FROM emp)"
e = LeafQueryOrExpr(ExprContext.ACCEPT_QUERY);
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.MAP_QUERY.createCall(
s.end(this), e);}
break;
default:
jj_la1[8] = jj_gen;
if (jj_2_514(2)) {
jj_consume_token(LBRACKET);
if (jj_2_513(2)) {
args = ExpressionCommaList(s, ExprContext.ACCEPT_NON_QUERY);
} else {
args = SqlNodeList.EMPTY;
}
jj_consume_token(RBRACKET);
{if (true) return SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR.createCall(
s.end(this), args.getList());}
} else {
jj_consume_token(-1);
throw new ParseException();
}
}
throw new Error("Missing return statement in function");
}
/** Parses a PERIOD constructor */
final public SqlNode PeriodConstructor() throws ParseException {
final List args = new ArrayList();
final Span s;
jj_consume_token(PERIOD);
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.ROW.createCall(s.end(this), args);}
throw new Error("Missing return statement in function");
}
/**
* Parses an interval literal.
*/
final public SqlLiteral IntervalLiteral() throws ParseException {
final String p;
final SqlIntervalQualifier intervalQualifier;
int sign = 1;
final Span s;
jj_consume_token(INTERVAL);
s = span();
if (jj_2_517(2)) {
if (jj_2_515(2)) {
jj_consume_token(MINUS);
sign = -1;
} else if (jj_2_516(2)) {
jj_consume_token(PLUS);
sign = 1;
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
p = SimpleStringLiteral();
intervalQualifier = IntervalQualifier();
{if (true) return SqlParserUtil.parseIntervalLiteral(s.end(intervalQualifier),
sign, p, intervalQualifier);}
throw new Error("Missing return statement in function");
}
/** Parses an interval literal (e.g. {@code INTERVAL '2:3' HOUR TO MINUTE})
* or an interval expression (e.g. {@code INTERVAL emp.empno MINUTE}
* or {@code INTERVAL 3 MONTHS}). */
final public SqlNode IntervalLiteralOrExpression() throws ParseException {
final String p;
final SqlIntervalQualifier intervalQualifier;
int sign = 1;
final Span s;
SqlNode e;
jj_consume_token(INTERVAL);
s = span();
if (jj_2_520(2)) {
if (jj_2_518(2)) {
jj_consume_token(MINUS);
sign = -1;
} else if (jj_2_519(2)) {
jj_consume_token(PLUS);
sign = 1;
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
if (jj_2_524(2)) {
// literal (with quoted string)
p = SimpleStringLiteral();
intervalQualifier = IntervalQualifier();
{if (true) return SqlParserUtil.parseIntervalLiteral(s.end(intervalQualifier),
sign, p, intervalQualifier);}
} else if (jj_2_525(2)) {
if (jj_2_521(2)) {
jj_consume_token(LPAREN);
e = Expression(ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(RPAREN);
} else if (jj_2_522(2)) {
e = UnsignedNumericLiteral();
} else if (jj_2_523(2)) {
e = CompoundIdentifier();
} else {
jj_consume_token(-1);
throw new ParseException();
}
intervalQualifier = IntervalQualifierStart();
if (sign == -1) {
e = SqlStdOperatorTable.UNARY_MINUS.createCall(e.getParserPosition(), e);
}
{if (true) return SqlStdOperatorTable.INTERVAL.createCall(s.end(this), e,
intervalQualifier);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public TimeUnit Year() throws ParseException {
if (jj_2_526(2)) {
jj_consume_token(YEAR);
{if (true) return TimeUnit.YEAR;}
} else if (jj_2_527(2)) {
jj_consume_token(YEARS);
{if (true) return warn(TimeUnit.YEAR);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public TimeUnit Quarter() throws ParseException {
if (jj_2_528(2)) {
jj_consume_token(QUARTER);
{if (true) return TimeUnit.QUARTER;}
} else if (jj_2_529(2)) {
jj_consume_token(QUARTERS);
{if (true) return warn(TimeUnit.QUARTER);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public TimeUnit Month() throws ParseException {
if (jj_2_530(2)) {
jj_consume_token(MONTH);
{if (true) return TimeUnit.MONTH;}
} else if (jj_2_531(2)) {
jj_consume_token(MONTHS);
{if (true) return warn(TimeUnit.MONTH);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public TimeUnit Week() throws ParseException {
if (jj_2_532(2)) {
jj_consume_token(WEEK);
{if (true) return TimeUnit.WEEK;}
} else if (jj_2_533(2)) {
jj_consume_token(WEEKS);
{if (true) return warn(TimeUnit.WEEK);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public TimeUnit Day() throws ParseException {
if (jj_2_534(2)) {
jj_consume_token(DAY);
{if (true) return TimeUnit.DAY;}
} else if (jj_2_535(2)) {
jj_consume_token(DAYS);
{if (true) return warn(TimeUnit.DAY);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public TimeUnit Hour() throws ParseException {
if (jj_2_536(2)) {
jj_consume_token(HOUR);
{if (true) return TimeUnit.HOUR;}
} else if (jj_2_537(2)) {
jj_consume_token(HOURS);
{if (true) return warn(TimeUnit.HOUR);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public TimeUnit Minute() throws ParseException {
if (jj_2_538(2)) {
jj_consume_token(MINUTE);
{if (true) return TimeUnit.MINUTE;}
} else if (jj_2_539(2)) {
jj_consume_token(MINUTES);
{if (true) return warn(TimeUnit.MINUTE);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public TimeUnit Second() throws ParseException {
if (jj_2_540(2)) {
jj_consume_token(SECOND);
{if (true) return TimeUnit.SECOND;}
} else if (jj_2_541(2)) {
jj_consume_token(SECONDS);
{if (true) return warn(TimeUnit.SECOND);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public SqlIntervalQualifier IntervalQualifier() throws ParseException {
final Span s;
final TimeUnit start;
final TimeUnit end;
final int startPrec;
int secondFracPrec = RelDataType.PRECISION_NOT_SPECIFIED;
if (jj_2_555(2)) {
start = Year();
s = span();
startPrec = PrecisionOpt();
if (jj_2_542(2)) {
jj_consume_token(TO);
end = Month();
} else {
end = null;
}
} else if (jj_2_556(2)) {
start = Quarter();
s = span();
startPrec = PrecisionOpt();
end = null;
} else if (jj_2_557(2)) {
start = Month();
s = span();
startPrec = PrecisionOpt();
end = null;
} else if (jj_2_558(2)) {
start = Week();
s = span();
startPrec = PrecisionOpt();
end = null;
} else if (jj_2_559(2)) {
start = Day();
s = span();
startPrec = PrecisionOpt();
if (jj_2_546(2)) {
jj_consume_token(TO);
if (jj_2_543(2)) {
end = Hour();
} else if (jj_2_544(2)) {
end = Minute();
} else if (jj_2_545(2)) {
end = Second();
secondFracPrec = PrecisionOpt();
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
end = null;
}
} else if (jj_2_560(2)) {
start = Hour();
s = span();
startPrec = PrecisionOpt();
if (jj_2_550(2)) {
jj_consume_token(TO);
if (jj_2_548(2)) {
end = Minute();
} else if (jj_2_549(2)) {
end = Second();
if (jj_2_547(2)) {
jj_consume_token(LPAREN);
secondFracPrec = UnsignedIntLiteral();
jj_consume_token(RPAREN);
} else {
;
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
end = null;
}
} else if (jj_2_561(2)) {
start = Minute();
s = span();
startPrec = PrecisionOpt();
if (jj_2_552(2)) {
jj_consume_token(TO);
end = Second();
if (jj_2_551(2)) {
jj_consume_token(LPAREN);
secondFracPrec = UnsignedIntLiteral();
jj_consume_token(RPAREN);
} else {
;
}
} else {
end = null;
}
} else if (jj_2_562(2)) {
start = Second();
s = span();
if (jj_2_554(2)) {
jj_consume_token(LPAREN);
startPrec = UnsignedIntLiteral();
if (jj_2_553(2)) {
jj_consume_token(COMMA);
secondFracPrec = UnsignedIntLiteral();
} else {
;
}
jj_consume_token(RPAREN);
} else {
startPrec = -1;
}
end = null;
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return new SqlIntervalQualifier(start, startPrec, end, secondFracPrec,
s.end(this));}
throw new Error("Missing return statement in function");
}
/** Interval qualifier without 'TO unit'. */
final public SqlIntervalQualifier IntervalQualifierStart() throws ParseException {
final Span s;
final TimeUnit start;
int startPrec = RelDataType.PRECISION_NOT_SPECIFIED;
int secondFracPrec = RelDataType.PRECISION_NOT_SPECIFIED;
if (jj_2_572(2)) {
if (jj_2_563(2)) {
start = Year();
} else if (jj_2_564(2)) {
start = Quarter();
} else if (jj_2_565(2)) {
start = Month();
} else if (jj_2_566(2)) {
start = Week();
} else if (jj_2_567(2)) {
start = Day();
} else if (jj_2_568(2)) {
start = Hour();
} else if (jj_2_569(2)) {
start = Minute();
} else {
jj_consume_token(-1);
throw new ParseException();
}
s = span();
startPrec = PrecisionOpt();
} else if (jj_2_573(2)) {
start = Second();
s = span();
if (jj_2_571(2)) {
jj_consume_token(LPAREN);
startPrec = UnsignedIntLiteral();
if (jj_2_570(2)) {
jj_consume_token(COMMA);
secondFracPrec = UnsignedIntLiteral();
} else {
;
}
jj_consume_token(RPAREN);
} else {
;
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return new SqlIntervalQualifier(start, startPrec, null, secondFracPrec,
s.end(this));}
throw new Error("Missing return statement in function");
}
/** Parses a built-in time unit (e.g. "YEAR")
* or user-defined time frame (e.g. "MINUTE15")
* and in each case returns a {@link SqlIntervalQualifier}.
*
* The units are used in several functions, incuding CEIL, FLOOR, EXTRACT.
* Includes NANOSECOND, MILLISECOND, which were previously allowed in EXTRACT
* but not CEIL, FLOOR.
*
*
Includes {@code WEEK} and {@code WEEK(SUNDAY)} through
{@code WEEK(SATURDAY)}.
*
*
Does not include SQL_TSI_DAY, SQL_TSI_FRAC_SECOND etc. These will be
* parsed as identifiers and can be resolved in the validator if they are
* registered as abbreviations in your time frame set.
*/
final public SqlIntervalQualifier TimeUnitOrName() throws ParseException {
final SqlIdentifier unitName;
final SqlIntervalQualifier intervalQualifier;
if (jj_2_574(2)) {
intervalQualifier = TimeUnit();
{if (true) return intervalQualifier;}
} else if (jj_2_575(2)) {
unitName = SimpleIdentifier();
{if (true) return new SqlIntervalQualifier(unitName.getSimple(),
unitName.getParserPosition());}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/** Parses a built-in time unit (e.g. "YEAR")
* and returns a {@link SqlIntervalQualifier}.
*
*
Includes {@code WEEK} and {@code WEEK(SUNDAY)} through
{@code WEEK(SATURDAY)}.
*
*
Does not include SQL_TSI_DAY, SQL_TSI_FRAC_SECOND etc. These will be
* parsed as identifiers and can be resolved in the validator if they are
* registered as abbreviations in your time frame set.
*/
final public SqlIntervalQualifier TimeUnit() throws ParseException {
final Span span;
final String w;
if (jj_2_577(2)) {
jj_consume_token(NANOSECOND);
{if (true) return new SqlIntervalQualifier(TimeUnit.NANOSECOND, null, getPos());}
} else if (jj_2_578(2)) {
jj_consume_token(MICROSECOND);
{if (true) return new SqlIntervalQualifier(TimeUnit.MICROSECOND, null, getPos());}
} else if (jj_2_579(2)) {
jj_consume_token(MILLISECOND);
{if (true) return new SqlIntervalQualifier(TimeUnit.MILLISECOND, null, getPos());}
} else if (jj_2_580(2)) {
jj_consume_token(SECOND);
{if (true) return new SqlIntervalQualifier(TimeUnit.SECOND, null, getPos());}
} else if (jj_2_581(2)) {
jj_consume_token(MINUTE);
{if (true) return new SqlIntervalQualifier(TimeUnit.MINUTE, null, getPos());}
} else if (jj_2_582(2)) {
jj_consume_token(HOUR);
{if (true) return new SqlIntervalQualifier(TimeUnit.HOUR, null, getPos());}
} else if (jj_2_583(2)) {
jj_consume_token(DAY);
{if (true) return new SqlIntervalQualifier(TimeUnit.DAY, null, getPos());}
} else if (jj_2_584(2)) {
jj_consume_token(DAYOFWEEK);
{if (true) return new SqlIntervalQualifier(TimeUnit.DOW, null, getPos());}
} else if (jj_2_585(2)) {
jj_consume_token(DAYOFYEAR);
{if (true) return new SqlIntervalQualifier(TimeUnit.DOY, null, getPos());}
} else if (jj_2_586(2)) {
jj_consume_token(DOW);
{if (true) return new SqlIntervalQualifier(TimeUnit.DOW, null, getPos());}
} else if (jj_2_587(2)) {
jj_consume_token(DOY);
{if (true) return new SqlIntervalQualifier(TimeUnit.DOY, null, getPos());}
} else if (jj_2_588(2)) {
jj_consume_token(ISODOW);
{if (true) return new SqlIntervalQualifier(TimeUnit.ISODOW, null, getPos());}
} else if (jj_2_589(2)) {
jj_consume_token(ISOYEAR);
{if (true) return new SqlIntervalQualifier(TimeUnit.ISOYEAR, null, getPos());}
} else if (jj_2_590(2)) {
jj_consume_token(WEEK);
span = span();
if (jj_2_576(2)) {
jj_consume_token(LPAREN);
w = weekdayName();
jj_consume_token(RPAREN);
{if (true) return new SqlIntervalQualifier(w, span.end(this));}
} else {
{if (true) return new SqlIntervalQualifier(TimeUnit.WEEK, null, getPos());}
}
} else if (jj_2_591(2)) {
jj_consume_token(MONTH);
{if (true) return new SqlIntervalQualifier(TimeUnit.MONTH, null, getPos());}
} else if (jj_2_592(2)) {
jj_consume_token(QUARTER);
{if (true) return new SqlIntervalQualifier(TimeUnit.QUARTER, null, getPos());}
} else if (jj_2_593(2)) {
jj_consume_token(YEAR);
{if (true) return new SqlIntervalQualifier(TimeUnit.YEAR, null, getPos());}
} else if (jj_2_594(2)) {
jj_consume_token(EPOCH);
{if (true) return new SqlIntervalQualifier(TimeUnit.EPOCH, null, getPos());}
} else if (jj_2_595(2)) {
jj_consume_token(DECADE);
{if (true) return new SqlIntervalQualifier(TimeUnit.DECADE, null, getPos());}
} else if (jj_2_596(2)) {
jj_consume_token(CENTURY);
{if (true) return new SqlIntervalQualifier(TimeUnit.CENTURY, null, getPos());}
} else if (jj_2_597(2)) {
jj_consume_token(MILLENNIUM);
{if (true) return new SqlIntervalQualifier(TimeUnit.MILLENNIUM, null, getPos());}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public String weekdayName() throws ParseException {
if (jj_2_598(2)) {
jj_consume_token(SUNDAY);
{if (true) return "WEEK_SUNDAY";}
} else if (jj_2_599(2)) {
jj_consume_token(MONDAY);
{if (true) return "WEEK_MONDAY";}
} else if (jj_2_600(2)) {
jj_consume_token(TUESDAY);
{if (true) return "WEEK_TUESDAY";}
} else if (jj_2_601(2)) {
jj_consume_token(WEDNESDAY);
{if (true) return "WEEK_WEDNESDAY";}
} else if (jj_2_602(2)) {
jj_consume_token(THURSDAY);
{if (true) return "WEEK_THURSDAY";}
} else if (jj_2_603(2)) {
jj_consume_token(FRIDAY);
{if (true) return "WEEK_FRIDAY";}
} else if (jj_2_604(2)) {
jj_consume_token(SATURDAY);
{if (true) return "WEEK_SATURDAY";}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses a dynamic parameter marker.
*/
final public SqlDynamicParam DynamicParam() throws ParseException {
jj_consume_token(HOOK);
{if (true) return new SqlDynamicParam(nDynamicParams++, getPos());}
throw new Error("Missing return statement in function");
}
/**
* Parses one segment of an identifier that may be composite.
*
*
Each time it reads an identifier it writes one element to each list;
* the entry in {@code positions} records its position and whether the
* segment was quoted.
*/
final public void AddIdentifierSegment(List names, List positions) throws ParseException {
final String id;
char unicodeEscapeChar = BACKSLASH;
final SqlParserPos pos;
final Span span;
if (jj_2_606(2)) {
jj_consume_token(IDENTIFIER);
id = unquotedIdentifier();
pos = getPos();
} else if (jj_2_607(2)) {
jj_consume_token(HYPHENATED_IDENTIFIER);
id = unquotedIdentifier();
pos = getPos();
} else if (jj_2_608(2)) {
jj_consume_token(QUOTED_IDENTIFIER);
id = SqlParserUtil.stripQuotes(getToken(0).image, DQ, DQ, DQDQ,
quotedCasing);
pos = getPos().withQuoting(true);
} else if (jj_2_609(2)) {
jj_consume_token(BACK_QUOTED_IDENTIFIER);
id = SqlParserUtil.stripQuotes(getToken(0).image, "`", "`", "``",
quotedCasing);
pos = getPos().withQuoting(true);
} else if (jj_2_610(2)) {
jj_consume_token(BIG_QUERY_BACK_QUOTED_IDENTIFIER);
id = SqlParserUtil.stripQuotes(getToken(0).image, "`", "`", "\\`",
quotedCasing);
pos = getPos().withQuoting(true);
} else if (jj_2_611(2)) {
jj_consume_token(BRACKET_QUOTED_IDENTIFIER);
id = SqlParserUtil.stripQuotes(getToken(0).image, "[", "]", "]]",
quotedCasing);
pos = getPos().withQuoting(true);
} else if (jj_2_612(2)) {
jj_consume_token(UNICODE_QUOTED_IDENTIFIER);
span = span();
String image = getToken(0).image;
image = image.substring(image.indexOf('"'));
image = SqlParserUtil.stripQuotes(image, DQ, DQ, DQDQ, quotedCasing);
if (jj_2_605(2)) {
jj_consume_token(UESCAPE);
jj_consume_token(QUOTED_STRING);
String s = SqlParserUtil.parseString(token.image);
unicodeEscapeChar = SqlParserUtil.checkUnicodeEscapeChar(s);
} else {
;
}
pos = span.end(this).withQuoting(true);
SqlLiteral lit = SqlLiteral.createCharString(image, "UTF16", pos);
lit = lit.unescapeUnicode(unicodeEscapeChar);
id = lit.toValue();
} else if (jj_2_613(2)) {
id = NonReservedKeyWord();
pos = getPos();
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (id.length() > this.identifierMaxLength) {
{if (true) throw SqlUtil.newContextException(pos,
RESOURCE.identifierTooLong(id, this.identifierMaxLength));}
}
names.add(id);
if (positions != null) {
positions.add(pos);
}
}
/** As {@link #AddIdentifierSegment} but part of a table name (for example,
* following {@code FROM}, {@code INSERT} or {@code UPDATE}).
*
* In some dialects the lexical rules for table names are different from
* for other identifiers. For example, in BigQuery, table names may contain
* hyphens. */
final public void AddTableIdentifierSegment(List names, List positions) throws ParseException {
AddIdentifierSegment(names, positions);
final int n = names.size();
if (n > 0
&& positions.size() == n
&& names.get(n - 1).contains(".")
&& positions.get(n - 1).isQuoted()
&& this.conformance.splitQuotedTableName()) {
final String name = names.remove(n - 1);
final SqlParserPos pos = positions.remove(n - 1);
final String[] splitNames = name.split("\\.");
for (String splitName : splitNames) {
names.add(splitName);
positions.add(pos);
}
}
}
/**
* Parses a simple identifier as a String.
*/
final public String Identifier() throws ParseException {
final List names = new ArrayList();
AddIdentifierSegment(names, null);
{if (true) return names.get(0);}
throw new Error("Missing return statement in function");
}
/**
* Parses a simple identifier as an SqlIdentifier.
*/
final public SqlIdentifier SimpleIdentifier() throws ParseException {
final List names = new ArrayList();
final List positions = new ArrayList();
AddIdentifierSegment(names, positions);
{if (true) return new SqlIdentifier(names.get(0), positions.get(0));}
throw new Error("Missing return statement in function");
}
/**
* Parses a character literal as an SqlIdentifier.
* Only valid for column aliases in certain dialects.
*/
final public SqlIdentifier SimpleIdentifierFromStringLiteral() throws ParseException {
jj_consume_token(QUOTED_STRING);
if (!this.conformance.allowCharLiteralAlias()) {
{if (true) throw SqlUtil.newContextException(getPos(), RESOURCE.charLiteralAliasNotValid());}
}
final String s = SqlParserUtil.parseString(token.image);
{if (true) return new SqlIdentifier(s, getPos());}
throw new Error("Missing return statement in function");
}
/**
* Parses a comma-separated list of simple identifiers.
*/
final public void AddSimpleIdentifiers(List list) throws ParseException {
SqlIdentifier id;
id = SimpleIdentifier();
list.add(id);
label_51:
while (true) {
if (jj_2_614(2)) {
;
} else {
break label_51;
}
jj_consume_token(COMMA);
id = SimpleIdentifier();
list.add(id);
}
}
/**
* List of simple identifiers in parentheses. The position extends from the
* open parenthesis to the close parenthesis.
*/
final public SqlNodeList ParenthesizedSimpleIdentifierList() throws ParseException {
final Span s;
final List list = new ArrayList();
jj_consume_token(LPAREN);
s = span();
AddSimpleIdentifiers(list);
jj_consume_token(RPAREN);
{if (true) return new SqlNodeList(list, s.end(this));}
throw new Error("Missing return statement in function");
}
/** List of simple identifiers in parentheses or one simple identifier.
*
* Examples:
* {@code DEPTNO}
* {@code (EMPNO, DEPTNO)}
*
*/
final public SqlNodeList SimpleIdentifierOrList() throws ParseException {
SqlIdentifier id;
SqlNodeList list;
if (jj_2_615(2)) {
id = SimpleIdentifier();
{if (true) return new SqlNodeList(Collections.singletonList(id), id.getParserPosition());}
} else if (jj_2_616(2)) {
list = ParenthesizedSimpleIdentifierList();
{if (true) return list;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Parses a compound identifier.
*/
final public SqlIdentifier CompoundIdentifier() throws ParseException {
final List nameList = new ArrayList();
final List posList = new ArrayList();
boolean star = false;
AddIdentifierSegment(nameList, posList);
label_52:
while (true) {
if (jj_2_617(2)) {
;
} else {
break label_52;
}
jj_consume_token(DOT);
AddIdentifierSegment(nameList, posList);
}
if (jj_2_618(2)) {
jj_consume_token(DOT);
jj_consume_token(STAR);
star = true;
nameList.add("");
posList.add(getPos());
} else {
;
}
SqlParserPos pos = SqlParserPos.sum(posList);
if (star) {
{if (true) return SqlIdentifier.star(nameList, pos, posList);}
}
{if (true) return new SqlIdentifier(nameList, null, pos, posList);}
throw new Error("Missing return statement in function");
}
/**
* Parses a compound identifier in the FROM clause.
*/
final public SqlIdentifier CompoundTableIdentifier() throws ParseException {
final List nameList = new ArrayList();
final List posList = new ArrayList();
AddTableIdentifierSegment(nameList, posList);
label_53:
while (true) {
if (jj_2_619(2)) {
;
} else {
break label_53;
}
jj_consume_token(DOT);
AddTableIdentifierSegment(nameList, posList);
}
SqlParserPos pos = SqlParserPos.sum(posList);
{if (true) return new SqlIdentifier(nameList, null, pos, posList);}
throw new Error("Missing return statement in function");
}
/**
* Parses a comma-separated list of compound identifiers.
*/
final public void AddCompoundIdentifierTypes(List list, List extendList) throws ParseException {
AddCompoundIdentifierType(list, extendList);
label_54:
while (true) {
if (jj_2_620(2)) {
;
} else {
break label_54;
}
jj_consume_token(COMMA);
AddCompoundIdentifierType(list, extendList);
}
}
/**
* List of compound identifiers in parentheses. The position extends from the
* open parenthesis to the close parenthesis.
*/
final public Pair ParenthesizedCompoundIdentifierList() throws ParseException {
final Span s;
final List list = new ArrayList();
final List extendList = new ArrayList();
jj_consume_token(LPAREN);
s = span();
AddCompoundIdentifierTypes(list, extendList);
jj_consume_token(RPAREN);
{if (true) return Pair.of(new SqlNodeList(list, s.end(this)), new SqlNodeList(extendList, s.end(this)));}
throw new Error("Missing return statement in function");
}
/**
* Parses a NEW UDT(...) expression.
*/
final public SqlNode NewSpecification() throws ParseException {
final Span s;
final SqlNode routineCall;
jj_consume_token(NEW);
s = span();
routineCall = NamedRoutineCall(SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR,
ExprContext.ACCEPT_SUB_QUERY);
{if (true) return SqlStdOperatorTable.NEW.createCall(s.end(routineCall), routineCall);}
throw new Error("Missing return statement in function");
}
//TODO: real parse errors.
final public int UnsignedIntLiteral() throws ParseException {
Token t;
t = jj_consume_token(UNSIGNED_INTEGER_LITERAL);
try {
{if (true) return Integer.parseInt(t.image);}
} catch (NumberFormatException ex) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.invalidLiteral(t.image, Integer.class.getCanonicalName()));}
}
throw new Error("Missing return statement in function");
}
final public int IntLiteral() throws ParseException {
Token t;
if (jj_2_623(2)) {
if (jj_2_621(2)) {
t = jj_consume_token(UNSIGNED_INTEGER_LITERAL);
} else if (jj_2_622(2)) {
jj_consume_token(PLUS);
t = jj_consume_token(UNSIGNED_INTEGER_LITERAL);
} else {
jj_consume_token(-1);
throw new ParseException();
}
try {
{if (true) return Integer.parseInt(t.image);}
} catch (NumberFormatException ex) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.invalidLiteral(t.image, Integer.class.getCanonicalName()));}
}
} else if (jj_2_624(2)) {
jj_consume_token(MINUS);
t = jj_consume_token(UNSIGNED_INTEGER_LITERAL);
try {
{if (true) return -Integer.parseInt(t.image);}
} catch (NumberFormatException ex) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.invalidLiteral(t.image, Integer.class.getCanonicalName()));}
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
// Type name with optional scale and precision.
final public SqlDataTypeSpec DataType() throws ParseException {
SqlTypeNameSpec typeName;
final Span s;
typeName = TypeName();
s = Span.of(typeName.getParserPos());
label_55:
while (true) {
if (jj_2_625(2)) {
;
} else {
break label_55;
}
typeName = CollectionsTypeName(typeName);
}
{if (true) return new SqlDataTypeSpec(typeName, s.add(typeName.getParserPos()).pos());}
throw new Error("Missing return statement in function");
}
// Some SQL type names need special handling due to the fact that they have
// spaces in them but are not quoted.
final public SqlTypeNameSpec TypeName() throws ParseException {
final SqlTypeNameSpec typeNameSpec;
final SqlIdentifier typeName;
final Span s = Span.of();
if (jj_2_626(2)) {
typeNameSpec = DruidType();
} else if (jj_2_627(2)) {
typeNameSpec = SqlTypeName(s);
} else if (jj_2_628(2)) {
typeNameSpec = RowTypeName();
} else if (jj_2_629(2)) {
typeName = CompoundIdentifier();
typeNameSpec = new SqlUserDefinedTypeNameSpec(typeName, s.end(this));
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return typeNameSpec;}
throw new Error("Missing return statement in function");
}
// Types used for JDBC and ODBC scalar conversion function
final public SqlTypeNameSpec SqlTypeName(Span s) throws ParseException {
final SqlTypeNameSpec sqlTypeNameSpec;
if (jj_2_630(2)) {
sqlTypeNameSpec = SqlTypeName1(s);
} else if (jj_2_631(2)) {
sqlTypeNameSpec = SqlTypeName2(s);
} else if (jj_2_632(2)) {
sqlTypeNameSpec = SqlTypeName3(s);
} else if (jj_2_633(2)) {
sqlTypeNameSpec = CharacterTypeName(s);
} else if (jj_2_634(2)) {
sqlTypeNameSpec = DateTimeTypeName();
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return sqlTypeNameSpec;}
throw new Error("Missing return statement in function");
}
// Parse sql type name that don't allow any extra specifications except the type name.
// For extra specification, we mean precision, scale, charSet, etc.
final public SqlTypeNameSpec SqlTypeName1(Span s) throws ParseException {
final SqlTypeName sqlTypeName;
if (jj_2_638(2)) {
jj_consume_token(GEOMETRY);
if (!this.conformance.allowGeometry()) {
{if (true) throw SqlUtil.newContextException(getPos(), RESOURCE.geometryDisabled());}
}
s.add(this);
sqlTypeName = SqlTypeName.GEOMETRY;
} else if (jj_2_639(2)) {
jj_consume_token(BOOLEAN);
s.add(this); sqlTypeName = SqlTypeName.BOOLEAN;
} else if (jj_2_640(2)) {
if (jj_2_635(2)) {
jj_consume_token(INTEGER);
} else if (jj_2_636(2)) {
jj_consume_token(INT);
} else {
jj_consume_token(-1);
throw new ParseException();
}
s.add(this); sqlTypeName = SqlTypeName.INTEGER;
} else if (jj_2_641(2)) {
jj_consume_token(TINYINT);
s.add(this); sqlTypeName = SqlTypeName.TINYINT;
} else if (jj_2_642(2)) {
jj_consume_token(SMALLINT);
s.add(this); sqlTypeName = SqlTypeName.SMALLINT;
} else if (jj_2_643(2)) {
jj_consume_token(BIGINT);
s.add(this); sqlTypeName = SqlTypeName.BIGINT;
} else if (jj_2_644(2)) {
jj_consume_token(REAL);
s.add(this); sqlTypeName = SqlTypeName.REAL;
} else if (jj_2_645(2)) {
jj_consume_token(DOUBLE);
s.add(this);
if (jj_2_637(2)) {
jj_consume_token(PRECISION);
} else {
;
}
sqlTypeName = SqlTypeName.DOUBLE;
} else if (jj_2_646(2)) {
jj_consume_token(FLOAT);
s.add(this); sqlTypeName = SqlTypeName.FLOAT;
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return new SqlBasicTypeNameSpec(sqlTypeName, s.end(this));}
throw new Error("Missing return statement in function");
}
// Parse sql type name that allows precision specification.
final public SqlTypeNameSpec SqlTypeName2(Span s) throws ParseException {
final SqlTypeName sqlTypeName;
int precision = -1;
if (jj_2_648(2)) {
jj_consume_token(BINARY);
s.add(this);
if (jj_2_647(2)) {
jj_consume_token(VARYING);
sqlTypeName = SqlTypeName.VARBINARY;
} else {
sqlTypeName = SqlTypeName.BINARY;
}
} else if (jj_2_649(2)) {
jj_consume_token(VARBINARY);
s.add(this); sqlTypeName = SqlTypeName.VARBINARY;
} else {
jj_consume_token(-1);
throw new ParseException();
}
precision = PrecisionOpt();
{if (true) return new SqlBasicTypeNameSpec(sqlTypeName, precision, s.end(this));}
throw new Error("Missing return statement in function");
}
// Parse sql type name that allows precision and scale specifications.
final public SqlTypeNameSpec SqlTypeName3(Span s) throws ParseException {
final SqlTypeName sqlTypeName;
int precision = -1;
int scale = -1;
if (jj_2_653(2)) {
if (jj_2_650(2)) {
jj_consume_token(DECIMAL);
} else if (jj_2_651(2)) {
jj_consume_token(DEC);
} else if (jj_2_652(2)) {
jj_consume_token(NUMERIC);
} else {
jj_consume_token(-1);
throw new ParseException();
}
s.add(this); sqlTypeName = SqlTypeName.DECIMAL;
} else if (jj_2_654(2)) {
jj_consume_token(ANY);
s.add(this); sqlTypeName = SqlTypeName.ANY;
} else {
jj_consume_token(-1);
throw new ParseException();
}
if (jj_2_656(2)) {
jj_consume_token(LPAREN);
precision = UnsignedIntLiteral();
if (jj_2_655(2)) {
jj_consume_token(COMMA);
scale = UnsignedIntLiteral();
} else {
;
}
jj_consume_token(RPAREN);
} else {
;
}
{if (true) return new SqlBasicTypeNameSpec(sqlTypeName, precision, scale, s.end(this));}
throw new Error("Missing return statement in function");
}
// Types used for for JDBC and ODBC scalar conversion function
final public SqlJdbcDataTypeName JdbcOdbcDataTypeName() throws ParseException {
if (jj_2_691(2)) {
if (jj_2_657(2)) {
jj_consume_token(SQL_CHAR);
} else if (jj_2_658(2)) {
jj_consume_token(CHAR);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_CHAR;}
} else if (jj_2_692(2)) {
if (jj_2_659(2)) {
jj_consume_token(SQL_VARCHAR);
} else if (jj_2_660(2)) {
jj_consume_token(VARCHAR);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_VARCHAR;}
} else if (jj_2_693(2)) {
if (jj_2_661(2)) {
jj_consume_token(SQL_DATE);
} else if (jj_2_662(2)) {
jj_consume_token(DATE);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_DATE;}
} else if (jj_2_694(2)) {
if (jj_2_663(2)) {
jj_consume_token(SQL_TIME);
} else if (jj_2_664(2)) {
jj_consume_token(TIME);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_TIME;}
} else if (jj_2_695(2)) {
if (jj_2_665(2)) {
jj_consume_token(SQL_TIMESTAMP);
} else if (jj_2_666(2)) {
jj_consume_token(TIMESTAMP);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_TIMESTAMP;}
} else if (jj_2_696(2)) {
if (jj_2_667(2)) {
jj_consume_token(SQL_DECIMAL);
} else if (jj_2_668(2)) {
jj_consume_token(DECIMAL);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_DECIMAL;}
} else if (jj_2_697(2)) {
if (jj_2_669(2)) {
jj_consume_token(SQL_NUMERIC);
} else if (jj_2_670(2)) {
jj_consume_token(NUMERIC);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_NUMERIC;}
} else if (jj_2_698(2)) {
if (jj_2_671(2)) {
jj_consume_token(SQL_BOOLEAN);
} else if (jj_2_672(2)) {
jj_consume_token(BOOLEAN);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_BOOLEAN;}
} else if (jj_2_699(2)) {
if (jj_2_673(2)) {
jj_consume_token(SQL_INTEGER);
} else if (jj_2_674(2)) {
jj_consume_token(INTEGER);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_INTEGER;}
} else if (jj_2_700(2)) {
if (jj_2_675(2)) {
jj_consume_token(SQL_BINARY);
} else if (jj_2_676(2)) {
jj_consume_token(BINARY);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_BINARY;}
} else if (jj_2_701(2)) {
if (jj_2_677(2)) {
jj_consume_token(SQL_VARBINARY);
} else if (jj_2_678(2)) {
jj_consume_token(VARBINARY);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_VARBINARY;}
} else if (jj_2_702(2)) {
if (jj_2_679(2)) {
jj_consume_token(SQL_TINYINT);
} else if (jj_2_680(2)) {
jj_consume_token(TINYINT);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_TINYINT;}
} else if (jj_2_703(2)) {
if (jj_2_681(2)) {
jj_consume_token(SQL_SMALLINT);
} else if (jj_2_682(2)) {
jj_consume_token(SMALLINT);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_SMALLINT;}
} else if (jj_2_704(2)) {
if (jj_2_683(2)) {
jj_consume_token(SQL_BIGINT);
} else if (jj_2_684(2)) {
jj_consume_token(BIGINT);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_BIGINT;}
} else if (jj_2_705(2)) {
if (jj_2_685(2)) {
jj_consume_token(SQL_REAL);
} else if (jj_2_686(2)) {
jj_consume_token(REAL);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_REAL;}
} else if (jj_2_706(2)) {
if (jj_2_687(2)) {
jj_consume_token(SQL_DOUBLE);
} else if (jj_2_688(2)) {
jj_consume_token(DOUBLE);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_DOUBLE;}
} else if (jj_2_707(2)) {
if (jj_2_689(2)) {
jj_consume_token(SQL_FLOAT);
} else if (jj_2_690(2)) {
jj_consume_token(FLOAT);
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return SqlJdbcDataTypeName.SQL_FLOAT;}
} else if (jj_2_708(2)) {
jj_consume_token(SQL_INTERVAL_YEAR);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_YEAR;}
} else if (jj_2_709(2)) {
jj_consume_token(SQL_INTERVAL_YEAR_TO_MONTH);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_YEAR_TO_MONTH;}
} else if (jj_2_710(2)) {
jj_consume_token(SQL_INTERVAL_MONTH);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_MONTH;}
} else if (jj_2_711(2)) {
jj_consume_token(SQL_INTERVAL_DAY);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_DAY;}
} else if (jj_2_712(2)) {
jj_consume_token(SQL_INTERVAL_DAY_TO_HOUR);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_DAY_TO_HOUR;}
} else if (jj_2_713(2)) {
jj_consume_token(SQL_INTERVAL_DAY_TO_MINUTE);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_DAY_TO_MINUTE;}
} else if (jj_2_714(2)) {
jj_consume_token(SQL_INTERVAL_DAY_TO_SECOND);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_DAY_TO_SECOND;}
} else if (jj_2_715(2)) {
jj_consume_token(SQL_INTERVAL_HOUR);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_HOUR;}
} else if (jj_2_716(2)) {
jj_consume_token(SQL_INTERVAL_HOUR_TO_MINUTE);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_HOUR_TO_MINUTE;}
} else if (jj_2_717(2)) {
jj_consume_token(SQL_INTERVAL_HOUR_TO_SECOND);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_HOUR_TO_SECOND;}
} else if (jj_2_718(2)) {
jj_consume_token(SQL_INTERVAL_MINUTE);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_MINUTE;}
} else if (jj_2_719(2)) {
jj_consume_token(SQL_INTERVAL_MINUTE_TO_SECOND);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_MINUTE_TO_SECOND;}
} else if (jj_2_720(2)) {
jj_consume_token(SQL_INTERVAL_SECOND);
{if (true) return SqlJdbcDataTypeName.SQL_INTERVAL_SECOND;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public SqlLiteral JdbcOdbcDataType() throws ParseException {
SqlJdbcDataTypeName typeName;
typeName = JdbcOdbcDataTypeName();
{if (true) return typeName.symbol(getPos());}
throw new Error("Missing return statement in function");
}
/**
* Parse a collection type name, the input element type name may
* also be a collection type.
*/
final public SqlTypeNameSpec CollectionsTypeName(SqlTypeNameSpec elementTypeName) throws ParseException {
final SqlTypeName collectionTypeName;
if (jj_2_721(2)) {
jj_consume_token(MULTISET);
collectionTypeName = SqlTypeName.MULTISET;
} else if (jj_2_722(2)) {
jj_consume_token(ARRAY);
collectionTypeName = SqlTypeName.ARRAY;
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return new SqlCollectionTypeNameSpec(elementTypeName,
collectionTypeName, getPos());}
throw new Error("Missing return statement in function");
}
/**
* Parse a nullable option, default is true.
*/
final public boolean NullableOptDefaultTrue() throws ParseException {
if (jj_2_723(2)) {
jj_consume_token(NULL);
{if (true) return true;}
} else if (jj_2_724(2)) {
jj_consume_token(NOT);
jj_consume_token(NULL);
{if (true) return false;}
} else {
{if (true) return true;}
}
throw new Error("Missing return statement in function");
}
/**
* Parse a nullable option, default is false.
*/
final public boolean NullableOptDefaultFalse() throws ParseException {
if (jj_2_725(2)) {
jj_consume_token(NULL);
{if (true) return true;}
} else if (jj_2_726(2)) {
jj_consume_token(NOT);
jj_consume_token(NULL);
{if (true) return false;}
} else {
{if (true) return false;}
}
throw new Error("Missing return statement in function");
}
/** Parses NOT NULL and returns false, or parses nothing and returns true. */
final public boolean NotNullOpt() throws ParseException {
if (jj_2_727(2)) {
jj_consume_token(NOT);
jj_consume_token(NULL);
{if (true) return false;}
} else {
{if (true) return true;}
}
throw new Error("Missing return statement in function");
}
/**
* Parse a "name1 type1 [NULL | NOT NULL], name2 type2 [NULL | NOT NULL] ..." list,
* the field type default is not nullable.
*/
final public void AddFieldNameTypes(List fieldNames,
List fieldTypes) throws ParseException {
AddFieldNameType(fieldNames, fieldTypes);
label_56:
while (true) {
if (jj_2_728(2)) {
;
} else {
break label_56;
}
jj_consume_token(COMMA);
AddFieldNameType(fieldNames, fieldTypes);
}
}
final public void AddFieldNameType(List fieldNames,
List fieldTypes) throws ParseException {
final SqlIdentifier fName;
final SqlDataTypeSpec fType;
final boolean nullable;
fName = SimpleIdentifier();
fType = DataType();
nullable = NullableOptDefaultFalse();
fieldNames.add(fName);
fieldTypes.add(fType.withNullable(nullable, getPos()));
}
/**
* Parse Row type with format: Row(name1 type1, name2 type2).
* Every field type can have suffix of `NULL` or `NOT NULL` to indicate if this type is nullable.
* i.e. Row(f0 int not null, f1 varchar null).
*/
final public SqlTypeNameSpec RowTypeName() throws ParseException {
List fieldNames = new ArrayList();
List fieldTypes = new ArrayList();
jj_consume_token(ROW);
jj_consume_token(LPAREN);
AddFieldNameTypes(fieldNames, fieldTypes);
jj_consume_token(RPAREN);
{if (true) return new SqlRowTypeNameSpec(getPos(), fieldNames, fieldTypes);}
throw new Error("Missing return statement in function");
}
/**
* Parse character types: char, varchar.
*/
final public SqlTypeNameSpec CharacterTypeName(Span s) throws ParseException {
int precision = -1;
final SqlTypeName sqlTypeName;
String charSetName = null;
if (jj_2_732(2)) {
if (jj_2_729(2)) {
jj_consume_token(CHARACTER);
} else if (jj_2_730(2)) {
jj_consume_token(CHAR);
} else {
jj_consume_token(-1);
throw new ParseException();
}
s.add(this);
if (jj_2_731(2)) {
jj_consume_token(VARYING);
sqlTypeName = SqlTypeName.VARCHAR;
} else {
sqlTypeName = SqlTypeName.CHAR;
}
} else if (jj_2_733(2)) {
jj_consume_token(VARCHAR);
s.add(this); sqlTypeName = SqlTypeName.VARCHAR;
} else {
jj_consume_token(-1);
throw new ParseException();
}
precision = PrecisionOpt();
if (jj_2_734(2)) {
jj_consume_token(CHARACTER);
jj_consume_token(SET);
charSetName = Identifier();
} else {
;
}
{if (true) return new SqlBasicTypeNameSpec(sqlTypeName, precision, charSetName, s.end(this));}
throw new Error("Missing return statement in function");
}
/**
* Parse datetime types: date, time, timestamp.
*/
final public SqlTypeNameSpec DateTimeTypeName() throws ParseException {
int precision = -1;
SqlTypeName typeName;
boolean withLocalTimeZone = false;
final Span s;
if (jj_2_735(2)) {
jj_consume_token(DATE);
typeName = SqlTypeName.DATE;
{if (true) return new SqlBasicTypeNameSpec(typeName, getPos());}
} else if (jj_2_736(2)) {
jj_consume_token(TIME);
s = span();
precision = PrecisionOpt();
withLocalTimeZone = TimeZoneOpt();
if (withLocalTimeZone) {
typeName = SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE;
} else {
typeName = SqlTypeName.TIME;
}
{if (true) return new SqlBasicTypeNameSpec(typeName, precision, s.end(this));}
} else if (jj_2_737(2)) {
jj_consume_token(TIMESTAMP);
s = span();
precision = PrecisionOpt();
withLocalTimeZone = TimeZoneOpt();
if (withLocalTimeZone) {
typeName = SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE;
} else {
typeName = SqlTypeName.TIMESTAMP;
}
{if (true) return new SqlBasicTypeNameSpec(typeName, precision, s.end(this));}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
// Parse an optional data type precision, default is -1.
final public int PrecisionOpt() throws ParseException {
int precision = -1;
if (jj_2_738(2)) {
jj_consume_token(LPAREN);
precision = UnsignedIntLiteral();
jj_consume_token(RPAREN);
{if (true) return precision;}
} else {
{if (true) return -1;}
}
throw new Error("Missing return statement in function");
}
/**
* Parse a time zone suffix for DateTime types. According to SQL-2011,
* "with time zone" and "without time zone" belong to standard SQL but we
* only implement the "without time zone".
*
* We also support "with local time zone".
*
* @return true if this is "with local time zone".
*/
final public boolean TimeZoneOpt() throws ParseException {
if (jj_2_739(3)) {
jj_consume_token(WITHOUT);
jj_consume_token(TIME);
jj_consume_token(ZONE);
{if (true) return false;}
} else if (jj_2_740(2)) {
jj_consume_token(WITH);
jj_consume_token(LOCAL);
jj_consume_token(TIME);
jj_consume_token(ZONE);
{if (true) return true;}
} else {
{if (true) return false;}
}
throw new Error("Missing return statement in function");
}
/**
* Parses a CURSOR(query) expression. The parser allows these
* anywhere, but the validator restricts them to appear only as
* arguments to table functions.
*/
final public SqlNode CursorExpression(ExprContext exprContext) throws ParseException {
final SqlNode e;
final Span s;
jj_consume_token(CURSOR);
s = span();
if (exprContext != ExprContext.ACCEPT_ALL
&& exprContext != ExprContext.ACCEPT_CURSOR) {
{if (true) throw SqlUtil.newContextException(s.end(this),
RESOURCE.illegalCursorExpression());}
}
e = Expression(ExprContext.ACCEPT_QUERY);
{if (true) return SqlStdOperatorTable.CURSOR.createCall(s.end(e), e);}
throw new Error("Missing return statement in function");
}
/**
* Parses a call to a builtin function with special syntax.
*/
final public SqlNode BuiltinFunctionCall() throws ParseException {
final SqlIdentifier name;
final List args = new ArrayList();
SqlNode e;
final Span s;
SqlDataTypeSpec dt;
final SqlIntervalQualifier unit;
final SqlNode node;
final SqlLiteral style; // mssql convert 'style' operand
final SqlFunction f;
if (jj_2_775(2)) {
if (jj_2_741(2)) {
jj_consume_token(CAST);
f = SqlStdOperatorTable.CAST;
} else if (jj_2_742(2)) {
jj_consume_token(SAFE_CAST);
f = SqlLibraryOperators.SAFE_CAST;
} else if (jj_2_743(2)) {
jj_consume_token(TRY_CAST);
f = SqlLibraryOperators.TRY_CAST;
} else {
jj_consume_token(-1);
throw new ParseException();
}
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(AS);
if (jj_2_744(2)) {
dt = DataType();
args.add(dt);
} else if (jj_2_745(2)) {
jj_consume_token(INTERVAL);
e = IntervalQualifier();
args.add(e);
} else {
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(RPAREN);
{if (true) return f.createCall(s.end(this), args);}
} else if (jj_2_776(2)) {
jj_consume_token(EXTRACT);
s = span();
jj_consume_token(LPAREN);
unit = TimeUnitOrName();
args.add(unit);
jj_consume_token(FROM);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.EXTRACT.createCall(s.end(this), args);}
} else if (jj_2_777(2)) {
jj_consume_token(POSITION);
s = span();
jj_consume_token(LPAREN);
// FIXME jvs 31-Aug-2006: FRG-192: This should be
// Expression(ExprContext.ACCEPT_SUB_QUERY), but that doesn't work
// because it matches the other kind of IN.
e = AtomicRowExpression();
args.add(e);
jj_consume_token(IN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_746(2)) {
jj_consume_token(FROM);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
} else {
;
}
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.POSITION.createCall(s.end(this), args);}
} else if (jj_2_778(2)) {
jj_consume_token(CONVERT);
s = span();
jj_consume_token(LPAREN);
if (jj_2_754(2)) {
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_747(2)) {
jj_consume_token(USING);
name = SimpleIdentifier();
args.add(name);
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.TRANSLATE.createCall(s.end(this), args);}
} else if (jj_2_748(2)) {
jj_consume_token(COMMA);
e = SimpleIdentifier();
args.add(e);
jj_consume_token(COMMA);
e = SimpleIdentifier();
args.add(e);
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.CONVERT.createCall(s.end(this), args);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else if (jj_2_755(2)) {
if (jj_2_749(2)) {
dt = DataType();
args.add(dt);
} else if (jj_2_750(2)) {
jj_consume_token(INTERVAL);
e = IntervalQualifier();
args.add(e);
} else {
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_753(2)) {
jj_consume_token(COMMA);
if (jj_2_751(2)) {
style = UnsignedNumericLiteral();
args.add(style);
} else if (jj_2_752(2)) {
jj_consume_token(NULL);
args.add(SqlLiteral.createNull(getPos()));
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
jj_consume_token(RPAREN);
{if (true) return SqlLibraryOperators.MSSQL_CONVERT.createCall(s.end(this), args);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else if (jj_2_779(2)) {
jj_consume_token(TRANSLATE);
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_757(2)) {
jj_consume_token(USING);
name = SimpleIdentifier();
args.add(name);
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.TRANSLATE.createCall(s.end(this),
args);}
} else if (jj_2_758(2)) {
label_57:
while (true) {
if (jj_2_756(2)) {
;
} else {
break label_57;
}
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
}
jj_consume_token(RPAREN);
{if (true) return SqlLibraryOperators.TRANSLATE3.createCall(s.end(this),
args);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else if (jj_2_780(2)) {
jj_consume_token(OVERLAY);
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(PLACING);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(FROM);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_759(2)) {
jj_consume_token(FOR);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
} else {
;
}
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.OVERLAY.createCall(s.end(this), args);}
} else if (jj_2_781(2)) {
jj_consume_token(FLOOR);
s = span();
e = FloorCeilOptions(s, true);
{if (true) return e;}
} else if (jj_2_782(2)) {
if (jj_2_760(2)) {
jj_consume_token(CEIL);
} else if (jj_2_761(2)) {
jj_consume_token(CEILING);
} else {
jj_consume_token(-1);
throw new ParseException();
}
s = span();
e = FloorCeilOptions(s, false);
{if (true) return e;}
} else if (jj_2_783(2)) {
jj_consume_token(SUBSTRING);
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_762(2)) {
jj_consume_token(FROM);
} else if (jj_2_763(2)) {
jj_consume_token(COMMA);
} else {
jj_consume_token(-1);
throw new ParseException();
}
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
if (jj_2_766(2)) {
if (jj_2_764(2)) {
jj_consume_token(FOR);
} else if (jj_2_765(2)) {
jj_consume_token(COMMA);
} else {
jj_consume_token(-1);
throw new ParseException();
}
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
} else {
;
}
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.SUBSTRING.createCall(
s.end(this), args);}
} else if (jj_2_784(2)) {
jj_consume_token(TRIM);
SqlLiteral flag = null;
SqlNode trimChars = null;
s = span();
jj_consume_token(LPAREN);
if (jj_2_774(2)) {
if (jj_2_770(2)) {
if (jj_2_767(2)) {
jj_consume_token(BOTH);
s.add(this);
flag = SqlTrimFunction.Flag.BOTH.symbol(getPos());
} else if (jj_2_768(2)) {
jj_consume_token(TRAILING);
s.add(this);
flag = SqlTrimFunction.Flag.TRAILING.symbol(getPos());
} else if (jj_2_769(2)) {
jj_consume_token(LEADING);
s.add(this);
flag = SqlTrimFunction.Flag.LEADING.symbol(getPos());
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
if (jj_2_771(2)) {
trimChars = Expression(ExprContext.ACCEPT_SUB_QUERY);
} else {
;
}
if (jj_2_772(2)) {
jj_consume_token(FROM);
if (null == flag && null == trimChars) {
{if (true) throw SqlUtil.newContextException(getPos(),
RESOURCE.illegalFromEmpty());}
}
} else if (jj_2_773(2)) {
jj_consume_token(RPAREN);
// This is to handle the case of TRIM(x)
// (FRG-191).
if (flag == null) {
flag = SqlTrimFunction.Flag.BOTH.symbol(SqlParserPos.ZERO);
}
args.add(flag);
args.add(null); // no trim chars
args.add(trimChars); // reinterpret trimChars as source
{if (true) return SqlStdOperatorTable.TRIM.createCall(s.end(this),
args);}
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
e = Expression(ExprContext.ACCEPT_SUB_QUERY);
if (flag == null) {
flag = SqlTrimFunction.Flag.BOTH.symbol(SqlParserPos.ZERO);
}
args.add(flag);
args.add(trimChars);
args.add(e);
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.TRIM.createCall(s.end(this), args);}
} else if (jj_2_785(2)) {
node = DateTimeConstructorCall();
{if (true) return node;}
} else if (jj_2_786(2)) {
node = DateDiffFunctionCall();
{if (true) return node;}
} else if (jj_2_787(2)) {
node = DateTruncFunctionCall();
{if (true) return node;}
} else if (jj_2_788(2)) {
node = DatetimeTruncFunctionCall();
{if (true) return node;}
} else if (jj_2_789(2)) {
node = TimestampAddFunctionCall();
{if (true) return node;}
} else if (jj_2_790(2)) {
node = DatetimeDiffFunctionCall();
{if (true) return node;}
} else if (jj_2_791(2)) {
node = TimestampDiffFunctionCall();
{if (true) return node;}
} else if (jj_2_792(2)) {
node = TimestampDiff3FunctionCall();
{if (true) return node;}
} else if (jj_2_793(2)) {
node = TimestampTruncFunctionCall();
{if (true) return node;}
} else if (jj_2_794(2)) {
node = TimeDiffFunctionCall();
{if (true) return node;}
} else if (jj_2_795(2)) {
node = TimeTruncFunctionCall();
{if (true) return node;}
} else if (jj_2_796(2)) {
node = MatchRecognizeFunctionCall();
{if (true) return node;}
} else if (jj_2_797(2)) {
node = JsonExistsFunctionCall();
{if (true) return node;}
} else if (jj_2_798(2)) {
node = JsonValueFunctionCall();
{if (true) return node;}
} else if (jj_2_799(2)) {
node = JsonQueryFunctionCall();
{if (true) return node;}
} else if (jj_2_800(2)) {
node = JsonObjectFunctionCall();
{if (true) return node;}
} else if (jj_2_801(2)) {
node = JsonObjectAggFunctionCall();
{if (true) return node;}
} else if (jj_2_802(2)) {
node = JsonArrayFunctionCall();
{if (true) return node;}
} else if (jj_2_803(2)) {
node = JsonArrayAggFunctionCall();
{if (true) return node;}
} else if (jj_2_804(2)) {
node = GroupByWindowingCall();
{if (true) return node;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public SqlJsonEncoding JsonRepresentation() throws ParseException {
jj_consume_token(JSON);
if (jj_2_808(2)) {
jj_consume_token(ENCODING);
if (jj_2_805(2)) {
jj_consume_token(UTF8);
{if (true) return SqlJsonEncoding.UTF8;}
} else if (jj_2_806(2)) {
jj_consume_token(UTF16);
{if (true) return SqlJsonEncoding.UTF16;}
} else if (jj_2_807(2)) {
jj_consume_token(UTF32);
{if (true) return SqlJsonEncoding.UTF32;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
} else {
;
}
{if (true) return SqlJsonEncoding.UTF8;}
throw new Error("Missing return statement in function");
}
final public void JsonInputClause() throws ParseException {
jj_consume_token(FORMAT);
JsonRepresentation();
}
final public SqlDataTypeSpec JsonReturningClause() throws ParseException {
SqlDataTypeSpec dt;
jj_consume_token(RETURNING);
dt = DataType();
{if (true) return dt;}
throw new Error("Missing return statement in function");
}
final public SqlDataTypeSpec JsonOutputClause() throws ParseException {
SqlDataTypeSpec dataType;
dataType = JsonReturningClause();
if (jj_2_809(2)) {
jj_consume_token(FORMAT);
JsonRepresentation();
} else {
;
}
{if (true) return dataType;}
throw new Error("Missing return statement in function");
}
final public SqlNode JsonPathSpec() throws ParseException {
SqlNode e;
e = StringLiteral();
{if (true) return e;}
throw new Error("Missing return statement in function");
}
final public List JsonApiCommonSyntax() throws ParseException {
SqlNode e;
final List args = new ArrayList();
AddExpression(args, ExprContext.ACCEPT_NON_QUERY);
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_NON_QUERY);
if (jj_2_811(2)) {
jj_consume_token(PASSING);
e = Expression(ExprContext.ACCEPT_NON_QUERY);
jj_consume_token(AS);
e = SimpleIdentifier();
label_58:
while (true) {
if (jj_2_810(2)) {
;
} else {
break label_58;
}
jj_consume_token(COMMA);
e = Expression(ExprContext.ACCEPT_NON_QUERY);
jj_consume_token(AS);
e = SimpleIdentifier();
}
} else {
;
}
{if (true) return args;}
throw new Error("Missing return statement in function");
}
final public SqlJsonExistsErrorBehavior JsonExistsErrorBehavior() throws ParseException {
if (jj_2_812(2)) {
jj_consume_token(TRUE);
{if (true) return SqlJsonExistsErrorBehavior.TRUE;}
} else if (jj_2_813(2)) {
jj_consume_token(FALSE);
{if (true) return SqlJsonExistsErrorBehavior.FALSE;}
} else if (jj_2_814(2)) {
jj_consume_token(UNKNOWN);
{if (true) return SqlJsonExistsErrorBehavior.UNKNOWN;}
} else if (jj_2_815(2)) {
jj_consume_token(ERROR);
{if (true) return SqlJsonExistsErrorBehavior.ERROR;}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public SqlCall JsonExistsFunctionCall() throws ParseException {
List args = new ArrayList();
List commonSyntax;
final Span span;
SqlJsonExistsErrorBehavior errorBehavior;
jj_consume_token(JSON_EXISTS);
span = span();
jj_consume_token(LPAREN);
commonSyntax = JsonApiCommonSyntax();
args.addAll(commonSyntax);
if (jj_2_816(2)) {
errorBehavior = JsonExistsErrorBehavior();
args.add(errorBehavior.symbol(getPos()));
jj_consume_token(ON);
jj_consume_token(ERROR);
} else {
;
}
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.JSON_EXISTS.createCall(span.end(this), args);}
throw new Error("Missing return statement in function");
}
final public List JsonValueEmptyOrErrorBehavior() throws ParseException {
final List list = new ArrayList();
if (jj_2_817(2)) {
jj_consume_token(ERROR);
list.add(SqlJsonValueEmptyOrErrorBehavior.ERROR.symbol(getPos()));
} else if (jj_2_818(2)) {
jj_consume_token(NULL);
list.add(SqlJsonValueEmptyOrErrorBehavior.NULL.symbol(getPos()));
} else if (jj_2_819(2)) {
jj_consume_token(DEFAULT_);
list.add(SqlJsonValueEmptyOrErrorBehavior.DEFAULT.symbol(getPos()));
AddExpression(list, ExprContext.ACCEPT_NON_QUERY);
} else {
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(ON);
if (jj_2_820(2)) {
jj_consume_token(EMPTY);
list.add(SqlJsonEmptyOrError.EMPTY.symbol(getPos()));
} else if (jj_2_821(2)) {
jj_consume_token(ERROR);
list.add(SqlJsonEmptyOrError.ERROR.symbol(getPos()));
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return list;}
throw new Error("Missing return statement in function");
}
final public SqlCall JsonValueFunctionCall() throws ParseException {
final List args = new ArrayList(7);
SqlNode e;
List commonSyntax;
final Span span;
List behavior;
jj_consume_token(JSON_VALUE);
span = span();
jj_consume_token(LPAREN);
commonSyntax = JsonApiCommonSyntax();
args.addAll(commonSyntax);
if (jj_2_822(2)) {
e = JsonReturningClause();
args.add(SqlJsonValueReturning.RETURNING.symbol(getPos()));
args.add(e);
} else {
;
}
label_59:
while (true) {
if (jj_2_823(2)) {
;
} else {
break label_59;
}
behavior = JsonValueEmptyOrErrorBehavior();
args.addAll(behavior);
}
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.JSON_VALUE.createCall(span.end(this), args);}
throw new Error("Missing return statement in function");
}
final public List JsonQueryEmptyOrErrorBehavior() throws ParseException {
final List list = new ArrayList();
if (jj_2_824(2)) {
jj_consume_token(ERROR);
list.add(SqlLiteral.createSymbol(SqlJsonQueryEmptyOrErrorBehavior.ERROR, getPos()));
} else if (jj_2_825(2)) {
jj_consume_token(NULL);
list.add(SqlLiteral.createSymbol(SqlJsonQueryEmptyOrErrorBehavior.NULL, getPos()));
} else if (jj_2_826(2)) {
jj_consume_token(EMPTY);
jj_consume_token(ARRAY);
list.add(SqlLiteral.createSymbol(SqlJsonQueryEmptyOrErrorBehavior.EMPTY_ARRAY, getPos()));
} else if (jj_2_827(2)) {
jj_consume_token(EMPTY);
jj_consume_token(OBJECT);
list.add(SqlLiteral.createSymbol(SqlJsonQueryEmptyOrErrorBehavior.EMPTY_OBJECT, getPos()));
} else {
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(ON);
if (jj_2_828(2)) {
jj_consume_token(EMPTY);
list.add(SqlLiteral.createSymbol(SqlJsonEmptyOrError.EMPTY, getPos()));
} else if (jj_2_829(2)) {
jj_consume_token(ERROR);
list.add(SqlLiteral.createSymbol(SqlJsonEmptyOrError.ERROR, getPos()));
} else {
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return list;}
throw new Error("Missing return statement in function");
}
final public SqlNode JsonQueryWrapperBehavior() throws ParseException {
if (jj_2_834(2)) {
jj_consume_token(WITHOUT);
if (jj_2_830(2)) {
jj_consume_token(ARRAY);
} else {
;
}
{if (true) return SqlLiteral.createSymbol(SqlJsonQueryWrapperBehavior.WITHOUT_ARRAY, getPos());}
} else if (jj_2_835(2)) {
jj_consume_token(WITH);
jj_consume_token(CONDITIONAL);
if (jj_2_831(2)) {
jj_consume_token(ARRAY);
} else {
;
}
{if (true) return SqlLiteral.createSymbol(SqlJsonQueryWrapperBehavior.WITH_CONDITIONAL_ARRAY, getPos());}
} else if (jj_2_836(2)) {
jj_consume_token(WITH);
if (jj_2_832(2)) {
jj_consume_token(UNCONDITIONAL);
} else {
;
}
if (jj_2_833(2)) {
jj_consume_token(ARRAY);
} else {
;
}
{if (true) return SqlLiteral.createSymbol(SqlJsonQueryWrapperBehavior.WITH_UNCONDITIONAL_ARRAY, getPos());}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public SqlCall JsonQueryFunctionCall() throws ParseException {
final SqlNode[] args = new SqlNode[5];
SqlNode e;
List commonSyntax;
final Span span;
List behavior;
jj_consume_token(JSON_QUERY);
span = span();
jj_consume_token(LPAREN);
commonSyntax = JsonApiCommonSyntax();
args[0] = commonSyntax.get(0);
args[1] = commonSyntax.get(1);
if (jj_2_837(2)) {
e = JsonQueryWrapperBehavior();
jj_consume_token(WRAPPER);
args[2] = e;
} else {
;
}
label_60:
while (true) {
if (jj_2_838(2)) {
;
} else {
break label_60;
}
behavior = JsonQueryEmptyOrErrorBehavior();
final SqlJsonEmptyOrError symbol =
((SqlLiteral) behavior.get(1)).getValueAs(SqlJsonEmptyOrError.class);
switch (symbol) {
case EMPTY:
args[3] = behavior.get(0);
break;
case ERROR:
args[4] = behavior.get(0);
break;
}
}
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.JSON_QUERY.createCall(span.end(this), args);}
throw new Error("Missing return statement in function");
}
final public SqlNode JsonName() throws ParseException {
final SqlNode e;
e = Expression(ExprContext.ACCEPT_NON_QUERY);
{if (true) return e;}
throw new Error("Missing return statement in function");
}
final public List JsonNameAndValue() throws ParseException {
final List list = new ArrayList();
final SqlNode e;
boolean kvMode = false;
if (jj_2_839(2)) {
jj_consume_token(KEY);
kvMode = true;
} else {
;
}
e = JsonName();
list.add(e);
if (jj_2_840(2)) {
jj_consume_token(VALUE);
} else if (jj_2_841(2)) {
jj_consume_token(COLON);
if (kvMode) {
{if (true) throw SqlUtil.newContextException(getPos(), RESOURCE.illegalColon());}
}
} else {
jj_consume_token(-1);
throw new ParseException();
}
AddExpression(list, ExprContext.ACCEPT_NON_QUERY);
{if (true) return list;}
throw new Error("Missing return statement in function");
}
final public SqlNode JsonConstructorNullClause() throws ParseException {
if (jj_2_842(2)) {
jj_consume_token(NULL);
jj_consume_token(ON);
jj_consume_token(NULL);
{if (true) return SqlLiteral.createSymbol(SqlJsonConstructorNullClause.NULL_ON_NULL, getPos());}
} else if (jj_2_843(2)) {
jj_consume_token(ABSENT);
jj_consume_token(ON);
jj_consume_token(NULL);
{if (true) return SqlLiteral.createSymbol(SqlJsonConstructorNullClause.ABSENT_ON_NULL, getPos());}
} else {
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
final public SqlCall JsonObjectFunctionCall() throws ParseException {
final List nvArgs = new ArrayList();
final SqlNode[] otherArgs = new SqlNode[1];
SqlNode e;
List list;
final Span span;
jj_consume_token(JSON_OBJECT);
span = span();
jj_consume_token(LPAREN);
if (jj_2_845(2)) {
list = JsonNameAndValue();
nvArgs.addAll(list);
label_61:
while (true) {
if (jj_2_844(2)) {
;
} else {
break label_61;
}
jj_consume_token(COMMA);
list = JsonNameAndValue();
nvArgs.addAll(list);
}
} else {
;
}
if (jj_2_846(2)) {
e = JsonConstructorNullClause();
otherArgs[0] = e;
} else {
;
}
jj_consume_token(RPAREN);
final List args = new ArrayList();
args.addAll(Arrays.asList(otherArgs));
args.addAll(nvArgs);
{if (true) return SqlStdOperatorTable.JSON_OBJECT.createCall(span.end(this), args);}
throw new Error("Missing return statement in function");
}
final public SqlCall JsonObjectAggFunctionCall() throws ParseException {
final SqlNode[] args = new SqlNode[2];
List list;
final Span span;
SqlJsonConstructorNullClause nullClause =
SqlJsonConstructorNullClause.NULL_ON_NULL;
final SqlNode e;
jj_consume_token(JSON_OBJECTAGG);
span = span();
jj_consume_token(LPAREN);
list = JsonNameAndValue();
args[0] = list.get(0);
args[1] = list.get(1);
if (jj_2_847(2)) {
e = JsonConstructorNullClause();
nullClause = (SqlJsonConstructorNullClause) ((SqlLiteral) e).getValue();
} else {
;
}
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.JSON_OBJECTAGG.with(nullClause)
.createCall(span.end(this), args);}
throw new Error("Missing return statement in function");
}
final public SqlCall JsonArrayFunctionCall() throws ParseException {
final List elements = new ArrayList();
final SqlNode[] otherArgs = new SqlNode[1];
SqlNode e;
final Span span;
jj_consume_token(JSON_ARRAY);
span = span();
jj_consume_token(LPAREN);
if (jj_2_849(2)) {
AddExpression(elements, ExprContext.ACCEPT_NON_QUERY);
label_62:
while (true) {
if (jj_2_848(2)) {
;
} else {
break label_62;
}
jj_consume_token(COMMA);
AddExpression(elements, ExprContext.ACCEPT_NON_QUERY);
}
} else {
;
}
if (jj_2_850(2)) {
e = JsonConstructorNullClause();
otherArgs[0] = e;
} else {
;
}
jj_consume_token(RPAREN);
final List args = new ArrayList();
args.addAll(Arrays.asList(otherArgs));
args.addAll(elements);
{if (true) return SqlStdOperatorTable.JSON_ARRAY.createCall(span.end(this), args);}
throw new Error("Missing return statement in function");
}
final public SqlNodeList JsonArrayAggOrderByClause() throws ParseException {
final SqlNodeList orderList;
orderList = OrderBy(true);
{if (true) return orderList;}
throw new Error("Missing return statement in function");
}
final public SqlCall JsonArrayAggFunctionCall() throws ParseException {
final SqlNode valueExpr;
final SqlNodeList orderList;
final Span span;
final SqlJsonConstructorNullClause nullClause;
SqlNode e;
final SqlNode aggCall;
jj_consume_token(JSON_ARRAYAGG);
span = span();
jj_consume_token(LPAREN);
e = Expression(ExprContext.ACCEPT_NON_QUERY);
valueExpr = e;
if (jj_2_851(2)) {
orderList = JsonArrayAggOrderByClause();
} else {
orderList = null;
}
if (jj_2_852(2)) {
e = JsonConstructorNullClause();
nullClause = (SqlJsonConstructorNullClause) ((SqlLiteral) e).getValue();
} else {
nullClause = SqlJsonConstructorNullClause.ABSENT_ON_NULL;
}
jj_consume_token(RPAREN);
aggCall = SqlStdOperatorTable.JSON_ARRAYAGG.with(nullClause)
.createCall(span.end(this), valueExpr, orderList);
if (jj_2_853(2)) {
e = withinGroup(aggCall);
if (orderList != null) {
{if (true) throw SqlUtil.newContextException(span.pos().plus(e.getParserPosition()),
RESOURCE.ambiguousSortOrderInJsonArrayAggFunc());}
}
{if (true) return (SqlCall) e;}
} else {
;
}
if (orderList == null) {
{if (true) return SqlStdOperatorTable.JSON_ARRAYAGG.with(nullClause)
.createCall(span.end(this), valueExpr);}
}
{if (true) return SqlStdOperatorTable.JSON_ARRAYAGG.with(nullClause)
.createCall(span.end(this), valueExpr, orderList);}
throw new Error("Missing return statement in function");
}
/**
* Parses a call to BigQuery's DATE_DIFF.
*/
final public SqlCall DateDiffFunctionCall() throws ParseException {
final List args = new ArrayList();
final Span s;
final SqlIntervalQualifier unit;
jj_consume_token(DATE_DIFF);
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
unit = TimeUnitOrName();
args.add(unit);
jj_consume_token(RPAREN);
{if (true) return SqlLibraryOperators.DATE_DIFF.createCall(s.end(this), args);}
throw new Error("Missing return statement in function");
}
/**
* Parses a call to TIMESTAMPADD.
*/
final public SqlCall TimestampAddFunctionCall() throws ParseException {
final List args = new ArrayList();
final Span s;
final SqlIntervalQualifier unit;
jj_consume_token(TIMESTAMPADD);
s = span();
jj_consume_token(LPAREN);
unit = TimeUnitOrName();
args.add(unit);
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.TIMESTAMP_ADD.createCall(
s.end(this), args);}
throw new Error("Missing return statement in function");
}
/**
* Parses a call to TIMESTAMPDIFF.
*/
final public SqlCall TimestampDiffFunctionCall() throws ParseException {
final List args = new ArrayList();
final Span s;
final SqlIntervalQualifier unit;
jj_consume_token(TIMESTAMPDIFF);
s = span();
jj_consume_token(LPAREN);
unit = TimeUnitOrName();
args.add(unit);
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(RPAREN);
{if (true) return SqlStdOperatorTable.TIMESTAMP_DIFF.createCall(
s.end(this), args);}
throw new Error("Missing return statement in function");
}
/**
* Parses a call to BigQuery's TIMESTAMP_DIFF.
*
* The difference between TIMESTAMPDIFF and TIMESTAMP_DIFF is the ordering of
* the parameters and the arrangement of the subtraction.
* TIMESTAMPDIFF uses (unit, timestamp1, timestamp2) with (t2 - t1), while
* TIMESTAMP_DIFF uses (timestamp1, timestamp2, unit) with (t1 - t2).
*/
final public SqlCall TimestampDiff3FunctionCall() throws ParseException {
final List args = new ArrayList();
final Span s;
final SqlIntervalQualifier unit;
jj_consume_token(TIMESTAMP_DIFF);
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
unit = TimeUnitOrName();
args.add(unit);
jj_consume_token(RPAREN);
{if (true) return SqlLibraryOperators.TIMESTAMP_DIFF3.createCall(s.end(this), args);}
throw new Error("Missing return statement in function");
}
/**
* Parses BigQuery's built-in DATETIME_DIFF() function.
*/
final public SqlCall DatetimeDiffFunctionCall() throws ParseException {
final List args = new ArrayList();
final Span s;
final SqlIntervalQualifier unit;
jj_consume_token(DATETIME_DIFF);
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
unit = TimeUnitOrName();
args.add(unit);
jj_consume_token(RPAREN);
{if (true) return SqlLibraryOperators.DATETIME_DIFF.createCall(s.end(this), args);}
throw new Error("Missing return statement in function");
}
/**
* Parses a call to DATE_TRUNC.
*/
final public SqlCall DateTruncFunctionCall() throws ParseException {
final List args = new ArrayList();
final Span s;
final SqlIntervalQualifier unit;
jj_consume_token(DATE_TRUNC);
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
if (jj_2_854(2)) {
unit = TimeUnit();
args.add(unit);
} else if (jj_2_855(2)) {
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
} else {
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(RPAREN);
{if (true) return SqlLibraryOperators.DATE_TRUNC.createCall(s.end(this), args);}
throw new Error("Missing return statement in function");
}
/**
* Parses a call to TIMESTAMP_TRUNC.
*/
final public SqlCall TimestampTruncFunctionCall() throws ParseException {
final List args = new ArrayList();
final Span s;
final SqlIntervalQualifier unit;
jj_consume_token(TIMESTAMP_TRUNC);
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
unit = TimeUnitOrName();
args.add(unit);
jj_consume_token(RPAREN);
{if (true) return SqlLibraryOperators.TIMESTAMP_TRUNC.createCall(s.end(this), args);}
throw new Error("Missing return statement in function");
}
/**
* Parses a call to BigQuery's TIME_DIFF.
*/
final public SqlCall TimeDiffFunctionCall() throws ParseException {
final List args = new ArrayList();
final Span s;
final SqlIntervalQualifier unit;
jj_consume_token(TIME_DIFF);
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
unit = TimeUnitOrName();
args.add(unit);
jj_consume_token(RPAREN);
{if (true) return SqlLibraryOperators.TIME_DIFF.createCall(s.end(this), args);}
throw new Error("Missing return statement in function");
}
/**
* Parses a call to DATETIME_TRUNC.
*/
final public SqlNode DatetimeTruncFunctionCall() throws ParseException {
final List args = new ArrayList();
final Span s;
final SqlIntervalQualifier unit;
final SqlNode literal;
jj_consume_token(DATETIME_TRUNC);
s = span();
jj_consume_token(LPAREN);
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY);
jj_consume_token(COMMA);
unit = TimeUnitOrName();
args.add(unit);
jj_consume_token(RPAREN);
{if (true) return SqlLibraryOperators.DATETIME_TRUNC.createCall(s.end(this), args);}
throw new Error("Missing return statement in function");
}
/**
* Parses a call to TIME_TRUNC.
*/
final public SqlCall TimeTruncFunctionCall() throws ParseException {
final List args = new ArrayList