namespace vast.fbs.table_slice.arrow;

/// A table slice encoded with Apache Arrow.
table v0 {
  /// The schema of the data.
  /// TODO: The schema is already included in the record batch, but it cannot be
  /// mapped 1-to-1 to VAST types. This can be resolved by using extension types
  /// for Arrow. Additionally, this is currently CAF binary; make this a
  /// separarate table.
  layout: [ubyte];

  /// The Arrow Schema containing the Record Batch layout.
  schema: [ubyte];

  /// The Arrow Recod Batch containing all data.
  record_batch: [ubyte];
}

namespace vast.fbs.table_slice.msgpack;

/// A table slice encoded with MessagePack.
table v0 {
  /// The schema of the data.
  /// TODO: currently CAF binary; make this a separate table.
  layout: [ubyte];

  /// Offsets from the beginning of the buffer to each row.
  offset_table: [ulong];

  /// The buffer that contains the MessagePack data.
  data: [ubyte];
}

namespace vast.fbs.table_slice;

/// The union of all possible table slice encoding and version combinations.
union TableSlice {
  arrow.v0,
  msgpack.v0,
}

namespace vast.fbs;

/// A horizontal partition of a table. A slice defines a tabular interface for
/// accessing homogenous data independent of the concrete carrier format.
table TableSlice {
  table_slice: table_slice.TableSlice;
}

/// A vector of bytes that wraps a table slice.
/// The extra wrapping makes it possible to append existing table slices as
/// blobs to a segment builder. For example, this happens when the archive
/// receives a stream of table slices. Without the wrapping, we'd have to go
/// through a new table slice builder for every slice.
table FlatTableSlice {
  data: [ubyte] (nested_flatbuffer: "TableSlice");
}

root_type TableSlice;
