apache/druid · error · IllegalArgumentException
Only one of fieldName and fieldExpression should be non-null
Error message
Only one of fieldName and fieldExpression should be non-null
What it means
Same mutual-exclusion rule as the float variant but for long-defaulting selectors: exactly one of fieldName or fieldExpression must be non-null when calling makeColumnValueSelectorWithLongDefault; otherwise IllegalArgumentException is thrown.
Source
Thrown at processing/src/main/java/org/apache/druid/query/aggregation/AggregatorUtil.java:304
inspector.visit("baseSelector", baseSelector);
}
}
return new ExpressionFloatColumnSelector();
}
}
/**
* Only one of fieldName and fieldExpression should be non-null
*/
static ColumnValueSelector<?> makeColumnValueSelectorWithLongDefault(
final ColumnSelectorFactory columnSelectorFactory,
@Nullable final String fieldName,
@Nullable final Expr fieldExpression,
final long nullValue
)
{
if ((fieldName == null) == (fieldExpression == null)) {
throw new IllegalArgumentException("Only one of fieldName and fieldExpression should be non-null");
}
if (fieldName != null) {
return columnSelectorFactory.makeColumnValueSelector(fieldName);
} else {
final ColumnValueSelector<ExprEval> baseSelector = ExpressionSelectors.makeExprEvalSelector(
columnSelectorFactory,
fieldExpression
);
class ExpressionLongColumnSelector implements LongColumnSelector
{
@Override
public long getLong()
{
final ExprEval<?> exprEval = baseSelector.getObject();
return exprEval.isNumericNull() ? nullValue : exprEval.asLong();
}
@OverrideView on GitHub (pinned to 9b90983fd2)
Solutions
- Supply exactly one of fieldName or fieldExpression
- Remove the extra key from the JSON spec when both are present
- Set the missing field when both are null
Example fix
// before
{"type":"longSum","name":"l","fieldName":"col","expression":"col + 1"}
// after
{"type":"longSum","name":"l","fieldName":"col"} Defensive patterns
Strategy: validation
Validate before calling
// before construction
if ((fieldName == null) == (fieldExpression == null)) {
throw new IllegalArgumentException("Exactly one of fieldName or fieldExpression must be set");
} Try / catch
try {
selector = AggregatorUtil.makeColumnValueSelectorWithLongDefault(sf, fieldName, expr, 0L);
} catch (IllegalArgumentException e) {
log.error("Bad long aggregator spec", e);
throw e;
} Prevention
- Audit long aggregator specs for both/neither fieldName and expression
- Use schema validation on ingestion specs before deploying tasks
- Keep expression usage in dedicated aggregators (e.g. expression 'longSum' variants) explicit
When it happens
Trigger: Calling makeColumnValueSelectorWithLongDefault with both fieldName and fieldExpression set, or with neither set.
Common situations: Ingestion/query spec mistakes with both 'fieldName' and 'expression' keys present (or both absent) in long aggregators; programmatic factory construction errors.
Related errors
- Aggregation [%s] does not support column [%s] of type [%s].
- Only one of fieldName or expression should be non-null
- maxStringBytes must be greater than 0
- maxStringBytes must be greater than 0
- Emit called unexpectedly before service start
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/39fed36a32d7513c.
Report an issue: GitHub.