{"record":{"id":"1b8afb3ff1ab8a9e","repo":"apache/seatunnel","slug":"failed-to-parse-sql-statement-exception","errorCode":null,"errorMessage":"Failed to parse SQL statement: {}, exception: {}","messagePattern":"Failed to parse SQL statement: (.+?), exception: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/util/ClickhouseUtil.java","lineNumber":127,"sourceCode":"        SeaTunnelRow seaTunnelRow = new SeaTunnelRow(values);\n        seaTunnelRow.setTableId(tableId);\n        return seaTunnelRow;\n    }\n\n    public static TablePath extractTablePathFromSql(String sql) {\n        try {\n            Statement statement = CCJSqlParserUtil.parse(sql);\n\n            TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();\n            Set<String> tableNames = tablesNamesFinder.getTables(statement);\n            if (tableNames.size() == 1) {\n                String tableFullName = tableNames.iterator().next();\n                return TablePath.of(tableFullName);\n            }\n\n            return TablePath.DEFAULT;\n        } catch (JSQLParserException e) {\n            log.warn(\"Failed to parse SQL statement: {}, exception: {}\", sql, e);\n            return TablePath.DEFAULT;\n        }\n    }\n}\n","sourceCodeStart":109,"sourceCodeEnd":132,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/util/ClickhouseUtil.java#L109-L132","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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","Check the logged exception (e.getMessage()) to identify the unsupported syntax and rewrite that clause","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"],"exampleFix":"// before\nsql = \"INSERT INTO db.t FINAL SELECT ...\"; // JSqlParser may fail\n// after\nsql = \"INSERT INTO db.t SELECT ...\"; // or configure table path explicitly\noptions.put(\"table_name\", \"db.t\");","handlingStrategy":"validation","validationCode":"// Prefer explicit config over SQL parsing\nif (config table_path/database+table not set) {\n  log.warn(\"SQL parse fallback active; TablePath.DEFAULT will be used if parsing fails\");\n}\n// Keep SQL simple: INSERT INTO db.table ... / SELECT ... FROM db.table","typeGuard":"boolean isParseable(String sql) {\n  try { new CCJSqlParserUtil.parse(sql); return true; }\n  catch (JSQLParserException e) { return false; }\n}","tryCatchPattern":null,"preventionTips":["Always set database/table options explicitly instead of relying on SQL extraction","Avoid dialect-specific clauses (FINAL, SETTINGS, SAMPLE) in templates used for table-path extraction","Check logs for this warning right after job start to catch parse failures early"],"tags":["sql","clickhouse","sql-parsing"],"backgroundTag":"sql-query-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}