{"record":{"id":"f3495bb6137a68a2","repo":"apache/druid","slug":"inconsistent-number-of-columns-d-and-columntypes","errorCode":null,"errorMessage":"Inconsistent number of columns[%d] and columnTypes[%d] specified!","messagePattern":"Inconsistent number of columns\\[(.+?)\\] and columnTypes\\[(.+?)\\] specified!","errorType":"validation","errorClass":"IllegalArgumentException (IAE)","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/scan/ScanQuery.java","lineNumber":163,"sourceCode":"    );\n    this.scanRowsOffset = scanRowsOffset;\n    Preconditions.checkArgument(\n        this.scanRowsOffset >= 0,\n        \"offset must be greater than or equal to 0\"\n    );\n    this.scanRowsLimit = (scanRowsLimit == 0) ? Long.MAX_VALUE : scanRowsLimit;\n    Preconditions.checkArgument(\n        this.scanRowsLimit > 0,\n        \"limit must be greater than 0\"\n    );\n    this.dimFilter = dimFilter;\n    this.columns = columns;\n    this.columnTypes = columnTypes;\n\n    if (columnTypes != null) {\n      Preconditions.checkNotNull(columns, \"columns may not be null if columnTypes are specified\");\n      if (columns.size() != columnTypes.size()) {\n        throw new IAE(\n            \"Inconsistent number of columns[%d] and columnTypes[%d] specified!\",\n            columns.size(),\n            columnTypes.size()\n        );\n      }\n    }\n\n    final Pair<List<OrderBy>, Order> ordering = verifyAndReconcileOrdering(orderBysFromUser, orderFromUser);\n    this.orderBys = Preconditions.checkNotNull(ordering.lhs);\n    this.timeOrder = ordering.rhs;\n\n    if (this.columns != null && this.columns.size() > 0) {\n      // Validate orderBy. (Cannot validate when signature is empty, since that means \"discover at runtime\".)\n\n      for (final OrderBy orderByColumn : this.orderBys) {\n        if (!this.columns.contains(orderByColumn.getColumnName())) {\n          // Error message depends on how the user originally specified ordering.\n          if (orderBysFromUser != null) {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/scan/ScanQuery.java#L145-L181","documentation":"The ScanQuery constructor validates that if columnTypes is provided, columns must also be provided and both lists must have the same length, since column types are matched positionally to columns. Mismatched sizes throw IAE. This guards the scan query's typed-columns API against ambiguous specs.","triggerScenarios":"Constructing ScanQuery (directly or via query JSON) where columns.size() != columnTypes.size(), or columnTypes set while columns is null.","commonSituations":"Hand-edited query JSON adding a type without the matching column; programmatic query building where the two lists are populated by different code paths.","solutions":["Make columns and columnTypes the same length and aligned by position","Omit columnTypes if you don't need to specify types","Ensure columns is non-null whenever columnTypes is specified"],"exampleFix":"// before\ncolumns: [\"a\",\"b\"], columnTypes: [\"LONG\"]\n// after\ncolumns: [\"a\",\"b\"], columnTypes: [\"LONG\",\"STRING\"]","handlingStrategy":"validation","validationCode":"if (columnTypes != null) {\n  if (columns == null || columns.size() != columnTypes.size()) {\n    throw new IllegalArgumentException(\"columns and columnTypes must be same length\");\n  }\n}","typeGuard":"boolean scanColumnsConsistent(List<String> columns, List<String> columnTypes) {\n  return columnTypes == null || (columns != null && columns.size() == columnTypes.size());\n}","tryCatchPattern":"try {\n  query = new ScanQuery(...);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Inconsistent number of columns\")) {\n    query = rebuildScanQueryAligned();\n  } else throw e;\n}","preventionTips":["Build columns and columnTypes in the same loop so they stay aligned","Omit columnTypes unless typed columns are explicitly needed"],"tags":["scan-query","argument-validation","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-17T15:17:12.973Z"}