decode method

RecordBatch decode(
  1. Map<String, Object?> batch
)

Implementation

RecordBatch decode(Map<String, Object?> batch) {
  final columns = (batch['columns'] as List)
      .map((raw) {
        final column = (raw as Map).cast<String, Object?>();
        final dtype = _arrowDType(
          (column['dtype'] as Map).cast<String, Object?>(),
        );
        final values = (column['values'] as List)
            .map((value) => _arrowValue(dtype, value))
            .toList(growable: false);
        return <String, Object?>{
          ...column,
          'dtype': dtype,
          'values': values,
          'validity': values
              .map((value) => value != null)
              .toList(growable: false),
        };
      })
      .toList(growable: false);
  final returnedLength = batch['length'];
  if (returnedLength != null && returnedLength is! int) {
    throw const FormatException('Native batch length must be an integer');
  }
  return _codec.fromJson({
    'schema': {
      'fields': [
        for (final column in columns)
          {
            'name': column['name'],
            'dtype': column['dtype'],
            'nullable': true,
          },
      ],
    },
    'length':
        returnedLength ??
        (columns.isEmpty ? 0 : (columns.first['values'] as List).length),
    'columns': columns,
  });
}