apache/seatunnel · error · IllegalArgumentException
Value is not a BSON date or timestamp
Error message
Value is not a BSON date or timestamp
What it means
DocumentDBItemDeserializer.convertDateTime expects a BSON value of type DateTime or Timestamp to produce a LocalDateTime. If the BSON value is any other type (string, int32, null, etc.) it throws this IllegalArgumentException, because SeaTunnel's timestamp column requires an actual BSON date/timestamp value.
Source
Thrown at seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/serialize/DocumentDBItemDeserializer.java:197
return value.asString().getValue();
}
if (value.isObjectId()) {
return value.asObjectId().getValue().toHexString();
}
if (value.isDocument()) {
return value.asDocument().toJson(RELAXED_JSON_SETTINGS);
}
return value.toString();
}
private static LocalDateTime convertDateTime(BsonValue value) {
Instant instant;
if (value.isDateTime()) {
instant = Instant.ofEpochMilli(value.asDateTime().getValue());
} else if (value.isTimestamp()) {
instant = Instant.ofEpochSecond(value.asTimestamp().getTime());
} else {
throw new IllegalArgumentException("Value is not a BSON date or timestamp");
}
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
}
/** Converts array elements recursively so nested rows, maps, and arrays use the same rules. */
private Object convertArray(String field, ArrayType<?, ?> type, BsonValue value) {
List<BsonValue> source = value.asArray();
Object target = Array.newInstance(type.getElementType().getTypeClass(), source.size());
for (int i = 0; i < source.size(); i++) {
Array.set(target, i, convert(field, type.getElementType(), source.get(i)));
}
return target;
}
/** Converts BSON documents to maps; BSON field names require a string map key type. */
private Map<String, Object> convertMap(String field, MapType<?, ?> type, BsonValue value) {
if (type.getKeyType().getSqlType() != SqlType.STRING) {
throw conversionError(field, type);View on GitHub (pinned to cf67b549a7)
Solutions
- Fix the data in DocumentDB to store the value as a BSON Date ($toDate in an update pipeline).
- Change the SeaTunnel schema column to STRING if the source stores date strings, then transform/parse downstream.
- Add a transform (e.g. with a custom deserializer or Transform) that parses string dates into timestamps before this converter runs.
Example fix
// before: document stores {"ts": "2024-01-01T00:00:00Z"} mapped to TIMESTAMP
// after: convert in MongoDB/DocumentDB
db.coll.updateMany({}, [{ $set: { ts: { $toDate: "$ts" } } }]) Defensive patterns
Strategy: type-guard
Validate before calling
if (!(bsonValue.isDateTime() || bsonValue.isTimestamp())) {
throw new IllegalArgumentException("Field must be BSON Date or Timestamp, got: " + bsonValue.getBsonType());
} Type guard
boolean isBsonDateLike(BsonValue v) { return v != null && (v.isDateTime() || v.isTimestamp()); } Try / catch
try { value = convertDateTime(field, type, bsonValue); } catch (IllegalArgumentException e) { log.warn("Non-date value for {}: {}", field, bsonValue); handleNull(); } Prevention
- Ensure all writers store BSON Dates (ISODate), not ISO strings or epoch ints.
- Run $type checks: db.coll.find({ ts: { $type: { $nin: ['date','timestamp'] } } }).
- Map string date columns to STRING in the schema and parse in a transform.
When it happens
Trigger: A document field declared as TIMESTAMP in the SeaTunnel schema contains a BSON string (e.g. "2024-01-01T00:00:00Z") or numeric value instead of a BSON Date (ISODate) or BSON Timestamp.
Common situations: Documents written by different applications with inconsistent typing; data migrated from another store as plain strings; schema mapping declared the field as TIMESTAMP while the collection stores ISO-8601 strings.
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
- Sparse vector value must be a Number, but got: %s
- Unsupported datetime format:
- Unsupported timestamp type:
- Decimal precision %d exceeds configured precision %d
- Failed to open AmazonDocumentDB source reader for database [
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/b6f619b704bc8221.
Report an issue: GitHub.