Class SessionContextBuilder

java.lang.Object
org.apache.datafusion.SessionContextBuilder

public final class SessionContextBuilder extends Object
Builder for a configured SessionContext. Each setter is optional; unset fields leave the DataFusion default in place.
  • Method Details

    • batchSize

      public SessionContextBuilder batchSize(int batchSize)
    • targetPartitions

      public SessionContextBuilder targetPartitions(int targetPartitions)
    • collectStatistics

      public SessionContextBuilder collectStatistics(boolean collectStatistics)
    • informationSchema

      public SessionContextBuilder informationSchema(boolean informationSchema)
    • memoryLimit

      public SessionContextBuilder memoryLimit(long maxMemoryBytes, double fraction)
      Cap the memory pool at maxMemoryBytes, reserving fraction of it for queries.
    • tempDirectory

      public SessionContextBuilder tempDirectory(String path)
      Directory the DiskManager uses for spill files.
    • setOption

      public SessionContextBuilder setOption(String key, String value)
      Set an arbitrary datafusion.* config option by string key. Mirrors DataFusion's ConfigOptions::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 explicit setOption call 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 at build(). Use the typed memoryLimit(long, double) and tempDirectory(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 RuntimeException from build() carrying DataFusion's error message.

      Throws:
      IllegalArgumentException - if key or value is null.
    • setOptions

      public SessionContextBuilder setOptions(LinkedHashMap<String,String> entries)
      Apply every entry of entries via setOption(String, String), in LinkedHashMap insertion 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_pushdown rewrites the per-operator enable_*_dynamic_filter_pushdown flags, so a per-operator override must come after the umbrella).
      Throws:
      IllegalArgumentException - if any key or value in entries is null.
    • setOptions

      public SessionContextBuilder setOptions(Map<String,String> entries)
      Apply every entry of entries via setOption(String, String). Iterates in whatever order the supplied Map produces, which for HashMap or Properties is 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 a LinkedHashMap.

      Throws:
      IllegalArgumentException - if any key or value in entries is null.
    • registerObjectStore

      public SessionContextBuilder registerObjectStore(ObjectStoreOptions options)
      Register an object_store::ObjectStore backend on the new context's RuntimeEnv. Build ObjectStoreOptions via the per-backend factories (ObjectStoreOptions.s3(), ObjectStoreOptions.gcs(), ObjectStoreOptions.http(String)). The store is reachable inside the resulting SessionContext by URL — e.g. once an S3 store is registered for my-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_store cloud-backend Cargo feature is not built into the native library, build() surfaces a clear error rather than silently dropping the registration. The default make build enables all three backends (S3 / GCS / HTTP).

      Throws:
      IllegalArgumentException - if options is null.
    • build

      public SessionContext build()
      Construct a SessionContext with the configured options.
      Throws:
      RuntimeException - if the native side fails to construct the context.