apache/druid · error · IllegalArgumentException
columnNames and columnTypes must be the same length
Error message
columnNames and columnTypes must be the same length
What it means
InlineDataSource.fromJson deserializes an inline datasource from JSON with columnNames, columnTypes (optional), and rows. If columnTypes is provided, it must have exactly one entry per column name; otherwise this IllegalArgumentException is thrown before building the RowSignature.
Source
Thrown at processing/src/main/java/org/apache/druid/query/InlineDataSource.java:77
this.rows = Preconditions.checkNotNull(rows, "'rows' must be nonnull");
this.signature = Preconditions.checkNotNull(signature, "'signature' must be nonnull");
}
/**
* Factory method for Jackson. Used for inline datasources that were originally encoded as JSON. Private because
* non-Jackson callers should use {@link #fromIterable}.
*/
@JsonCreator
private static InlineDataSource fromJson(
@JsonProperty("columnNames") List<String> columnNames,
@JsonProperty("columnTypes") List<ColumnType> columnTypes,
@JsonProperty("rows") ArrayList<Object[]> rows
)
{
Preconditions.checkNotNull(columnNames, "'columnNames' must be nonnull");
if (columnTypes != null && columnNames.size() != columnTypes.size()) {
throw new IAE("columnNames and columnTypes must be the same length");
}
final RowSignature.Builder builder = RowSignature.builder();
for (int i = 0; i < columnNames.size(); i++) {
final String name = columnNames.get(i);
final ColumnType type = columnTypes != null ? columnTypes.get(i) : null;
builder.add(name, type);
}
return new InlineDataSource(rows, builder.build());
}
/**
* Creates an inline datasource from an Iterable. The Iterable will not be iterated until someone calls
* {@link #getRows()} and iterates the result, or until someone calls {@link #getRowsAsList()}.
*
* @param rows rows, each of the same length as {@code signature.size()}View on GitHub (pinned to 9b90983fd2)
Solutions
- Make columnTypes the same length as columnNames, adding the type for each column.
- Alternatively remove columnTypes entirely (it is optional) so types are inferred from rows.
- Fix the client code that builds the two lists to append to both together.
Example fix
// before
{"columnNames":["a","b"],"columnTypes":["LONG"],"rows":[[1,"x"]]}
// after
{"columnNames":["a","b"],"columnTypes":["LONG","VARCHAR"],"rows":[[1,"x"]]} Defensive patterns
Strategy: validation
Validate before calling
if (columnTypes != null && columnNames.size() != columnTypes.size()) {
throw new IllegalArgumentException("columnNames and columnTypes must be the same length");
} Prevention
- Build columnNames and columnTypes together in one loop.
- Omit columnTypes if types are unknown.
- Validate inline datasource JSON before submitting queries.
When it happens
Trigger: POSTing/serializing an inline datasource JSON where columnNames and columnTypes arrays differ in length, e.g. hand-written query JSON or a client adding a column name without the matching type.
Common situations: Hand-editing inline datasource JSON in query submissions; programmatic construction appending to one list but not the other; round-tripping through tools that truncate the types array.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Aggregation [%s] does not support column [%s] of type [%s].
- '%s' must be a string or an array of strings
- First token should be START_ARRAY, but it is actually [%s]
- Must provide at least one range
- Dim lengths not equal %s vs %s
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/3632c9b45a0f5cbf.
Report an issue: GitHub.