{"record":{"id":"ad66a0dd6a770a07","repo":"apache/seatunnel","slug":"failed-to-read-data-from-sql-s-shard-s-spliti","errorCode":null,"errorMessage":"Failed to read data from sql %s, shard: %s, splitId %s, message: %s","messagePattern":"Failed to read data from sql (.+?), shard: (.+?), splitId (.+?), message: (.+?)","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":197,"sourceCode":"                            query, clickhouseSourceTable.getTablePath(), rowTypeInfo);\n\n            String sortingKey = clickhouseSourceTable.getClickhouseTable().getSortingKey();\n\n            if (rowBatch.isEmpty()) {\n                return false;\n            }\n            SeaTunnelRow lastRow = rowBatch.get(rowBatch.size() - 1);\n\n            sqlLastOrderingKeyValues = extractOrderingKeyValuesFromRow(lastRow, sortingKey);\n\n            log.debug(\n                    \"lastRow: {}, extract ordering key values from row: {}\",\n                    lastRow,\n                    sqlLastOrderingKeyValues);\n\n            return !rowBatch.isEmpty();\n        } catch (Exception e) {\n            throw new ClickhouseConnectorException(\n                    ClickhouseConnectorErrorCode.QUERY_DATA_ERROR,\n                    String.format(\n                            \"Failed to read data from sql %s, shard: %s, splitId %s, message: %s\",\n                            query,\n                            clickhouseSourceSplit.getShard().getNode(),\n                            clickhouseSourceSplit.getSplitId(),\n                            e.getMessage()),\n                    e);\n        }\n    }\n\n    public void close() {\n        if (proxy != null) {\n            proxy.close();\n        }\n        if (streamValueReader != null) {\n            streamValueReader.close();\n        }","sourceCodeStart":179,"sourceCodeEnd":215,"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#L179-L215","documentation":"Thrown by ClickhouseValueReader.sqlBatchStrategyRead() when the SQL-based batch read fails with any Exception. The connector wraps the root cause in a ClickhouseConnectorException with QUERY_DATA_ERROR, including the executed query, shard node, split id, and underlying message. It indicates the per-batch SQL query (often a paged query using the last ordering key) could not be executed or its results consumed.","triggerScenarios":"sqlBatchStrategyRead() runs the split's query (with ORDER BY / WHERE paging on ordering keys) and the JDBC execution or row/ordering-key extraction throws: bad SQL, connection drop, type mapping failure, or missing ordering-key column in the result.","commonSituations":"Query references a column dropped/renamed by a schema change; shard unavailable mid-job; ORDER BY key mismatch after table engine change; timeouts on very large batches; ClickHouse version differences in SQL support.","solutions":["Copy the query from the error message and run it manually against the shard node to see the real server error","Verify the ordering key columns still exist and match the configured ordering key in the source config","Retry the job with checkpointing enabled to recover from transient shard/network failures","Reduce batch size / add query timeout settings if the failure is timeout-related on large reads"],"exampleFix":"// before\nselect * from my_table;\n// after\nselect col1, col2 from my_table; -- explicit columns matching schema and ordering key\n// validate manually: clickhouse-client --host <shard> -q \"<query from error message>\"","handlingStrategy":"retry","validationCode":"// Validate the split query against the shard before the job\ntry (Connection c = DriverManager.getConnection(jdbcUrl, user, pass)) {\n    c.createStatement().executeQuery(\"SELECT 1 FROM \" + table + \" LIMIT 1\");\n    // also confirm ordering key columns exist:\n    c.createStatement().executeQuery(\n        \"SELECT name FROM system.columns WHERE database='\" + db + \"' AND table='\" + table + \"'\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    hasMore = reader.hasNext();\n} catch (ClickhouseConnectorException e) {\n    if (e.getErrorCode() == ClickhouseConnectorErrorCode.QUERY_DATA_ERROR\n        && e.getMessage().startsWith(\"Failed to read data from sql\")) {\n        // log full query from message; retry split after backoff or fail job with context\n    }\n    throw e;\n}","preventionTips":["Validate schema and ordering-key columns exist before the run; lock schema during the job","Test the generated SQL manually against the target shard","Enable checkpointing for automatic split re-reads after transient failures","Keep batch sizes moderate to avoid timeouts on wide tables"],"tags":["clickhouse","sql","query","source-reader"],"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-14T05:17:10.506Z"}