toJson method

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

Implementation

Map<String, Object?> toJson(RecordBatch batch) {
  // Logical nested values carry dictionary indices, not the child dictionary
  // storage. Do not serialize an apparently complete but lossy payload.
  bool hasDictionary(Array array) =>
      array.dictionary != null || array.children.any(hasDictionary);
  void checkDictionaries(Array array) {
    if (array.children.any(hasDictionary)) {
      throw UnsupportedError(
        'Owned JSON does not encode nested dictionary storage; use physical Arrow buffers',
      );
    }
    if (array.dictionary case final dictionary?)
      checkDictionaries(dictionary);
  }

  batch.columns.forEach(checkDictionaries);
  return {
    'schema': batch.schema.toJson(),
    'length': batch.numRows,
    'columns': [
      for (var i = 0; i < batch.columns.length; i++)
        _columnToJson(batch.schema.fields[i], batch.columns[i]),
    ],
  };
}