{"record":{"id":"2534a5c1fadf0708","repo":"influxdata/influxdb","slug":"error-creating-field-record-batch","errorCode":null,"errorMessage":"Error creating _field record batch","messagePattern":"Error creating _field record batch","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/predicate/src/rpc_predicate/field_rewrite.rs","lineNumber":137,"sourceCode":"        // Form an array of strings from the field *names*:\n        //\n        // ┌─────────┐\n        // │ _field  │\n        // │  ----   │\n        // │  \"f1\"   │\n        // │  \"f2\"   │\n        // │  \"f3\"   │\n        // └─────────┘\n        let field_names: ArrayRef = Arc::new(\n            self.schema\n                .fields_iter()\n                .map(|f| f.name())\n                .map(Some)\n                .collect::<StringArray>(),\n        );\n\n        let batch = RecordBatch::try_from_iter(vec![(FIELD_COLUMN_NAME, Arc::clone(&field_names))])\n            .expect(\"Error creating _field record batch\");\n\n        // Ceremony to prepare to evaluate the predicates\n        let input_schema = batch.schema();\n        let input_df_schema: DFSchema = input_schema.as_ref().clone().try_into().unwrap();\n        let exprs = self\n            .field_predicates\n            .into_iter()\n            .map(|expr| session_ctx.create_physical_expr(expr, &input_df_schema))\n            .collect::<DataFusionResult<Vec<_>>>()\n            .map_err(|e| DataFusionError::Internal(format!(\"Unsupported _field predicate: {e}\")))?;\n\n        // evaluate into a boolean array where each element is true if\n        // the field name evaluated to true for all predicates, and\n        // false otherwise\n        let matching = exprs\n            .into_iter()\n            // evaluate each field_predicate against the actual field\n            // names. For example, if we have two predicates like","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/core/predicate/src/rpc_predicate/field_rewrite.rs#L119-L155","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check field_predicates is non-empty before calling add_to_predicate; return early with Transformed::no when empty","Log/dump the predicate being normalized — empty field predicates mean the caller should skip this rewriter","Fix upstream predicate parsing so add_to_predicate is only invoked for predicates containing field expressions","Convert the expect into a Result and propagate an error instead of panicking"],"exampleFix":"// before\nlet batch = RecordBatch::try_from_iter(vec![(FIELD_COLUMN_NAME, field_names)])\n    .expect(\"Error creating _field record batch\");\n// after\nif self.field_predicates.is_empty() {\n    return Ok(Transformed::no(orig_expr));\n}\nlet batch = RecordBatch::try_from_iter(vec![(FIELD_COLUMN_NAME, field_names)])?;","handlingStrategy":"validation","validationCode":"// caller-side: only invoke the field rewriter when field predicates exist\nif !predicate_has_field_expr(&predicate) {\n    return Ok(predicate);\n}","typeGuard":null,"tryCatchPattern":"// panic (expect) — cannot be caught as Result; guard the input instead\n// during diagnosis:\nlet result = std::panic::catch_unwind(|| rewriter.add_to_predicate(expr.clone()));","preventionTips":["Return early (Transformed::no) when field_predicates is empty","Never call add_to_predicate on predicates lacking field comparisons","Convert expects to Result/&DataFusionError propagation in library code","Test the rewriter against predicates composed only of time and value clauses"],"tags":["panic","empty-input","record-batch","datafusion"],"backgroundTag":"empty-required-field","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}