{"record":{"id":"9a47dec8bd7bcd7a","repo":"apache/seatunnel","slug":"convert-target-data-type-error-source-targett","errorCode":null,"errorMessage":"convert target data type error. source:{}, targetType:{}","messagePattern":"convert target data type error\\. source:(.+?), targetType:(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-sensorsdata/src/main/java/org/apache/seatunnel/connectors/sensorsdata/format/utils/TypeUtil.java","lineNumber":183,"sourceCode":"        if (source instanceof LocalDateTime) {\n            return ((LocalDateTime) source)\n                    .atZone(ZoneId.systemDefault())\n                    .toInstant()\n                    .toEpochMilli();\n        }\n        if (source instanceof String) {\n            Long timestamp;\n            if (format == null) {\n                timestamp = tryParse((String) source);\n            } else {\n                DateTimeFormatter formatter = parseDateTimeFormatter(format);\n                timestamp = tryParse((String) source, formatter);\n            }\n            if (timestamp != null) {\n                return timestamp;\n            }\n        }\n        log.warn(TRANSFORM_WARN_INFO, source, targetType);\n        return source;\n    }\n\n    private static Object toBoolean(Object source, SensorsDataTypes.DataTypes targetType) {\n        if (source instanceof Boolean) {\n            return source;\n        }\n        if (source instanceof Number) {\n            return !Objects.equal(0, source)\n                    && !Objects.equal(0F, source)\n                    && !Objects.equal(0D, source)\n                    && !Objects.equal(0L, source);\n        }\n        if (source instanceof String) {\n            return StringUtils.equalsIgnoreCase(\"true\", source.toString());\n        }\n        log.warn(TRANSFORM_WARN_INFO, source, targetType);\n        return source;","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-sensorsdata/src/main/java/org/apache/seatunnel/connectors/sensorsdata/format/utils/TypeUtil.java#L165-L201","documentation":"In Apache SeaTunnel's SensorsData connector, TypeUtil.toTimestamp() converts a field value to an epoch-millisecond timestamp for the SensorsData (zhugeio) inf-sdk. When the source value cannot be interpreted as a Date, Number, LocalDate, LocalDateTime, or a date string matching one of the supported formatters (or a custom `extra` pattern), the conversion fails. This is NOT an exception: the method logs 'convert target data type error. source:{}, targetType:{}' at WARN level and returns the original value unchanged, so the field is sent to SensorsData with its raw, unconverted type.","triggerScenarios":"TypeUtil.toTimestamp(source, TIMESTAMP, extra) is reached via toTargetType() when the schema maps a column to TIMESTAMP but the runtime value is a String that matches none of the internal patterns (yyyy-MM-dd HH:mm:ss.SSS, yyyy-MM-dd HH:mm:ss, yyyy-MM-dd HH:mm, yyyy-MM-dd, yyyyMMdd_HHmmss, yyyyMMdd) nor the custom `extra` DateTimeFormatter pattern; e.g. an ISO-8601 string like '2024-01-15T10:30:00Z' or a locale-formatted date.","commonSituations":"Upstream data (CSV/JSON/Kafka) carries dates in ISO-8601 or RFC-3339 format with 'T' separator or timezone suffix, which the hardcoded SeaTunnel formatters do not accept; user forgets to set the TIMESTAMP extra format option; source column is empty or contains 'N/A'/'null' strings; timezone/locale differences shift the expected pattern.","solutions":["Set the TIMESTAMP column's extra format option in the connector schema to a DateTimeFormatter pattern matching your data (e.g. \"yyyy-MM-dd'T'HH:mm:ssXXX\").","Normalize the date string upstream (transform) into one of the supported patterns: yyyy-MM-dd HH:mm:ss, yyyy-MM-dd HH:mm:ss.SSS, yyyy-MM-dd, yyyyMMdd_HHmmss, yyyyMMdd, or yyyy-MM-dd HH:mm.","Check the WARN log line to see the exact offending source value and target type, then fix the source data or mapping.","If the field is not really a timestamp, change the schema type to STRING so no conversion is attempted."],"exampleFix":"// before: schema maps event_time as TIMESTAMP but data is ISO-8601\n// 2024-01-15T10:30:00Z  -> conversion fails, value passed through as String\n\n// after: declare the extra format for the TIMESTAMP field\n// fields { event_time = TIMESTAMP }\n// with extra format option set to:\n// \"yyyy-MM-dd'T'HH:mm:ssXXX\"\n// or pre-normalize the value: 2024-01-15 10:30:00","handlingStrategy":"validation","validationCode":"// Java: verify before writing a TIMESTAMP field\nprivate static boolean isValidTimestamp(Object v) {\n    return v instanceof java.util.Date\n        || v instanceof Number\n        || v instanceof java.time.LocalDate\n        || v instanceof java.time.LocalDateTime\n        || (v instanceof String s && !s.isBlank() && TypeUtil.tryParsePatterns(s)); // matches yyyy-MM-dd[ HH:mm:ss[.SSS]] etc.\n}\n// call: if (!isValidTimestamp(value)) { normalize(value); }","typeGuard":"private static boolean isTimestampConvertible(Object v) {\n    if (v == null) return true; // null short-circuits in toTargetType\n    return v instanceof java.util.Date || v instanceof Number\n        || v instanceof java.time.LocalDate || v instanceof java.time.LocalDateTime\n        || (v instanceof String && v.toString().matches(\"\\\\d{4}-\\\\d{2}-\\\\d{2}( \\\\d{2}:\\\\d{2}(:\\\\d{2}(\\\\.\\\\d{3})?)?)?|\\\\d{8}(_\\\\d{6})?\"));\n}","tryCatchPattern":null,"preventionTips":["Always declare the extra format pattern for TIMESTAMP columns whose data is not in a supported default pattern.","Pre-normalize ISO-8601 ('T'-separated, timezone-suffixed) dates before ingest.","Grep connector logs for 'convert target data type error' after pipeline changes to catch silently passed-through fields.","Validate sample source records against the formatter patterns before running full jobs."],"tags":["date-format","type-conversion","sensorsdata","sea-tunnel"],"backgroundTag":"invalid-date-format","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}