apache/druid · error · IllegalArgumentException
Cannot make array element selector for path
Error message
Cannot make array element selector for path [%s], negative array index not supported for this selector
What it means
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.
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
Example fix
// before String path = "$.tags[-1]"; // after String path = "$.tags[0]"; // or compute size-1 via array functions
Defensive patterns
Strategy: validation
Validate before calling
int idx = nestedField.elementNumber; if (idx < 0) { throw new IllegalArgumentException("Negative array index not supported, use >= 0: " + path); } Type guard
boolean hasPositiveArrayIndex(String jsonPath) { return !java.util.regex.Pattern.compile("\\[\\s*-\\d+\\s*\\]").matcher(jsonPath).find(); } Try / catch
try { sel = column.makeDimensionSelector(offset, extractionFn); } catch (IAE e) { log.warn("Unsupported path %s: %s", path, e.getMessage()); sel = null; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Cannot use lookupNameUtf8 on this selector
- Multi-value row not supported
- Unsupported nested array type
- Aggregator[ ] cannot vectorize
- AppenderatorsManager methods should only called by services…
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/359b4e1eb9cd2a88.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/segment/nested/CompressedNestedDataComplexColumn.java:580
public DimensionSelector makeDimensionSelector(
List<NestedPathPart> path,
ExtractionFn extractionFn,
ColumnSelectorFactory selectorFactory,
ReadableOffset readableOffset
)
{
final Field field = getNestedFieldOrNestedArrayElementFromPath(path);
if (field instanceof NestedField) {
DictionaryEncodedColumn<?> col = (DictionaryEncodedColumn<?>) getColumnHolder(
((NestedField) field).fieldName,
((NestedField) field).fieldIndex
).getColumn();
return col.makeDimensionSelector(readableOffset, extractionFn);
} else if (field instanceof NestedArrayElement) {
final NestedArrayElement arrayField = (NestedArrayElement) field;
final int elementNumber = arrayField.elementNumber;
if (elementNumber < 0) {
throw new IAE(
"Cannot make array element selector for path [%s], negative array index not supported for this selector",
path
);
}
ColumnValueSelector<?> arraySelector = getColumnHolder(
arrayField.nestedField.fieldName,
arrayField.nestedField.fieldIndex
).getColumn().makeColumnValueSelector(readableOffset);
return new BaseSingleValueDimensionSelector()
{
@Nullable
@Override
protected String getValue()
{
Object o = arraySelector.getObject();
if (o instanceof Object[]) {
Object[] array = (Object[]) o;
if (elementNumber < array.length) {View on GitHub (pinned to 9b90983fd2)