{"record":{"id":"359b4e1eb9cd2a88","repo":"apache/druid","slug":"cannot-make-array-element-selector-for-path-s","errorCode":null,"errorMessage":"Cannot make array element selector for path [%s], negative array index not supported for this selector","messagePattern":"Cannot make array element selector for path \\[(.+?)\\], negative array index not supported for this selector","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/nested/CompressedNestedDataComplexColumn.java","lineNumber":580,"sourceCode":"  public DimensionSelector makeDimensionSelector(\n      List<NestedPathPart> path,\n      ExtractionFn extractionFn,\n      ColumnSelectorFactory selectorFactory,\n      ReadableOffset readableOffset\n  )\n  {\n    final Field field = getNestedFieldOrNestedArrayElementFromPath(path);\n    if (field instanceof NestedField) {\n      DictionaryEncodedColumn<?> col = (DictionaryEncodedColumn<?>) getColumnHolder(\n          ((NestedField) field).fieldName,\n          ((NestedField) field).fieldIndex\n      ).getColumn();\n      return col.makeDimensionSelector(readableOffset, extractionFn);\n    } else if (field instanceof NestedArrayElement) {\n      final NestedArrayElement arrayField = (NestedArrayElement) field;\n      final int elementNumber = arrayField.elementNumber;\n      if (elementNumber < 0) {\n        throw new IAE(\n            \"Cannot make array element selector for path [%s], negative array index not supported for this selector\",\n            path\n        );\n      }\n      ColumnValueSelector<?> arraySelector = getColumnHolder(\n          arrayField.nestedField.fieldName,\n          arrayField.nestedField.fieldIndex\n      ).getColumn().makeColumnValueSelector(readableOffset);\n      return new BaseSingleValueDimensionSelector()\n      {\n        @Nullable\n        @Override\n        protected String getValue()\n        {\n          Object o = arraySelector.getObject();\n          if (o instanceof Object[]) {\n            Object[] array = (Object[]) o;\n            if (elementNumber < array.length) {","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/nested/CompressedNestedDataComplexColumn.java#L562-L598","documentation":"When a nested field path references an array element (NestedArrayElement) with a negative element number, makeDimensionSelector cannot build the selector and throws IAE. Negative array indices are not supported for dimension selectors on nested columns.","triggerScenarios":"Calling makeDimensionSelector (via fieldSelector) with a path like $.arr[-1] or JSON_VALUE using a negative array index; NestedFieldPath parsed to NestedArrayElement with elementNumber < 0.","commonSituations":"Users writing SQL with negative JSON array indexing (e.g. '$[-1]') expecting Python-like last-element semantics; programmatically built NestedFieldPath with elementNumber computed to a negative value.","solutions":["Use a non-negative array index in the path (e.g. $.arr[0])","To get the last element, use SQL functions like ARRAY_OFFSET/ARRAY_SLICE or reverse logic instead of -1","Validate elementNumber >= 0 before constructing NestedArrayElement"],"exampleFix":"// before\nString path = \"$.tags[-1]\";\n// after\nString path = \"$.tags[0]\"; // or compute size-1 via array functions","handlingStrategy":"validation","validationCode":"int idx = nestedField.elementNumber; if (idx < 0) { throw new IllegalArgumentException(\"Negative array index not supported, use >= 0: \" + path); }","typeGuard":"boolean hasPositiveArrayIndex(String jsonPath) { return !java.util.regex.Pattern.compile(\"\\\\[\\\\s*-\\\\d+\\\\s*\\\\]\").matcher(jsonPath).find(); }","tryCatchPattern":"try { sel = column.makeDimensionSelector(offset, extractionFn); } catch (IAE e) { log.warn(\"Unsupported path %s: %s\", path, e.getMessage()); sel = null; }","preventionTips":["Reject negative array indices in user-supplied JSON paths at the API layer","Document supported path syntax for nested columns","Add query-level validation for JSON_VALUE/JSON_QUERY paths before planning"],"tags":["nested-column","selector","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}