Skip to content

[BUG] JSQLParser 5.4 / 5.5-SNAPSHOT: single-field ROW casts throw NPE when deparsed #2756

Description

@PHJ2000

Failing SQL Feature

A cast to a named ROW with one field parses successfully, but both Statement.toString() and StatementDeParser throw NullPointerException. This prevents applications from serializing or rewriting the parsed query.

SQL Example

SELECT CAST(ROW(1) AS ROW(x BIGINT))

Minimal Java reproduction (run each serialization call separately):

Statement statement = CCJSqlParserUtil.parse(
        "SELECT CAST(ROW(1) AS ROW(x BIGINT))");
System.out.println(statement.toString());

StringBuilder output = new StringBuilder();
statement.accept(new StatementDeParser(output));

Expected: both paths preserve the query, including ROW(x BIGINT).

Actual: the first throws from CastExpression.toString(), and the second throws from ExpressionDeParser.visit(CastExpression, ...), because colDataType is null. The parser correctly stores the target in a one-element columnDefinitions list, but both serializers require its size to be greater than one before rendering it as a row type.

Software Information

  • Reproduced with the Maven Central com.github.jsqlparser:jsqlparser:5.4 artifact.
  • Also reproduced on current master 26d3e02a78e061f5fecf2eb2e783bf0482e10840 (5.5-SNAPSHOT).
  • Java 21.
  • SQL dialect: Trino. Its ROW documentation describes named row fields; the type grammar permits one field: ROW '(' rowField (',' rowField)* ')'.

The online formatter also returns -- failed to format start around this query.

The earlier #1267 / #1274 added support for casting to multi-field row types. This report concerns the remaining single-field serialization case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions