{"record":{"id":"e794735deb22ee9e","repo":"apache/seatunnel","slug":"query-data-error","errorCode":"QUERY_DATA_ERROR","errorMessage":"Query data with sql error. sql: %s, message: %s","messagePattern":"Query data with sql error\\. sql: (.+?), message: (.+?)","errorType":"error_code","errorClass":"ClickhouseConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/util/ClickhouseProxy.java","lineNumber":493,"sourceCode":"        }\n    }\n\n    public List<SeaTunnelRow> batchFetchRecords(\n            String sql, TablePath tablePath, SeaTunnelRowType seaTunnelRowType) {\n        List<SeaTunnelRow> seaTunnelRowList = new ArrayList<>();\n        log.debug(\"run query data sql: {}\", sql);\n\n        try (ClickHouseResponse response = clickhouseRequest.query(sql).executeAndWait()) {\n            response.stream()\n                    .forEach(\n                            record -> {\n                                SeaTunnelRow seaTunnelRow =\n                                        ClickhouseUtil.convertToSeaTunnelRow(\n                                                record, seaTunnelRowType, tablePath.getFullName());\n                                seaTunnelRowList.add(seaTunnelRow);\n                            });\n        } catch (ClickHouseException e) {\n            throw new ClickhouseConnectorException(\n                    ClickhouseConnectorErrorCode.QUERY_DATA_ERROR,\n                    String.format(\n                            \"Query data with sql error. sql: %s, message: %s\", sql, e.getMessage()),\n                    e);\n        }\n\n        return seaTunnelRowList;\n    }\n\n    public boolean isComplexSql(String sql) {\n        try {\n            String explainSql = \"EXPLAIN \" + sql;\n\n            try (ClickHouseResponse response =\n                    getClickhouseConnection().query(explainSql).executeAndWait()) {\n                List<String> explainOutput =\n                        response.stream()\n                                .map(record -> record.getValue(0).asString())","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/util/ClickhouseProxy.java#L475-L511","documentation":"ClickhouseProxy.batchFetchRecords executes a data query (used by rows()) and wraps ClickHouseException from the SELECT into QUERY_DATA_ERROR, including the SQL and the ClickHouse message. It indicates the data-reading query itself failed — bad SQL, type conversion problems, or a server error mid-read.","triggerScenarios":"Calling batchFetchRecords / rows() when the generated SELECT fails: schema mismatch between configured SeaTunnelRowType and actual table columns, invalid WHERE/filter expression, query timeout, or ClickHouse node failure during fetch.","commonSituations":"Configured columns don't match the real ClickHouse table (renamed/dropped columns); unsupported filter pushdown producing invalid SQL; querying a Distributed table whose underlying shard is down; version-specific clickhouse-client incompatibilities.","solutions":["Read the embedded ClickHouse message in the error (the SQL and server reason are printed) and fix the query cause — usually a column/schema mismatch.","Verify the connector's schema (table_path and columns) exactly matches `DESCRIBE TABLE` output.","Reproduce the SQL from the message in clickhouse-client to confirm the error is server-side, then adjust filters or table.","Increase query timeouts / check replica health if the failure is a timeout or dropped connection during large reads."],"exampleFix":"// before\nsource {\n  Clickhouse {\n    table_path = \"db.events\"\n    # schema lists column \"user_id\" but table has \"uid\"\n  }\n}\n// after\nsource {\n  Clickhouse {\n    table_path = \"db.events\"\n    schema = { columns = { uid = \"string\" } }\n  }\n}","handlingStrategy":"validation","validationCode":"// validate configured columns against the live table before the read\nString desc = \"DESCRIBE TABLE \" + tablePath.getFullName();\nSet<String> actual = runQuery(desc).stream().map(r -> r[0]).collect(toSet());\nconfiguredColumns.forEach(c -> {\n    if (!actual.contains(c)) throw new IllegalArgumentException(\"column mismatch: \" + c);\n});","typeGuard":null,"tryCatchPattern":"try {\n    rows = proxy.rows(tablePath, rowType, ...);\n} catch (ClickhouseConnectorException e) {\n    LOG.error(\"data query failed: {}\", e.getMessage()); // message already contains SQL + server reason\n    throw e;\n}","preventionTips":["Keep the connector schema in sync with the real table; re-run schema inference after DDL changes.","Test pushed-down filters manually in clickhouse-client first.","Check replica health for Distributed tables before large reads.","Set realistic query timeouts for the data volume being read."],"tags":["clickhouse","query-failed","sql","data-read"],"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"}