{"record":{"id":"3632c9b45a0f5cbf","repo":"apache/druid","slug":"columnnames-and-columntypes-must-be-the-same-lengt","errorCode":null,"errorMessage":"columnNames and columnTypes must be the same length","messagePattern":"columnNames and columnTypes must be the same length","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/InlineDataSource.java","lineNumber":77,"sourceCode":"    this.rows = Preconditions.checkNotNull(rows, \"'rows' must be nonnull\");\n    this.signature = Preconditions.checkNotNull(signature, \"'signature' must be nonnull\");\n  }\n\n  /**\n   * Factory method for Jackson. Used for inline datasources that were originally encoded as JSON. Private because\n   * non-Jackson callers should use {@link #fromIterable}.\n   */\n  @JsonCreator\n  private static InlineDataSource fromJson(\n      @JsonProperty(\"columnNames\") List<String> columnNames,\n      @JsonProperty(\"columnTypes\") List<ColumnType> columnTypes,\n      @JsonProperty(\"rows\") ArrayList<Object[]> rows\n  )\n  {\n    Preconditions.checkNotNull(columnNames, \"'columnNames' must be nonnull\");\n\n    if (columnTypes != null && columnNames.size() != columnTypes.size()) {\n      throw new IAE(\"columnNames and columnTypes must be the same length\");\n    }\n\n    final RowSignature.Builder builder = RowSignature.builder();\n\n    for (int i = 0; i < columnNames.size(); i++) {\n      final String name = columnNames.get(i);\n      final ColumnType type = columnTypes != null ? columnTypes.get(i) : null;\n      builder.add(name, type);\n    }\n\n    return new InlineDataSource(rows, builder.build());\n  }\n\n  /**\n   * Creates an inline datasource from an Iterable. The Iterable will not be iterated until someone calls\n   * {@link #getRows()} and iterates the result, or until someone calls {@link #getRowsAsList()}.\n   *\n   * @param rows      rows, each of the same length as {@code signature.size()}","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/InlineDataSource.java#L59-L95","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n{\"columnNames\":[\"a\",\"b\"],\"columnTypes\":[\"LONG\"],\"rows\":[[1,\"x\"]]}\n// after\n{\"columnNames\":[\"a\",\"b\"],\"columnTypes\":[\"LONG\",\"VARCHAR\"],\"rows\":[[1,\"x\"]]}","handlingStrategy":"validation","validationCode":"if (columnTypes != null && columnNames.size() != columnTypes.size()) {\n  throw new IllegalArgumentException(\"columnNames and columnTypes must be the same length\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build columnNames and columnTypes together in one loop.","Omit columnTypes if types are unknown.","Validate inline datasource JSON before submitting queries."],"tags":["json","validation","inline-datasource","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}