{"record":{"id":"4341dfb36cface8d","repo":"influxdata/influxdb","slug":"the-record-batch-is-empty","errorCode":null,"errorMessage":"The Record batch is empty","messagePattern":"The Record batch is empty","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"core/iox_query/src/util.rs","lineNumber":104,"sourceCode":"    let mut min_time = i64::MAX;\n    let mut max_time = i64::MIN;\n    for batch in batches {\n        let (mi, ma) = compute_timenanosecond_min_max_for_one_record_batch(batch)?;\n        min_time = min(min_time, mi);\n        max_time = max(max_time, ma);\n    }\n    Ok(TimestampMinMax {\n        min: min_time,\n        max: max_time,\n    })\n}\n\n/// Return min and max for column `time` in the given record batch by performing\n/// an `O(n)` scan of `batch`.\npub fn compute_timenanosecond_min_max_for_one_record_batch(\n    batch: &RecordBatch,\n) -> Result<(i64, i64)> {\n    ensure!(batch.num_columns() > 0, EmptyBatchSnafu);\n\n    let index = batch\n        .schema()\n        .index_of(TIME_COLUMN_NAME)\n        .context(TimeColumnSnafu {})?;\n\n    let time_col = batch\n        .column(index)\n        .as_any()\n        .downcast_ref::<TimestampNanosecondArray>()\n        .context(TimeCastingSnafu {})?;\n\n    let (min, max) = match time_col.iter().minmax() {\n        itertools::MinMaxResult::NoElements => return Err(Error::TimeValue),\n        itertools::MinMaxResult::OneElement(val) => {\n            let val = val.context(TimeNullSnafu)?;\n            (val, val)\n        }","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/core/iox_query/src/util.rs#L86-L122","documentation":"Returned by compute_timenanosecond_min_max_for_one_record_batch when the record batch has no columns (EmptyBatchSnafu). The function scans the `time` column to compute min/max, which is impossible on an empty-schema batch, so it fails fast with this error.","triggerScenarios":"Calling compute_timenanosecond_min_max (or the per-batch helper) with a RecordBatch created with zero columns — e.g. an empty projection or a batch built from an empty schema.","commonSituations":"Query plans that select no columns alongside time bounds; record batches constructed manually in tests with an empty schema; upstream chunks yielding degenerate empty batches.","solutions":["Check batch.num_columns() > 0 before calling the helper","Ensure the query projection always includes the time column","Skip empty batches in the caller loop and aggregate the rest"],"exampleFix":"// before\nlet (min, max) = compute_timenanosecond_min_max_for_one_record_batch(&batch)?;\n// after\nif batch.num_columns() == 0 {\n    continue; // or return a default range\n}\nlet (min, max) = compute_timenanosecond_min_max_for_one_record_batch(&batch)?;","handlingStrategy":"validation","validationCode":"if batch.num_columns() == 0 { return Ok(default_range); }","typeGuard":"fn has_columns(b: &RecordBatch) -> bool { b.num_columns() > 0 }","tryCatchPattern":"match compute_timenanosecond_min_max_for_one_record_batch(&batch) {\n    Err(e) if matches!(e.find_root(), EmptyBatchError) => return default,\n    other => other?,\n}","preventionTips":["Skip empty batches before min/max computation","Ensure projections include the time column","Add empty-batch cases to tests"],"tags":["rust","record-batch","time-column","empty-input"],"backgroundTag":"empty-result-set","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"}