{"record":{"id":"d2788e701dec5855","repo":"apache/seatunnel","slug":"failed-to-build-the-split-data-read-statement","errorCode":null,"errorMessage":"Failed to build the split data read statement.","messagePattern":"Failed to build the split data read statement\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-cdc/connector-cdc-db2/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/db2/utils/Db2Utils.java","lineNumber":322,"sourceCode":"            if (isFirstSplit) {\n                for (int i = 0; i < primaryKeyNum; i++) {\n                    statement.setObject(i + 1, splitEnd[i]);\n                    statement.setObject(i + 1 + primaryKeyNum, splitEnd[i]);\n                }\n            } else if (isLastSplit) {\n                for (int i = 0; i < primaryKeyNum; i++) {\n                    statement.setObject(i + 1, splitStart[i]);\n                }\n            } else {\n                for (int i = 0; i < primaryKeyNum; i++) {\n                    statement.setObject(i + 1, splitStart[i]);\n                    statement.setObject(i + 1 + primaryKeyNum, splitEnd[i]);\n                    statement.setObject(i + 1 + 2 * primaryKeyNum, splitEnd[i]);\n                }\n            }\n            return statement;\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to build the split data read statement.\", e);\n        }\n    }\n\n    public static Db2DatabaseSchema createDb2DatabaseSchema(\n            Db2ConnectorConfig connectorConfig, Db2Connection connection) {\n        TopicSelector<TableId> topicSelector = Db2TopicSelector.defaultSelector(connectorConfig);\n        SchemaNameAdjuster schemaNameAdjuster = SchemaNameAdjuster.create();\n        return new Db2DatabaseSchema(\n                connectorConfig, schemaNameAdjuster, topicSelector, connection);\n    }\n\n    private static String getPrimaryKeyColumnsProjection(SeaTunnelRowType rowType) {\n        StringBuilder sql = new StringBuilder();\n        for (Iterator<String> fieldNamesIt = Arrays.stream(rowType.getFieldNames()).iterator();\n                fieldNamesIt.hasNext(); ) {\n            sql.append(quote(fieldNamesIt.next()));\n            if (fieldNamesIt.hasNext()) {\n                sql.append(\" , \");","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-cdc/connector-cdc-db2/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/db2/utils/Db2Utils.java#L304-L340","documentation":"readTableSplitDataStatement builds a PreparedStatement for reading a split's data using chunk bounds. Any exception during construction (bad parameter types, null split bounds, wrong column count) is rethrown as RuntimeException('Failed to build the split data read statement.') with the original cause attached.","triggerScenarios":"statement.setObject with values incompatible with the split column types, null split start/end arrays, or a mismatch between the split's row type and the number of primary-key columns when binding chunk-bound parameters.","commonSituations":"Unsupported primary-key column types (e.g. binary/LOB keys) in the chunk bounds; schema drift between snapshot planning and reading; corrupt split metadata after checkpoint restore.","solutions":["Read the wrapped cause ('Caused by') for the actual failure","Avoid LOB/BLOB/unsupported types as primary keys for incremental snapshot","Re-run the job to rebuild split metadata if it was corrupted","Verify the table schema hasn't changed mid-snapshot (column type changes)","Use a supported PK type (integer, string, timestamp) for chunk splitting"],"exampleFix":"// before: LOB primary key\nCREATE TABLE t (payload CLOB PRIMARY KEY ...);\n// after: integer surrogate key\nCREATE TABLE t (id INT PRIMARY KEY, payload CLOB ...);","handlingStrategy":"try-catch","validationCode":"// Pre-check split bound types are JDBC-bindable\nfor (Object v : splitStart) { if (v == null || v instanceof byte[] || v instanceof java.sql.Blob) throw new IllegalStateException(\"Unsupported PK bound type: \" + v.getClass()); }","typeGuard":null,"tryCatchPattern":"try { PreparedStatement ps = Db2Utils.readTableSplitDataStatement(...); } catch (RuntimeException e) { if (\"Failed to build the split data read statement.\".equals(e.getMessage())) { log.error(\"statement build failed\", e.getCause()); } throw e; }","preventionTips":["Use simple scalar types (int/bigint/varchar/timestamp) as primary keys","Avoid schema changes during snapshot","Inspect the cause chain for the real bind error"],"tags":["db2","cdc","statement","type-mismatch"],"backgroundTag":"type-mismatch","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"}