apache/seatunnel · error · JdbcConnectorException

JdbcConnectorErrorCode.DATA_TYPE_CAST_FAILED

JdbcConnectorErrorCode.DATA_TYPE_CAST_FAILED

Error message

error field:${fieldName}

What it means

In PostgresJdbcRowConverter.toExternal, any Exception thrown while binding a field's value into the PreparedStatement is rethrown as JdbcConnectorException with code DATA_TYPE_CAST_FAILED and message 'error field:<fieldName>', preserving the cause. It identifies which schema field failed the JDBC type conversion.

Source

Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresJdbcRowConverter.java:338

                        if (SqlType.TINYINT.equals(elementType.getSqlType())) {
                            Short[] shortArray = new Short[array.length];
                            for (int i = 0; i < array.length; i++) {
                                shortArray[i] = Short.valueOf(array[i].toString());
                            }
                            statement.setObject(statementIndex, shortArray);
                        } else {
                            statement.setObject(statementIndex, array);
                        }
                        break;
                    case MAP:
                    case ROW:
                    default:
                        throw new JdbcConnectorException(
                                CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE,
                                "Unexpected value: " + seaTunnelDataType);
                }
            } catch (Exception e) {
                throw new JdbcConnectorException(
                        JdbcConnectorErrorCode.DATA_TYPE_CAST_FAILED,
                        "error field:" + rowType.getFieldNames()[fieldIndex],
                        e);
            }
        }
        return statement;
    }

    @Nullable private String resolveSourceType(
            SeaTunnelRowType rowType,
            int fieldIndex,
            @Nullable TableSchema databaseTableSchema,
            String[] sourceTypes) {
        if (databaseTableSchema != null) {
            String fieldName = rowType.getFieldName(fieldIndex);
            if (databaseTableSchema.contains(fieldName)) {
                return databaseTableSchema.getColumn(fieldName).getSourceType();
            }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Inspect the wrapped cause ('Caused by') to find the actual conversion failure
  2. Fix the data: ensure values match the declared column type/range (e.g. valid dates, numerics within precision)
  3. Adjust the SeaTunnel schema type to match the actual data, or cast values upstream before the sink

Example fix

// before
field(birthday, STRING_TYPE) // value "31/02/2020" to DATE column
// after
field(birthday, DATE_TYPE) // and clean invalid date strings upstream
Defensive patterns

Strategy: try-catch

Try / catch

try {
    converter.toExternal(row, statement);
} catch (JdbcConnectorException e) {
    if (e.getCode().equals(JdbcConnectorErrorCode.DATA_TYPE_CAST_FAILED)) {
        log.error("field '{}' failed conversion", e.getMessage(), e.getCause());
    }
}

Prevention

When it happens

Trigger: Any exception inside the per-field binding block of toExternal - e.g. casting a value to the target JDBC type, setObject failures, array serialization errors, or type-conversion exceptions from the driver.

Common situations: Data values that don't fit the declared column (overflowing numeric, wrong string format for date/timestamp), nulls in unsupported positions, driver-side conversion failures on unusual values.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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