apache/seatunnel · error · SeaTunnelRuntimeException

SOURCE_ALREADY_HAS_DATA

SOURCE_ALREADY_HAS_DATA

Error message

The target data source already has data

What it means

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.

Solutions

  1. 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
  2. Manually clean or move the existing data if overwrite is intended
  3. Verify the job is not accidentally re-pointing at a table that a previous run already populated
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/DefaultSaveModeHandler.java:163 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/7c31b7eb0382af70. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/DefaultSaveModeHandler.java:163

            throw new SeaTunnelRuntimeException(SINK_TABLE_NOT_EXIST, "The sink table not exist");
        }
    }

    protected void keepSchemaDropData() {
        if (tableExists() && !isNewTableCreated) {
            truncateTable();
        }
    }

    protected void keepSchemaAndData() {}

    protected void customProcessing() {
        executeCustomSql();
    }

    protected void errorWhenDataExists() {
        if (dataExists()) {
            throw new SeaTunnelRuntimeException(
                    SOURCE_ALREADY_HAS_DATA, "The target data source already has data");
        }
    }

    protected boolean tableExists() {
        return catalog.tableExists(tablePath);
    }

    protected void dropTable() {
        try {
            log.info(
                    "Dropping table {} with action {}",
                    tablePath,
                    catalog.previewAction(
                            Catalog.ActionType.DROP_TABLE, tablePath, Optional.empty()));
        } catch (UnsupportedOperationException ignore) {
            log.info("Dropping table {}", tablePath);
        }

View on GitHub (pinned to cf67b549a7)