{"record":{"id":"cc592c6daebf37c4","repo":"apache/seatunnel","slug":"failed-to-build-the-split-data-read-statement-cc592c","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-mysql/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mysql/utils/MySqlUtils.java","lineNumber":318,"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 SeaTunnelRowType getSplitType(\n            Table table, RelationalDatabaseConnectorConfig dbzConnectorConfig) {\n        List<Column> primaryKeys = table.primaryKeyColumns();\n        if (primaryKeys.isEmpty()) {\n            throw new SeaTunnelException(\n                    String.format(\n                            \"Incremental snapshot for tables requires primary key,\"\n                                    + \" but table %s doesn't have primary key.\",\n                            table.id()));\n        }\n\n        // use first field in primary key as the split key\n        return getSplitType(primaryKeys.get(0), dbzConnectorConfig);\n    }\n","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mysql/utils/MySqlUtils.java#L300-L336","documentation":"MySqlUtils.readTableSplitDataStatement builds the JDBC PreparedStatement that reads one snapshot chunk (with start/end key parameters) and wraps any Exception during statement construction into a RuntimeException with this message. It throws when bind parameters, SQL text, or driver interaction fail while assembling the chunk-read statement, with the original exception as the cause.","triggerScenarios":"Calling readTableSplitDataStatement when setObject binding fails for the split-key values (e.g. value type unsupported by the driver), the split key array is null/shorter than the primary key count, or the SQL string is malformed after quoting.","commonSituations":"Exotic primary-key column types (e.g. unsigned bigint, spatial) whose values the driver can't bind via setObject; primary key columns removed by concurrent DDL so splitEnd arrays mismatch; corrupted split metadata from a prior planning bug.","solutions":["Read the cause of the RuntimeException to see which bind/type failed and check the primary key column types","Avoid unsupported/exotic PK column types, or add the table's primary key as a supported type (e.g. convert unsigned bigint handling)","Re-run the snapshot so splits are re-planned against the current table schema","Verify the table schema did not change (PK dropped/altered) between planning and reading"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// confirm PK column types are driver-bindable before snapshot\nResultSet rs = st.executeQuery(\n    \"SELECT data_type FROM information_schema.columns \" +\n    \"WHERE table_schema=DATABASE() AND table_name='t' AND column_key='PRI'\");","typeGuard":null,"tryCatchPattern":"try {\n    PreparedStatement ps = MySqlUtils.readTableSplitDataStatement(jdbc, query, splitStart, splitEnd, pkNum);\n} catch (RuntimeException e) {\n    // inspect e.getCause() for the bind failure\n}","preventionTips":["Use standard PK column types (INT/BIGINT/VARCHAR)","Avoid schema changes to PK columns mid-snapshot","Re-plan splits if the table schema changed","Inspect the cause chain when this RuntimeException fires"],"tags":["mysql","cdc","jdbc","statement","chunk-splitting"],"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"}