{"record":{"id":"72c49b04332bc5fa","repo":"apache/druid","slug":"cannot-provide-order-incompatible-with-orderby","errorCode":null,"errorMessage":"Cannot provide 'order' incompatible with 'orderBy'","messagePattern":"Cannot provide 'order' incompatible with 'orderBy'","errorType":"validation","errorClass":"IllegalArgumentException (IAE)","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/scan/ScanQuery.java","lineNumber":545,"sourceCode":"  {\n    final List<OrderBy> orderByRetVal;\n    final Order orderRetVal;\n\n    // Compute the returned orderBy.\n    if (orderByFromUser != null) {\n      orderByRetVal = orderByFromUser;\n    } else if (orderFromUser == null || orderFromUser == Order.NONE) {\n      orderByRetVal = Collections.emptyList();\n    } else {\n      orderByRetVal = Collections.singletonList(new OrderBy(ColumnHolder.TIME_COLUMN_NAME, orderFromUser));\n    }\n\n    // Compute the returned order.\n    orderRetVal = computeTimeOrderFromOrderBys(orderByRetVal);\n\n    // Verify compatibility, if the user specified both kinds of ordering.\n    if (orderFromUser != null && orderFromUser != Order.NONE && orderRetVal != orderFromUser) {\n      throw new IAE(\"Cannot provide 'order' incompatible with 'orderBy'\");\n    }\n\n    return Pair.of(orderByRetVal, orderRetVal);\n  }\n\n  /**\n   * Compute time ordering based on a list of orderBys.\n   *\n   * Returns {@link Order#ASCENDING} or {@link Order#DESCENDING} if the ordering is time-based; returns\n   * {@link Order#NONE} otherwise. Importantly, this means that the returned order is not necessarily compatible\n   * with the input orderBys.\n   */\n  @Nullable\n  private static Order computeTimeOrderFromOrderBys(final List<OrderBy> orderBys)\n  {\n    if (orderBys.size() == 1) {\n      final OrderBy orderByColumn = Iterables.getOnlyElement(orderBys);\n","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/scan/ScanQuery.java#L527-L563","documentation":"verifyAndReconcileOrdering reconciles the legacy 'order' property with the newer 'orderBy' list. If the user supplied both, and the computed order derived from orderBy differs from the explicitly requested order, the query is contradictory and Druid throws IAE at query construction.","triggerScenarios":"Constructing/deserializing a ScanQuery where 'order' is non-null, not NONE, and computeTimeOrderFromOrderBys(orderBys) yields a different Order than the user-specified orderFromUser (e.g. order:\"descending\" with orderBy on a non-__time column).","commonSituations":"Migrating queries from 'order' to 'orderBy' where both were left in the JSON; templated queries where a UI injected orderBy while the payload kept the old order field.","solutions":["Remove the legacy 'order' property and keep only 'orderBy'","Align 'order' with what the orderBy list implies (ascending/descending for __time-only orderBy)","Keep only 'order' and drop orderBy if simple time ordering suffices"],"exampleFix":"// before\n{\"queryType\":\"scan\",\"columns\":[\"__time\"],\"order\":\"descending\",\"orderBy\":[{\"columnName\":\"country\"}]}\n// after\n{\"queryType\":\"scan\",\"columns\":[\"__time\",\"country\"],\"orderBy\":[{\"columnName\":\"country\"}]}","handlingStrategy":"validation","validationCode":"if (raw.order != null && raw.order != Order.NONE && raw.orderBy != null) {\n  throw new IllegalArgumentException(\"Provide either 'order' or 'orderBy', not both\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  ScanQuery q = objectMapper.readValue(json, ScanQuery.class);\n} catch (IllegalArgumentException e) {\n  // strip legacy 'order' field and retry\n}","preventionTips":["Migrate all payloads to use only 'orderBy'","Strip the legacy 'order' key in query-ingestion middleware","Document the mutual exclusivity in client SDKs"],"tags":["druid","scan-query","conflicting-options","validation"],"backgroundTag":"conflicting-config-options","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}