@@ -362,6 +362,70 @@ public DataFrame readArrow(String path, ArrowReadOptions options) {
362362 return new DataFrame (dfHandle );
363363 }
364364
365+ /** Register an Avro file (or directory of Avro files) as a table. */
366+ public void registerAvro (String name , String path ) {
367+ registerAvro (name , path , new AvroReadOptions ());
368+ }
369+
370+ /**
371+ * Register an Avro file (or directory of Avro files) as a table with the supplied {@link
372+ * AvroReadOptions}.
373+ *
374+ * @throws IllegalArgumentException if any of {@code name}, {@code path}, or {@code options} is
375+ * {@code null}.
376+ * @throws RuntimeException if registration fails (path not found, schema mismatch, etc.).
377+ */
378+ public void registerAvro (String name , String path , AvroReadOptions options ) {
379+ if (nativeHandle == 0 ) {
380+ throw new IllegalStateException ("SessionContext is closed" );
381+ }
382+ if (name == null ) {
383+ throw new IllegalArgumentException ("registerAvro name must be non-null" );
384+ }
385+ if (path == null ) {
386+ throw new IllegalArgumentException ("registerAvro path must be non-null" );
387+ }
388+ if (options == null ) {
389+ throw new IllegalArgumentException ("registerAvro options must be non-null" );
390+ }
391+ registerAvroWithOptions (
392+ nativeHandle ,
393+ name ,
394+ path ,
395+ options .toBytes (),
396+ options .schema () != null ? serializeSchemaIpc (options .schema ()) : null );
397+ }
398+
399+ /** Read an Avro file as a {@link DataFrame} without registering it. */
400+ public DataFrame readAvro (String path ) {
401+ return readAvro (path , new AvroReadOptions ());
402+ }
403+
404+ /**
405+ * Read an Avro file as a {@link DataFrame} with the supplied {@link AvroReadOptions}.
406+ *
407+ * @throws IllegalArgumentException if {@code path} or {@code options} is {@code null}.
408+ * @throws RuntimeException if the read fails.
409+ */
410+ public DataFrame readAvro (String path , AvroReadOptions options ) {
411+ if (nativeHandle == 0 ) {
412+ throw new IllegalStateException ("SessionContext is closed" );
413+ }
414+ if (path == null ) {
415+ throw new IllegalArgumentException ("readAvro path must be non-null" );
416+ }
417+ if (options == null ) {
418+ throw new IllegalArgumentException ("readAvro options must be non-null" );
419+ }
420+ long dfHandle =
421+ readAvroWithOptions (
422+ nativeHandle ,
423+ path ,
424+ options .toBytes (),
425+ options .schema () != null ? serializeSchemaIpc (options .schema ()) : null );
426+ return new DataFrame (dfHandle );
427+ }
428+
365429 /**
366430 * Register a Java-implemented scalar UDF. After registration, the function can be invoked by SQL
367431 * via the UDF's name or referenced in DataFusion plans deserialised with {@link #fromProto}.
@@ -443,6 +507,12 @@ private static native void registerArrowWithOptions(
443507 private static native long readArrowWithOptions (
444508 long handle , String path , byte [] optionsBytes , byte [] schemaIpcBytes );
445509
510+ private static native void registerAvroWithOptions (
511+ long handle , String name , String path , byte [] optionsBytes , byte [] schemaIpcBytes );
512+
513+ private static native long readAvroWithOptions (
514+ long handle , String path , byte [] optionsBytes , byte [] schemaIpcBytes );
515+
446516 private static native void registerJsonWithOptions (
447517 long handle , String name , String path , byte [] optionsBytes , byte [] schemaIpcBytes );
448518
0 commit comments