prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Number of split tokens is not equal to schema length. Expected %s received %s. Schema: %s, fields {%s}, delimiter %s

What it means

Row.fromString splits a delimited string with Splitter.on(delimiter) and asserts the token count equals the number of columns in the supplied RowSchema; if not, it throws INVALID_FUNCTION_ARGUMENT with expected vs received counts, the schema, fields, and delimiter. This guards against misaligned positional field deserialization.

Source

Thrown at presto-accumulo/src/main/java/com/facebook/presto/accumulo/model/Row.java:153

    /**
     * Creates a new {@link Row} from the given delimited string based on the given {@link RowSchema}
     *
     * @param schema Row's schema
     * @param str String to parse
     * @param delimiter Delimiter of the string
     * @return A new Row
     * @throws PrestoException If the length of the split string is not equal to the length of the schema
     * @throws PrestoException If the schema contains an unsupported type
     */
    public static Row fromString(RowSchema schema, String str, char delimiter)
    {
        Row row = new Row();

        ImmutableList.Builder<String> builder = ImmutableList.builder();
        List<String> fields = builder.addAll(Splitter.on(delimiter).split(str)).build();

        if (fields.size() != schema.getLength()) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Number of split tokens is not equal to schema length. Expected %s received %s. Schema: %s, fields {%s}, delimiter %s", schema.getLength(), fields.size(), schema, StringUtils.join(fields, ","), delimiter));
        }

        for (int i = 0; i < fields.size(); ++i) {
            Type type = schema.getColumn(i).getType();
            row.addField(valueFromString(fields.get(i), type), type);
        }

        return row;
    }

    /**
     * Converts the given String into a Java object based on the given Presto type
     *
     * @param str String to convert
     * @param type Presto Type
     * @return Java object
     * @throws PrestoException If the type is not supported by this function
     */

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Verify the delimiter matches the one used when the row string was written
  2. Escape or remove delimiter characters inside field values, or choose a delimiter that never appears in data
  3. Reconcile the RowSchema with the actual data — regenerate row strings after schema changes
  4. Pre-split and validate the record yourself, then build the Row via addField instead of fromString

Example fix

// before
Row row = Row.fromString(schema, line, ",");
// after
String safeDelim = "\u0001"; // unit separator unlikely in data
Row row = Row.fromString(schema, line, safeDelim);
Defensive patterns

Strategy: validation

Validate before calling

List<String> fields = Splitter.on(delimiter).splitToList(str);
if (fields.size() != schema.getLength()) {
    throw new IllegalArgumentException(format("Expected %d fields, got %d", schema.getLength(), fields.size()));
}
Row row = Row.fromString(schema, str, delimiter);

Type guard

static boolean isSplittableRecord(String str, RowSchema schema, String delimiter) {
    return str != null && Splitter.on(delimiter).splitToList(str).size() == schema.getLength();
}

Try / catch

try {
    return Row.fromString(schema, line, delim);
} catch (PrestoException e) {
    if (e.getErrorCode().getCode() == StandardErrorCode.INVALID_FUNCTION_ARGUMENT.toErrorCode().getCode()) {
        log.warn("Skipping malformed record: %s", e.getMessage());
        return null;
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling Row.fromString(schema, str, delimiter) where the record's split token count != schema.getLength() — e.g. extra embedded delimiter characters in field values, missing trailing columns, or a wrong delimiter string passed in.

Common situations: Importing Accumulo rows whose String serialization was produced with a different delimiter; values containing the delimiter (commas/tabs in text); schema evolved (column added/removed) after rows were written.

Related errors


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