{"record":{"id":"1d4bfbe8a27e3f99","repo":"apache/seatunnel","slug":"failed-to-execute-query-s","errorCode":null,"errorMessage":"Failed to execute query: %s","messagePattern":"Failed to execute query: (.+?)","errorType":"exception","errorClass":"ClickhouseConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/source/ClickhouseValueReader.java","lineNumber":478,"sourceCode":"                                                                                .convertToSeaTunnelRow(\n                                                                                        record,\n                                                                                        rowTypeInfo,\n                                                                                        clickhouseSourceTable\n                                                                                                .getTablePath()\n                                                                                                .getFullName());\n                                                                try {\n                                                                    rowQueue.put(seaTunnelRow);\n                                                                } catch (InterruptedException e) {\n                                                                    throw new ClickhouseConnectorException(\n                                                                            ClickhouseConnectorErrorCode\n                                                                                    .ROW_BATCH_GET_FAILED,\n                                                                            e);\n                                                                }\n                                                            });\n                                        }\n                                    }\n                                } catch (ClickHouseException e) {\n                                    throw new ClickhouseConnectorException(\n                                            ClickhouseConnectorErrorCode.QUERY_DATA_ERROR,\n                                            String.format(\n                                                    \"Failed to execute query: %s\", executeSql),\n                                            e);\n                                } finally {\n                                    eos.set(true);\n                                    log.info(\"StreamValueReader finished reading data\");\n                                }\n                            }\n                        },\n                        \"clickhouse-stream-reader-\" + clickhouseSourceSplit.getSplitId());\n\n        public boolean hasNext() {\n            List<SeaTunnelRow> rows = new ArrayList<>();\n            while (!eos.get() || !rowQueue.isEmpty()) {\n                if (!rowQueue.isEmpty()) {\n                    try {\n                        SeaTunnelRow seaTunnelRow = rowQueue.take();","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/source/ClickhouseValueReader.java#L460-L496","documentation":"Thrown by ClickhouseValueReader.run() when ClickHouse's JDBC driver raises a ClickHouseException while executing the streaming read SQL (executeSql). The connector wraps it in a ClickhouseConnectorException with QUERY_DATA_ERROR and the message 'Failed to execute query: %s' plus the original exception. It means the query driving the whole-part/streamed read failed at execution time on the server or connection.","triggerScenarios":"executeSql sent via the ClickHouse JDBC client during run() returns a ClickHouseException: server-side query error (syntax, missing table, permissions, memory limit), connection reset, or query killed due to timeout/max_execution_time.","commonSituations":"Table or database renamed/dropped before the job ran; ClickHouse user lacking grants; query hitting memory/max_execution_time limits on large tables; shard host down or DNS failure; ClickHouse server version rejecting the generated SQL.","solutions":["Read the wrapped ClickHouseException cause for the exact server error code and message, then fix that (e.g., grant SELECT, restore table, raise memory limits)","Run the executeSql shown in the error manually with clickhouse-client to reproduce and see the server-side error","Verify connectivity/auth to the shard host and that the tablePath resolves to an existing table","Tune query limits (max_execution_time, max_memory_usage) or reduce read scope if the query was killed for resource limits"],"exampleFix":"// before (no limit, killed on large table)\nString executeSql = \"SELECT * FROM \" + tablePath.getFullName();\n// after\nString executeSql = \"SELECT * FROM \" + tablePath.getFullName() + \" SETTINGS max_execution_time = 600, max_memory_usage = 10000000000\";","handlingStrategy":"try-catch","validationCode":"// Validate connectivity, auth, and table existence before the job\ntry (Connection c = DriverManager.getConnection(jdbcUrl, user, pass)) {\n    ResultSet rs = c.createStatement().executeQuery(\n        \"EXISTS TABLE \" + tablePath.getFullName());\n    rs.next();\n    if (rs.getInt(1) != 1) throw new IllegalStateException(\"Table missing: \" + tablePath.getFullName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    reader.run();\n} catch (ClickhouseConnectorException e) {\n    if (e.getErrorCode() == ClickhouseConnectorErrorCode.QUERY_DATA_ERROR\n        && e.getMessage().startsWith(\"Failed to execute query:\")) {\n        Throwable cause = e.getCause(); // ClickHouseException with server error code\n        // inspect cause.getErrorCode() and retry transient codes with backoff\n    }\n    throw e;\n}","preventionTips":["Check the wrapped ClickHouseException's error code to distinguish transient (network/timeout) from permanent (syntax/permissions) failures","Verify the table exists and the user has grants before submitting the job","Set max_execution_time/max_memory_usage in the query or server profile for large reads","Keep ClickHouse JDBC driver and server versions compatible"],"tags":["clickhouse","sql","query","jdbc"],"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-14T11:17:12.474Z"}