Interface HardwoodContext
- All Superinterfaces:
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:
Hardwoodinstance (for multi-file usage)ParquetFileReaderinstance (for standalone single-file usage)ParquetFileWriterinstance (for a writer created without a context)
A context created by the caller is closed by the caller, after every reader and writer using it.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic HardwoodContext.Builderbuilder()Starts building a context.voidclose()Closes the context.static HardwoodContextcreate()Create a new context with a thread pool sized to available processors.static HardwoodContextcreate(int threads) Create a new context with a thread pool of the specified size.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.
-
Method Details
-
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:
closein interfaceAutoCloseable
-
create
Create a new context with a thread pool sized to available processors. -
create
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- ifthreadsis 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 }
-