apache/seatunnel · warning

Failed to parse SQL statement

Error message

Failed to parse SQL statement: {}, exception: {}

What it means

ClickhouseUtil.extractTablePathFromSql uses JSqlParser to derive a TablePath from a SQL statement. When the parser cannot parse the SQL (JSQLParserException), it logs this warning and falls back to TablePath.DEFAULT instead of failing. The job continues with a default/unknown table path, which can cause downstream catalog or save-mode behavior to use wrong database/table identifiers.

Solutions

  1. Simplify the SQL to a standard INSERT INTO db.table / SELECT form the parser supports, or specify the table path explicitly via config options so SQL parsing is not needed
  2. Check the logged exception (e.getMessage()) to identify the unsupported syntax and rewrite that clause
  3. If the fallback to TablePath.DEFAULT is unacceptable, upgrade the SeaTunnel/JSqlParser version or set database/table options explicitly instead of relying on SQL parsing

Example fix

// before
sql = "INSERT INTO db.t FINAL SELECT ..."; // JSqlParser may fail
// after
sql = "INSERT INTO db.t SELECT ..."; // or configure table path explicitly
options.put("table_name", "db.t");
Defensive patterns

Strategy: validation

Validate before calling

// Prefer explicit config over SQL parsing
if (config table_path/database+table not set) {
  log.warn("SQL parse fallback active; TablePath.DEFAULT will be used if parsing fails");
}
// Keep SQL simple: INSERT INTO db.table ... / SELECT ... FROM db.table

Type guard

boolean isParseable(String sql) {
  try { new CCJSqlParserUtil.parse(sql); return true; }
  catch (JSQLParserException e) { return false; }
}

Prevention

When it happens

Trigger: Passing a SQL string (e.g. via 'database_name' or save-mode custom SQL) that JSqlParser cannot parse: dialect-specific syntax, CTEs, comments, or non-standard functions unsupported by the bundled JSqlParser version.

Common situations: Users configure ClickHouse-specific SQL (e.g. FINAL, SAMPLE, SETTINGS clauses) in a template; SQL uses backtick-quoted or nested identifiers the parser rejects; version drift between SeaTunnel and its JSqlParser dependency.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/1b8afb3ff1ab8a9e. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/util/ClickhouseUtil.java:127

        SeaTunnelRow seaTunnelRow = new SeaTunnelRow(values);
        seaTunnelRow.setTableId(tableId);
        return seaTunnelRow;
    }

    public static TablePath extractTablePathFromSql(String sql) {
        try {
            Statement statement = CCJSqlParserUtil.parse(sql);

            TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
            Set<String> tableNames = tablesNamesFinder.getTables(statement);
            if (tableNames.size() == 1) {
                String tableFullName = tableNames.iterator().next();
                return TablePath.of(tableFullName);
            }

            return TablePath.DEFAULT;
        } catch (JSQLParserException e) {
            log.warn("Failed to parse SQL statement: {}, exception: {}", sql, e);
            return TablePath.DEFAULT;
        }
    }
}

View on GitHub (pinned to cf67b549a7)