apache/seatunnel · error · SensorsDataException

DATA_TYPE_CAST_FIELD

DATA_TYPE_CAST_FIELD

Error message

Value type must be STRING when target column type is LIST.

What it means

TypeUtil.toList converts a source value into a SensorsData LIST column by splitting a delimited string. It only accepts a java.lang.String; any other runtime type (numbers, arrays, collections, dates) is rejected with SensorsDataException code DATA_TYPE_CAST_FIELD. This guards the Sensors inf-sdk, which requires LIST target columns to be fed string input split by the configured separator.

Source

Thrown at seatunnel-connectors-v2/connector-sensorsdata/src/main/java/org/apache/seatunnel/connectors/sensorsdata/format/utils/TypeUtil.java:145

            case LIST_COMMA:
                return toList(source, ',');
            case LIST_SEMICOLON:
                return toList(source, ';');
            case TIMESTAMP:
                return toTimestamp(source, targetType, extra);
            case DATE:
                return toDate(source, targetType);
            case STRING:
            default:
                return toString(source);
        }
    }

    private static List<String> toList(Object str, char sep) {
        if (str instanceof String) {
            return Arrays.asList(StringUtils.split((String) str, sep));
        } else {
            throw new SensorsDataException(
                    SensorsDataErrorCode.DATA_TYPE_CAST_FIELD,
                    "Value type must be STRING when target column type is LIST.");
        }
    }

    private static Object toTimestamp(
            Object source, SensorsDataTypes.DataTypes targetType, String format) {
        if (source instanceof Date) {
            return ((Date) source).getTime();
        }
        if (source instanceof Number) {
            return source;
        }
        if (source instanceof LocalDate) {
            return ((LocalDate) source)
                    .atStartOfDay(ZoneId.systemDefault())
                    .toInstant()
                    .toEpochMilli();

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Change the target column type in the sink config from list to string, or cast the source column to STRING upstream before the sink.
  2. Use a transform (e.g. Cast/SQL transform) to convert the field to STRING prior to writing.
  3. Update the source schema so the column is declared as STRING when it feeds a LIST target.
  4. If the source is genuinely a list, serialize it to a delimited string (joining with the separator) upstream.

Example fix

// before: source field is an array feeding a LIST target
{"source_field": "tags_array", "target": "tags", "type": "list"} // throws
// after: cast to string first (transform) or declare source as STRING
{"source_field": "tags_array", "target": "tags", "type": "string"}
// or transform: CAST(tags_array AS STRING) before the sink
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(value instanceof String)) {
    throw new IllegalArgumentException(
        "Column '" + name + "' must be STRING to feed a LIST target; got " + value.getClass().getSimpleName());
}

Type guard

boolean isStringForListTarget(Object v) { return v instanceof String; }

Try / catch

try {
    Object converted = TypeUtil.toTargetType(value, "list");
} catch (SensorsDataException e) {
    if (SensorsDataErrorCode.DATA_TYPE_CAST_FIELD.equals(e.getErrorCode())) {
        // fall back to string conversion
        converted = String.valueOf(value);
    }
}

Prevention

When it happens

Trigger: toTargetType(source, LIST/LIST_COMMA/LIST_SEMICOLON) is called with a source value that is not a String — e.g. the SeaTunnel field is an INT, ARRAY, or DATE, while the target column config declares a LIST type (list, list-comma, or list-semicolon).

Common situations: Mismatches between the source table schema and the sink's target-column type mapping (e.g. source column is an array of strings but target is list); upstream schema evolution changed a column from STRING to a non-string type; users expect automatic coercion that the connector does not perform.

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/7efa3ab0a9478551. Report an issue: GitHub.