@@ -44,6 +44,7 @@ public final class SessionContextBuilder {
4444 private boolean spillDisabled ;
4545 private Long maxTempDirectorySize ;
4646 private CacheManagerOptions cacheManager ;
47+ private boolean sparkFunctions ;
4748 private final LinkedHashMap <String , String > options = new LinkedHashMap <>();
4849 private final List <ObjectStoreOptions > objectStores = new ArrayList <>();
4950
@@ -227,6 +228,20 @@ public SessionContextBuilder cacheManager(CacheManagerOptions options) {
227228 return this ;
228229 }
229230
231+ /**
232+ * Register Apache Spark-compatible functions and expression planners on the new context, using
233+ * the {@code datafusion-spark} crate. Once enabled, Spark-compatible functions (e.g. {@code
234+ * crc32}) are callable from SQL and override any DataFusion built-in of the same name.
235+ *
236+ * <p>Requires the native library to be built with the {@code spark} Cargo feature, which is
237+ * enabled in the default build. If it is not, {@link #build()} throws a {@link RuntimeException}
238+ * explaining the feature is missing.
239+ */
240+ public SessionContextBuilder withSparkFunctions () {
241+ this .sparkFunctions = true ;
242+ return this ;
243+ }
244+
230245 /**
231246 * Register an {@code object_store::ObjectStore} backend on the new context's {@code RuntimeEnv}.
232247 * Build {@link ObjectStoreOptions} via the per-backend factories ({@link ObjectStoreOptions#s3},
@@ -309,6 +324,9 @@ byte[] toBytes() {
309324 for (Map .Entry <String , String > e : options .entrySet ()) {
310325 b .addOptions (ConfigOption .newBuilder ().setKey (e .getKey ()).setValue (e .getValue ()).build ());
311326 }
327+ if (sparkFunctions ) {
328+ b .setSparkFunctions (true );
329+ }
312330 for (ObjectStoreOptions os : objectStores ) {
313331 b .addObjectStores (os .toRegistration ());
314332 }
0 commit comments