apache/beam · error · IllegalArgumentException

field was received -- type mismatch

Error message

 field  was received -- type mismatch

What it means

parseCell() wraps any IllegalArgumentException thrown while converting a CSV cell (e.g. Integer.parseInt failure) into a new IllegalArgumentException whose message is '<original message> field <name> was received -- type mismatch'. The reported message shows empty brackets because the underlying message and field name were null/empty at runtime, but the cause is always a bad cell value for the declared FieldType.

Source

Thrown at sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpers.java:158

        case BOOLEAN:
          return Boolean.parseBoolean(cell);
        case BYTE:
          return Byte.parseByte(cell);
        case DECIMAL:
          return new BigDecimal(cell);
        case DOUBLE:
          return Double.parseDouble(cell);
        case FLOAT:
          return Float.parseFloat(cell);
        case DATETIME:
          return Instant.parse(cell);
        default:
          throw new UnsupportedOperationException(
              "Unsupported type: " + fieldType + ", consider using withCustomRecordParsing");
      }

    } catch (IllegalArgumentException e) {
      throw new IllegalArgumentException(
          e.getMessage() + " field " + field.getName() + " was received -- type mismatch");
    }
  }
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Fix or filter malformed rows in the source CSV so each cell matches its field's type.
  2. Mark the field nullable and supply a custom parser/empty-cell handling to tolerate blanks.
  3. Validate data out-of-band (e.g. a dry-run parse) and log offending records before running the pipeline.

Example fix

// before: csv row '1,abc' with INTEGER field 'count' -> type mismatch
// after
CsvIO.read(path).withCustomRecordParsing(ParsingBuilder.of(schema)
    .setCustomParser("count", cell -> cell.isEmpty() ? 0L : Long.parseLong(cell.trim()))
    .build());
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate sample rows against field types
long bad = rows.filter(r -> !matchesSchema(r)).count();

Try / catch

try { pipeline.apply(CsvIO.read(path)); } catch (IllegalArgumentException e) { LOG.error("CSV type mismatch: {}", e.getMessage()); /* route file to dead-letter */ }

Prevention

When it happens

Trigger: A CSV cell that cannot be parsed as the schema field's type, e.g. 'abc' in an INTEGER column, '2024-13-99' in a DATETIME column, or 'yes' in a BOOLEAN column.

Common situations: Dirty data files with empty or malformed cells; columns shifted so values land in the wrong fields; locale-formatted numbers ('1,5') in DOUBLE columns; Excel-exported dates in unexpected formats.

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/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/bd31f3798a6ec5f7. Report an issue: GitHub.