prestodb/presto · error · IllegalArgumentException

invalid mapping '%s' for column '%s'

Error message

invalid mapping '%s' for column '%s'

What it means

During CsvColumnDecoder construction, each column's mapping string must parse to a non-negative integer CSV field index. If Integer.parseInt fails (non-numeric mapping) or the parsed index is negative, the constructor throws IllegalArgumentException with this message. It is a table/connector configuration error caught at decoder build time, not a data error.

Source

Thrown at presto-record-decoder/src/main/java/com/facebook/presto/decoder/csv/CsvColumnDecoder.java:60

    private final Type columnType;
    private final int columnIndex;

    public CsvColumnDecoder(DecoderColumnHandle columnHandle)
    {
        try {
            requireNonNull(columnHandle, "columnHandle is null");
            checkArgument(!columnHandle.isInternal(), "unexpected internal column '%s'", columnHandle.getName());
            columnName = columnHandle.getName();
            checkArgument(columnHandle.getFormatHint() == null, "unexpected format hint '%s' defined for column '%s'", columnHandle.getFormatHint(), columnName);
            checkArgument(columnHandle.getDataFormat() == null, "unexpected data format '%s' defined for column '%s'", columnHandle.getDataFormat(), columnName);
            columnType = columnHandle.getType();

            checkArgument(columnHandle.getMapping() != null, "mapping not defined for column '%s'", columnName);
            try {
                columnIndex = Integer.parseInt(columnHandle.getMapping());
            }
            catch (NumberFormatException e) {
                throw new IllegalArgumentException(format("invalid mapping '%s' for column '%s'", columnHandle.getMapping(), columnName));
            }
            checkArgument(columnIndex >= 0, "invalid mapping '%s' for column '%s'", columnHandle.getMapping(), columnName);

            checkArgument(isSupportedType(columnType), "Unsupported column type '%s' for column '%s'", columnType.getDisplayName(), columnName);
        }
        catch (IllegalArgumentException e) {
            throw new PrestoException(GENERIC_USER_ERROR, e);
        }
    }

    private static boolean isSupportedType(Type type)
    {
        if (isVarcharType(type)) {
            return true;
        }
        if (ImmutableList.of(BIGINT, INTEGER, SMALLINT, TINYINT, BOOLEAN, DOUBLE).contains(type)) {
            return true;
        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Set the column mapping to a zero-based integer matching the CSV field position, e.g. mapping='3'
  2. Validate all column mappings are numeric and >= 0 before running the query
  3. Check the connector-specific documentation for the mapping syntax (CSV requires integer indexes, not field names)
  4. Fix the table definition (CREATE TABLE ... COMMENT with mappings) and recreate/alter the table

Example fix

// before
{"name": "user_id", "mapping": "userId"}
// after
{"name": "user_id", "mapping": "0"}
Defensive patterns

Strategy: validation

Validate before calling

void validateCsvMappings(Map<String,String> mappings) {
    mappings.forEach((col, m) -> {
        if (m == null) throw new IllegalArgumentException("mapping not defined for column '" + col + "'");
        int idx;
        try { idx = Integer.parseInt(m.trim()); }
        catch (NumberFormatException e) { throw new IllegalArgumentException("invalid mapping '" + m + "' for column '" + col + "'"); }
        if (idx < 0) throw new IllegalArgumentException("invalid mapping '" + m + "' for column '" + col + "'");
    });
}

Try / catch

try {
    CsvColumnDecoder d = new CsvColumnDecoder(columnHandles);
} catch (IllegalArgumentException e) {
    throw new TableConfigException("Fix column mappings in table definition: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Column mapping in the connector config is a non-numeric string (e.g. 'name', '1a'); mapping is negative (e.g. '-1'); mapping property missing but the null check above passed only for other columns.

Common situations: Typos in CREATE TABLE mapping syntax; copying JSON decoder configs (which use JSON paths) into a CSV table; template scripts substituting placeholders like '{idx}' that never got replaced; off-by-one attempts using negative indexes.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/c3b7d1d8d618d567. Report an issue: GitHub.