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();
        }

        @Override

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Supply exactly one of fieldName or fieldExpression
  2. Remove the extra key from the JSON spec when both are present
  3. 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

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


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/39fed36a32d7513c. Report an issue: GitHub.