block_builder.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from typing import Generic
  2. from ray.data.block import Block, BlockAccessor, BlockType, T
  3. class BlockBuilder(Generic[T]):
  4. """A builder class for blocks."""
  5. @staticmethod
  6. def for_block(block: Block) -> "BlockBuilder":
  7. return BlockAccessor.for_block(block).builder()
  8. def add(self, item: T) -> None:
  9. """Append a single row to the block being built."""
  10. raise NotImplementedError
  11. def add_block(self, block: Block) -> None:
  12. """Append an entire block to the block being built."""
  13. raise NotImplementedError
  14. def will_build_yield_copy(self) -> bool:
  15. """Whether building this block will yield a new block copy."""
  16. raise NotImplementedError
  17. def build(self) -> Block:
  18. """Build the block."""
  19. raise NotImplementedError
  20. def num_rows(self) -> int:
  21. """Return the number of rows added in the block."""
  22. raise NotImplementedError
  23. def get_estimated_memory_usage(self) -> int:
  24. """Return the estimated memory usage so far in bytes."""
  25. raise NotImplementedError
  26. def block_type(self) -> BlockType:
  27. """Return the block type."""
  28. raise NotImplementedError