apache/seatunnel · error · JdbcConnectorException
DATA_TYPE_CAST_FAILED
DATA_TYPE_CAST_FAILED
Error message
error field:
What it means
AbstractJdbcRowConverter.toExternal converts a SeaTunnelRow field into a JDBC statement parameter; if the per-field conversion throws for any field, the exception is wrapped in JdbcConnectorException(DATA_TYPE_CAST_FAILED) with the offending field name. It signals that a value in your data cannot be represented as the target SQL type for that column (conversion code threw inside the converter).
Source
Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/converter/AbstractJdbcRowConverter.java:228
int statementIndex = fieldIndex + 1;
String sourceType = null;
if (databaseTableSchema != null && databaseTableSchema.contains(fieldName)) {
sourceType = databaseTableSchema.getColumn(fieldName).getSourceType();
}
Object fieldValue = row.getField(fieldIndex);
if (fieldValue == null) {
setNullToStatementByDataType(
statement, seaTunnelDataType, statementIndex, sourceType);
continue;
}
setValueToStatementByDataType(
row.getField(fieldIndex),
statement,
seaTunnelDataType,
statementIndex,
sourceType);
} catch (Exception e) {
throw new JdbcConnectorException(
JdbcConnectorErrorCode.DATA_TYPE_CAST_FAILED,
"error field:" + rowType.getFieldNames()[fieldIndex],
e);
}
}
return statement;
}
/**
* Bind a null value to the PreparedStatement parameter.
*
* <p>Default implementation uses {@link PreparedStatement#setObject(int, Object)}, which works
* for most databases. However, some databases (e.g., SQL Server) require explicit type
* information for null values in certain column types (e.g., IMAGE, BLOB).
*
* <p>Subclasses can override this method to provide database-specific null handling. For
* example, SQL Server uses {@link PreparedStatement#setNull(int, int)} with the appropriate
* JDBC type (e.g., {@link java.sql.Types#LONGVARBINARY} for IMAGE columns).
*View on GitHub (pinned to cf67b549a7)
Solutions
- Read the message field name and the wrapped cause to identify the offending value and target type
- Align the SeaTunnel source schema with the actual data (correct data types, sizes) before the sink
- Pre-clean/transform the data (e.g. via a Transform) to null-out or coerce invalid values
- Adjust the target column type or converter dialect mapping if the mapping itself is wrong
Example fix
// before
schema: { field { name = "age" type = INT } } // source yields "abc" strings
// after
Transform: filter or Cast age to INT with default, or declare age as STRING and cast in sink target column VARCHAR Defensive patterns
Strategy: try-catch
Validate before calling
Object v = row.getField(idx);
SeaTunnelDataType t = rowType.getFieldType(idx);
if (v == null && !t nullable-allowed) validate per column config;
if (v instanceof String s && t == INT_TYPE && !s.matches("-?\\d+")) fail fast with field name; Try / catch
try {
converter.toExternal(row, statement);
} catch (JdbcConnectorException e) {
if (e.getErrorCode() == JdbcConnectorErrorCode.DATA_TYPE_CAST_FAILED) {
LOG.error("Unconvertible value at field '{}' (row={}); fix schema or clean data", e.getMessage(), row, e.getCause());
}
throw e;
} Prevention
- Validate source data types against the declared SeaTunnel schema at read time
- Add a data-quality Transform step to null/defaults dirty values before the JDBC sink
- Keep BigDecimal scale/precision within the target column limits
- Run a small sample batch through the sink before full production runs
When it happens
Trigger: During toExternal(row, statement) — typically in the JDBC sink write path — a row field's value is incompatible with the mapped target type: e.g. null in a primitive-required column, a string too long / unparseable into a numeric or date type, oversized BigDecimal precision, or a bytes/object mismatch.
Common situations: Source data contains dirty values (empty strings, out-of-range numbers) destined for strict SQL columns; SeaTunnel schema declared as INT but source yields longs/strings; timezone or date-format parse failures; BigDecimal scale exceeding column scale.
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/36da91f39d20dd4a.
Report an issue: GitHub.