{"record":{"id":"7c31b7eb0382af70","repo":"apache/seatunnel","slug":"source-already-has-data","errorCode":"SOURCE_ALREADY_HAS_DATA","errorMessage":"The target data source already has data","messagePattern":"The target data source already has data","errorType":"error_code","errorClass":"SeaTunnelRuntimeException","httpStatus":null,"severity":"error","filePath":"seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/DefaultSaveModeHandler.java","lineNumber":163,"sourceCode":"            throw new SeaTunnelRuntimeException(SINK_TABLE_NOT_EXIST, \"The sink table not exist\");\n        }\n    }\n\n    protected void keepSchemaDropData() {\n        if (tableExists() && !isNewTableCreated) {\n            truncateTable();\n        }\n    }\n\n    protected void keepSchemaAndData() {}\n\n    protected void customProcessing() {\n        executeCustomSql();\n    }\n\n    protected void errorWhenDataExists() {\n        if (dataExists()) {\n            throw new SeaTunnelRuntimeException(\n                    SOURCE_ALREADY_HAS_DATA, \"The target data source already has data\");\n        }\n    }\n\n    protected boolean tableExists() {\n        return catalog.tableExists(tablePath);\n    }\n\n    protected void dropTable() {\n        try {\n            log.info(\n                    \"Dropping table {} with action {}\",\n                    tablePath,\n                    catalog.previewAction(\n                            Catalog.ActionType.DROP_TABLE, tablePath, Optional.empty()));\n        } catch (UnsupportedOperationException ignore) {\n            log.info(\"Dropping table {}\", tablePath);\n        }","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/DefaultSaveModeHandler.java#L145-L181","documentation":"DefaultSaveModeHandler.errorWhenDataExists executed during handleDataSaveMode: data_save_mode was set to ERROR_WHEN_DATA_EXISTS and the target data source already contains rows (dataExists() returned true). Error code SOURCE_ALREADY_HAS_DATA — a deliberate guard to prevent overwriting or duplicating existing data, fired from the save-mode phase before the sink writes anything.","triggerScenarios":"Thrown at seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/DefaultSaveModeHandler.java:163 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set data_save_mode to KEEP_SCHEMA_AND_DATA, KEEP_SCHEMA_DROP_DATA, or CUSTOM_PROCESSING depending on whether existing rows should be kept, truncated, or handled by custom SQL","Manually clean or move the existing data if overwrite is intended","Verify the job is not accidentally re-pointing at a table that a previous run already populated"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}