Search in sources :

Example 1 with JSONTableColumnsStep

use of org.jooq.JSONTableColumnsStep 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);
}
Also used : Delete(org.jooq.Delete) JSONTableColumnsStep(org.jooq.JSONTableColumnsStep) XMLPassingMechanism(org.jooq.impl.QOM.XMLPassingMechanism) ResultQuery(org.jooq.ResultQuery) Query(org.jooq.Query) DDLQuery(org.jooq.DDLQuery) XMLTableColumnsStep(org.jooq.XMLTableColumnsStep) Update(org.jooq.Update) Insert(org.jooq.Insert) XMLTablePassingStep(org.jooq.XMLTablePassingStep) Constraint(org.jooq.Constraint) DSL.constraint(org.jooq.impl.DSL.constraint) Name(org.jooq.Name) DSL.systemName(org.jooq.impl.DSL.systemName) BigInteger(java.math.BigInteger) GroupField(org.jooq.GroupField) TableField(org.jooq.TableField) Field(org.jooq.Field) SortField(org.jooq.SortField) SelectField(org.jooq.SelectField) Merge(org.jooq.Merge) Record(org.jooq.Record) XMLTableColumnPathStep(org.jooq.XMLTableColumnPathStep) JSONTableColumnPathStep(org.jooq.JSONTableColumnPathStep)

Aggregations

BigInteger (java.math.BigInteger)1 Constraint (org.jooq.Constraint)1 DDLQuery (org.jooq.DDLQuery)1 Delete (org.jooq.Delete)1 Field (org.jooq.Field)1 GroupField (org.jooq.GroupField)1 Insert (org.jooq.Insert)1 JSONTableColumnPathStep (org.jooq.JSONTableColumnPathStep)1 JSONTableColumnsStep (org.jooq.JSONTableColumnsStep)1 Merge (org.jooq.Merge)1 Name (org.jooq.Name)1 Query (org.jooq.Query)1 Record (org.jooq.Record)1 ResultQuery (org.jooq.ResultQuery)1 SelectField (org.jooq.SelectField)1 SortField (org.jooq.SortField)1 TableField (org.jooq.TableField)1 Update (org.jooq.Update)1 XMLTableColumnPathStep (org.jooq.XMLTableColumnPathStep)1 XMLTableColumnsStep (org.jooq.XMLTableColumnsStep)1