use of org.jooq.JSONTableColumnPathStep in project jOOQ by jOOQ.
the class DefaultParseContext method parseTableFactor.
private final Table<?> parseTableFactor(BooleanSupplier forbiddenKeywords) {
// [#7982] Postpone turning Select into a Table in case there is an alias
TableLike<?> result;
// TODO ONLY ( table primary )
if (parseFunctionNameIf("OLD TABLE")) {
parse('(');
Query query = parseQuery(false, false);
parse(')');
if (query instanceof Merge)
result = oldTable((Merge<?>) query);
else if (query instanceof Update)
result = oldTable((Update<?>) query);
else if (query instanceof Delete)
result = oldTable((Delete<?>) query);
else
throw expected("UPDATE", "DELETE", "MERGE");
} else if (parseFunctionNameIf("NEW TABLE")) {
parse('(');
Query query = parseQuery(false, false);
parse(')');
if (query instanceof Merge)
result = newTable((Merge<?>) query);
else if (query instanceof Insert)
result = newTable((Insert<?>) query);
else if (query instanceof Update)
result = newTable((Update<?>) query);
else
throw expected("INSERT", "UPDATE", "MERGE");
} else if (parseFunctionNameIf("FINAL TABLE")) {
parse('(');
Query query = parseQuery(false, false);
parse(')');
if (query instanceof Merge)
result = finalTable((Merge<?>) query);
else if (query instanceof Insert)
result = finalTable((Insert<?>) query);
else if (query instanceof Update)
result = finalTable((Update<?>) query);
else
throw expected("INSERT", "UPDATE", "MERGE");
} else if (parseFunctionNameIf("UNNEST", "TABLE")) {
parse('(');
if (parseFunctionNameIf("GENERATOR")) {
parse('(');
Field<?> tl = parseFunctionArgumentIf("TIMELIMIT");
Field<?> rc = parseFunctionArgumentIf("ROWCOUNT");
if (tl == null)
tl = parseFunctionArgumentIf("TIMELIMIT");
parse(')');
result = generateSeries(one(), (Field<Integer>) rc);
} else {
Field<?> f = parseField();
// Work around a missing feature in unnest()
if (!f.getType().isArray())
f = f.coerce(f.getDataType().getArrayDataType());
result = unnest(f);
}
parse(')');
} else if (parseFunctionNameIf("GENERATE_SERIES", "SYSTEM_RANGE")) {
parse('(');
Field from = toField(parseConcat());
parse(',');
Field to = toField(parseConcat());
Field step = parseIf(',') ? toField(parseConcat()) : null;
parse(')');
result = step == null ? generateSeries(from, to) : generateSeries(from, to, step);
} else if (parseFunctionNameIf("JSON_TABLE")) {
parse('(');
Field json = parseField();
parse(',');
Field path = toField(parseConcat());
JSONTableColumnsStep s1 = (JSONTableColumnsStep) jsonTable(json, path);
parseKeyword("COLUMNS");
parse('(');
do {
Name fieldName = parseIdentifier();
if (parseKeywordIf("FOR ORDINALITY")) {
s1 = s1.column(fieldName).forOrdinality();
} else {
JSONTableColumnPathStep s2 = s1.column(fieldName, parseDataType());
s1 = parseKeywordIf("PATH") ? s2.path(parseStringLiteral()) : s2;
}
} while (parseIf(','));
parse(')');
parse(')');
result = s1;
} else if (peekFunctionNameIf("VALUES")) {
result = parseTableValueConstructor();
} else if (parseFunctionNameIf("XMLTABLE")) {
parse('(');
XMLTablePassingStep s1 = xmltable((Field) toField(parseConcat()));
XMLPassingMechanism m = parseXMLPassingMechanismIf();
Field<XML> passing = m == null ? null : (Field<XML>) parseField();
XMLTableColumnsStep s2 = (XMLTableColumnsStep) (m == BY_REF ? s1.passingByRef(passing) : m == BY_VALUE ? s1.passingByValue(passing) : m == XMLPassingMechanism.DEFAULT ? s1.passing(passing) : s1);
parseKeyword("COLUMNS");
do {
Name fieldName = parseIdentifier();
if (parseKeywordIf("FOR ORDINALITY")) {
s2 = s2.column(fieldName).forOrdinality();
} else {
XMLTableColumnPathStep s3 = s2.column(fieldName, parseDataType());
s2 = parseKeywordIf("PATH") ? s3.path(parseStringLiteral()) : s3;
}
} while (parseIf(','));
parse(')');
result = s2;
} else if (parseIf('(')) {
// - A combination of the above: E.g. ((a join (select 1) on p) right join (((select 1)) union (select 2)) on q)
if (peekKeyword("SELECT", "SEL", "WITH")) {
SelectQueryImpl<Record> select = parseWithOrSelect();
parse(')');
result = parseQueryExpressionBody(null, null, select);
} else if (peekKeyword("VALUES")) {
result = parseTableValueConstructor();
parse(')');
} else {
result = parseJoinedTable(forbiddenKeywords);
parse(')');
}
} else {
result = parseTableName();
// TODO Sample clause
}
if (!ignoreProEdition() && parseKeywordIf("VERSIONS BETWEEN") && requireProEdition()) {
} else if (!ignoreProEdition() && peekKeyword("FOR") && !peekKeyword("FOR JSON") && !peekKeyword("FOR KEY SHARE") && !peekKeyword("FOR NO KEY UPDATE") && !peekKeyword("FOR SHARE") && !peekKeyword("FOR UPDATE") && !peekKeyword("FOR XML") && parseKeyword("FOR") && requireProEdition()) {
} else if (!ignoreProEdition() && parseKeywordIf("AS OF") && requireProEdition()) {
}
if (!ignoreProEdition() && parseKeywordIf("PIVOT") && requireProEdition()) {
}
// TODO UNPIVOT
result = parseCorrelationNameIf(result, forbiddenKeywords);
int p = position();
if (parseKeywordIf("WITH")) {
if (!ignoreProEdition() && parseIf('(') && requireProEdition()) {
} else
// [#10164] Without parens, WITH is part of the next statement in delimiter free statement batches
position(p);
}
return t(result);
}
Aggregations