Interface HardwoodContext

All Superinterfaces:
AutoCloseable

public interface HardwoodContext extends AutoCloseable

Context object that manages shared resources for reading and writing Parquet files.

Holds the thread pool for parallel page decoding and column chunk encoding, the libdeflate decompressor pool for native GZIP decompression, the decompressor factory, and the MetadataSource installed through builder(), if any.

A context of zero threads (create(int) with 0) has no pool: a read on it decodes on the thread calling the reader, as that thread asks for each batch, and a writer encodes on the thread calling it. A read of files not in memory still fetches bytes ahead on virtual threads.

The context lifecycle is tied to either:

A context created by the caller is closed by the caller, after every reader and writer using it.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Builder for a HardwoodContext.
  • Method Summary

    Modifier and Type
    Method
    Description
    Starts building a context.
    void
    Closes the context.
    Create a new context with a thread pool sized to available processors.
    create(int threads)
    Create a new context with a thread pool of the specified size.
    Deprecated, for removal: This API element is subject to removal in a future version.
    The executor is not meant to run the caller's tasks, and this method has no replacement; it will be removed in the next major release.
  • Method Details

    • executor

      @Deprecated(since="1.1", forRemoval=true) ExecutorService executor()
      Deprecated, for removal: This API element is subject to removal in a future version.
      The executor is not meant to run the caller's tasks, and this method has no replacement; it will be removed in the next major release.

      Get the executor service for parallel operations.

      The executor runs Hardwood's own work: it decodes the pages of every read and encodes the column chunks of every write on this context, so a task submitted to it competes with them. A read waits for work only this executor's threads run, so a reader built with this context cannot be built in a task running on it: building one there fails with an IllegalStateException.

      Throws:
      UnsupportedOperationException - if the context has zero threads, and so no pool
    • close

      void close()
      Closes the context. The pool accepts no new task, and the tasks already submitted to it run to completion; the call waits up to five seconds for them.
      Specified by:
      close in interface AutoCloseable
    • create

      static HardwoodContext create()
      Create a new context with a thread pool sized to available processors.
    • create

      static HardwoodContext create(int threads)
      Create a new context with a thread pool of the specified size. With zero threads, the context has no pool, and its reads and writes run on the threads calling them.
      Throws:
      IllegalArgumentException - if threads is negative
    • builder

      Starts building a context.

      try (HardwoodContext context = HardwoodContext.builder()
              .threads(16)
              .metadataSource(source)
              .build()) {
          // every reader opened against context takes its footers from source
      }