slice method

RecordBatch slice(
  1. int offset, [
  2. int? length
])

Returns an owned copy of a row range while retaining schema metadata.

Dictionaries are immutable and shared with the source. Other value lists are copied; this method does not promise zero-copy physical buffers.

Implementation

RecordBatch slice(int offset, [int? length]) {
  if (offset < 0 || offset > rowCount) {
    throw RangeError.range(offset, 0, rowCount, 'offset');
  }
  final count = length ?? rowCount - offset;
  if (count < 0 || count > rowCount - offset) {
    throw RangeError.range(count, 0, rowCount - offset, 'length');
  }
  return RecordBatch(schema, [
    for (final column in columns)
      ArrowArray(
        column.type,
        column.values.sublist(offset, offset + count),
        dictionary: column.dictionary,
        nestedDictionaries: column.nestedDictionaries,
      ),
  ], rowCount: count);
}