influxdata/influxdb · error

Error creating _field record batch

Error message

Error creating _field record batch

What it means

`add_to_predicate` builds a single-column record batch of `_field` names with `RecordBatch::try_from_iter(...).expect("Error creating _field record batch")`. This panics if the batch cannot be constructed — practically, when the list of field predicate names is empty (try_from_iter rejects zero columns/empty iterator fails on the array construction) or the StringArray build fails.

Solutions

  1. Check field_predicates is non-empty before calling add_to_predicate; return early with Transformed::no when empty
  2. Log/dump the predicate being normalized — empty field predicates mean the caller should skip this rewriter
  3. Fix upstream predicate parsing so add_to_predicate is only invoked for predicates containing field expressions
  4. Convert the expect into a Result and propagate an error instead of panicking

Example fix

// before
let batch = RecordBatch::try_from_iter(vec![(FIELD_COLUMN_NAME, field_names)])
    .expect("Error creating _field record batch");
// after
if self.field_predicates.is_empty() {
    return Ok(Transformed::no(orig_expr));
}
let batch = RecordBatch::try_from_iter(vec![(FIELD_COLUMN_NAME, field_names)])?;
Defensive patterns

Strategy: validation

Validate before calling

// caller-side: only invoke the field rewriter when field predicates exist
if !predicate_has_field_expr(&predicate) {
    return Ok(predicate);
}

Try / catch

// panic (expect) — cannot be caught as Result; guard the input instead
// during diagnosis:
let result = std::panic::catch_unwind(|| rewriter.add_to_predicate(expr.clone()));

Prevention

When it happens

Trigger: Calling normalize_predicate on a predicate whose field_predicates list is empty, yielding an empty iterator into try_from_iter; also on schema/array construction failure for FIELD_COLUMN_NAME.

Common situations: Rewriting a predicate with no field-specific comparisons (only time/value predicates); API misuse where add_to_predicate is invoked though there is nothing to rewrite.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19). Data as JSON: /api/errors/2534a5c1fadf0708. Report an issue: GitHub.

Appendix: source

Thrown at core/predicate/src/rpc_predicate/field_rewrite.rs:137

        // Form an array of strings from the field *names*:
        //
        // ┌─────────┐
        // │ _field  │
        // │  ----   │
        // │  "f1"   │
        // │  "f2"   │
        // │  "f3"   │
        // └─────────┘
        let field_names: ArrayRef = Arc::new(
            self.schema
                .fields_iter()
                .map(|f| f.name())
                .map(Some)
                .collect::<StringArray>(),
        );

        let batch = RecordBatch::try_from_iter(vec![(FIELD_COLUMN_NAME, Arc::clone(&field_names))])
            .expect("Error creating _field record batch");

        // Ceremony to prepare to evaluate the predicates
        let input_schema = batch.schema();
        let input_df_schema: DFSchema = input_schema.as_ref().clone().try_into().unwrap();
        let exprs = self
            .field_predicates
            .into_iter()
            .map(|expr| session_ctx.create_physical_expr(expr, &input_df_schema))
            .collect::<DataFusionResult<Vec<_>>>()
            .map_err(|e| DataFusionError::Internal(format!("Unsupported _field predicate: {e}")))?;

        // evaluate into a boolean array where each element is true if
        // the field name evaluated to true for all predicates, and
        // false otherwise
        let matching = exprs
            .into_iter()
            // evaluate each field_predicate against the actual field
            // names. For example, if we have two predicates like

View on GitHub (pinned to 06200ef96b)