Class SessionContextBuilder
SessionContext. Each setter is optional; unset fields leave the
DataFusion default in place.-
Method Summary
Modifier and TypeMethodDescriptionbatchSize(int batchSize) build()Construct aSessionContextwith the configured options.cacheManager(CacheManagerOptions options) Configure DataFusion's built-inCacheManagerfor the new context.collectStatistics(boolean collectStatistics) Disable on-disk spill entirely.informationSchema(boolean informationSchema) maxTempDirectorySize(long bytes) Cap the cumulative bytes used by spill files undertempDirectory(String).memoryLimit(long maxMemoryBytes, double fraction) Cap the memory pool atmaxMemoryBytes, reservingfractionof it for queries.registerObjectStore(ObjectStoreOptions options) Register anobject_store::ObjectStorebackend on the new context'sRuntimeEnv.Set an arbitrarydatafusion.*config option by string key.setOptions(LinkedHashMap<String, String> entries) setOptions(Map<String, String> entries) Apply every entry ofentriesviasetOption(String, String).targetPartitions(int targetPartitions) tempDirectory(String path) Directory the DiskManager uses for spill files.Register Apache Spark-compatible functions and expression planners on the new context, using thedatafusion-sparkcrate.
-
Method Details
-
batchSize
-
targetPartitions
-
collectStatistics
-
informationSchema
-
memoryLimit
Cap the memory pool atmaxMemoryBytes, reservingfractionof it for queries. -
tempDirectory
Directory the DiskManager uses for spill files. -
disableSpill
Disable on-disk spill entirely. Queries that need spill fail with aResourcesExhaustedExceptionrather than going to disk; useful for memory-only execution profiles or environments without writable disk.Mutually exclusive with
tempDirectory(String)— the combination throws atbuild()time.maxTempDirectorySize(long)is allowed alongside this setter but is a no-op (no directory to cap). -
maxTempDirectorySize
Cap the cumulative bytes used by spill files undertempDirectory(String). Mirrors upstreamRuntimeEnvBuilder::with_max_temp_directory_size1:1. Once exceeded, queries that need more spill space fail with aResourcesExhaustedException. Combinable withdisableSpill()but a no-op there.0is accepted — upstream documents zero as legal and equivalent to "no spill allowed". Negative values are rejected.- Throws:
IllegalArgumentException- ifbytesis negative.
-
setOption
Set an arbitrarydatafusion.*config option by string key. Mirrors DataFusion'sConfigOptions::set(key, value)API — see the DataFusion configuration reference for the full set of keys. Entries set this way are applied after the typed setters on this builder, so an explicitsetOptioncall overrides a typed setter for the same knob.datafusion.runtime.*keys (memory limit, temp directory, cache sizes, etc) are not yet supported by this setter and will throw atbuild(). Use the typedmemoryLimit(long, double)andtempDirectory(String)setters instead. Round-trip support for the runtime subtree is tracked as a follow-up.Unknown keys or unparseable values are not validated here; they surface as a
RuntimeExceptionfrombuild()carrying DataFusion's error message.- Throws:
IllegalArgumentException- ifkeyorvalueisnull.
-
setOptions
Apply every entry ofentriesviasetOption(String, String), inLinkedHashMapinsertion order. Use this overload when you need the strict last-write-wins ordering guarantee for overlapping side-effect keys (e.g.datafusion.optimizer.enable_dynamic_filter_pushdownrewrites the per-operatorenable_*_dynamic_filter_pushdownflags, so a per-operator override must come after the umbrella).- Throws:
IllegalArgumentException- if any key or value inentriesisnull.
-
setOptions
Apply every entry ofentriesviasetOption(String, String). Iterates in whatever order the suppliedMapproduces, which forHashMaporPropertiesis unspecified.This is the right overload for the common case where the caller's keys don't overlap with any upstream setter's side effects. If you do need order — see the
setOptions(LinkedHashMap)overload, which the compiler will resolve to automatically when you pass aLinkedHashMap.- Throws:
IllegalArgumentException- if any key or value inentriesisnull.
-
cacheManager
Configure DataFusion's built-inCacheManagerfor the new context. Build theCacheManagerOptionsviaCacheManagerOptions.builder(); each cache slot is independent, so leaving a setter unset keeps the upstream default in place.Calling this setter twice replaces the previous configuration — there is no incremental merge between calls. If you need a different cache configuration, build a new
CacheManagerOptionsfrom scratch.- Throws:
IllegalArgumentException- ifoptionsisnull.
-
withSparkFunctions
Register Apache Spark-compatible functions and expression planners on the new context, using thedatafusion-sparkcrate. Once enabled, Spark-compatible functions (e.g.crc32) are callable from SQL and override any DataFusion built-in of the same name.Requires the native library to be built with the
sparkCargo feature, which is enabled in the default build. If it is not,build()throws aRuntimeExceptionexplaining the feature is missing. -
registerObjectStore
Register anobject_store::ObjectStorebackend on the new context'sRuntimeEnv. BuildObjectStoreOptionsvia the per-backend factories (ObjectStoreOptions.s3(),ObjectStoreOptions.gcs(),ObjectStoreOptions.http(String)). The store is reachable inside the resultingSessionContextby URL — e.g. once an S3 store is registered formy-bucket,ctx.registerParquet("orders", "s3://my-bucket/orders/")will resolve through it.Multiple registrations are applied in the order added; if two registrations resolve to the same URL, the later one wins (matching upstream
RuntimeEnv::register_object_store).If the underlying
object_storecloud-backend Cargo feature is not built into the native library,build()surfaces a clear error rather than silently dropping the registration. The defaultmakebuild enables all three backends (S3 / GCS / HTTP).- Throws:
IllegalArgumentException- ifoptionsisnull.
-
build
Construct aSessionContextwith the configured options.- Throws:
IllegalStateException- ifdisableSpill()was called alongsidetempDirectory(String)— the combination is contradictory.RuntimeException- if the native side fails to construct the context.
-