@@ -61,6 +61,7 @@ pub enum FileFormatParams {
6161 Xml ( XmlFileFormatParams ) ,
6262 Parquet ( ParquetFileFormatParams ) ,
6363 Orc ( OrcFileFormatParams ) ,
64+ Avro ( AvroFileFormatParams ) ,
6465}
6566
6667impl FileFormatParams {
@@ -73,6 +74,7 @@ impl FileFormatParams {
7374 FileFormatParams :: Xml ( _) => StageFileFormatType :: Xml ,
7475 FileFormatParams :: Parquet ( _) => StageFileFormatType :: Parquet ,
7576 FileFormatParams :: Orc ( _) => StageFileFormatType :: Orc ,
77+ FileFormatParams :: Avro ( _) => StageFileFormatType :: Avro ,
7678 }
7779 }
7880
@@ -90,6 +92,9 @@ impl FileFormatParams {
9092 Ok ( FileFormatParams :: Json ( JsonFileFormatParams :: default ( ) ) )
9193 }
9294 StageFileFormatType :: Orc => Ok ( FileFormatParams :: Orc ( OrcFileFormatParams :: default ( ) ) ) ,
95+ StageFileFormatType :: Avro => {
96+ Ok ( FileFormatParams :: Avro ( AvroFileFormatParams :: default ( ) ) )
97+ }
9398 _ => Err ( ErrorCode :: IllegalFileFormat ( format ! (
9499 "Unsupported file format type: {:?}" ,
95100 format_type
@@ -106,6 +111,7 @@ impl FileFormatParams {
106111 FileFormatParams :: Xml ( v) => v. compression ,
107112 FileFormatParams :: Parquet ( _) => StageFileCompression :: None ,
108113 FileFormatParams :: Orc ( _) => StageFileCompression :: None ,
114+ FileFormatParams :: Avro ( _) => StageFileCompression :: None ,
109115 }
110116 }
111117
@@ -169,6 +175,16 @@ impl FileFormatParams {
169175 null_if,
170176 ) ?)
171177 }
178+ StageFileFormatType :: Avro => {
179+ let compression = reader. take_compression ( ) ?;
180+ let missing_field_as = reader. options . remove ( MISSING_FIELD_AS ) ;
181+ let null_if = parse_null_if ( reader. options . remove ( NULL_IF ) ) ?;
182+ FileFormatParams :: Avro ( AvroFileFormatParams :: try_create (
183+ compression,
184+ missing_field_as. as_deref ( ) ,
185+ null_if,
186+ ) ?)
187+ }
172188 StageFileFormatType :: Parquet => {
173189 let missing_field_as = reader. options . remove ( MISSING_FIELD_AS ) ;
174190 let null_if = parse_null_if ( reader. options . remove ( NULL_IF ) ) ?;
@@ -690,6 +706,52 @@ impl NdJsonFileFormatParams {
690706 }
691707}
692708
709+ #[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
710+ pub struct AvroFileFormatParams {
711+ pub compression : StageFileCompression ,
712+ pub missing_field_as : NullAs ,
713+ pub null_if : Vec < String > ,
714+ }
715+
716+ impl AvroFileFormatParams {
717+ pub fn try_create (
718+ compression : StageFileCompression ,
719+ missing_field_as : Option < & str > ,
720+ null_if : Vec < String > ,
721+ ) -> Result < Self > {
722+ let missing_field_as = NullAs :: parse ( missing_field_as, MISSING_FIELD_AS , NullAs :: Error ) ?;
723+ if matches ! ( missing_field_as, NullAs :: Null ) {
724+ return Err ( ErrorCode :: InvalidArgument (
725+ "Invalid option value for Avro: NULL_FIELD_AS is set to NULL. The valid values are ERROR | FIELD_DEFAULT." ,
726+ ) ) ;
727+ }
728+ Ok ( Self {
729+ compression,
730+ missing_field_as,
731+ null_if,
732+ } )
733+ }
734+ }
735+
736+ impl Default for crate :: principal:: AvroFileFormatParams {
737+ fn default ( ) -> Self {
738+ crate :: principal:: AvroFileFormatParams {
739+ compression : StageFileCompression :: None ,
740+ missing_field_as : NullAs :: Error ,
741+ null_if : vec ! [ ] ,
742+ }
743+ }
744+ }
745+
746+ impl AvroFileFormatParams {
747+ pub fn downcast_unchecked ( params : & FileFormatParams ) -> & AvroFileFormatParams {
748+ match params {
749+ FileFormatParams :: Avro ( p) => p,
750+ _ => unreachable ! ( ) ,
751+ }
752+ }
753+ }
754+
693755#[ derive( Clone , Debug , Default , PartialEq , Eq , Serialize , Deserialize ) ]
694756pub struct ParquetFileFormatParams {
695757 pub missing_field_as : NullAs ,
@@ -776,6 +838,9 @@ impl Display for FileFormatParams {
776838 params. compression, params. missing_field_as, params. null_field_as
777839 )
778840 }
841+ FileFormatParams :: Avro ( params) => {
842+ write ! ( f, "TYPE = AVRO, NULL_FIELDS_AS = {}" , params. compression, )
843+ }
779844 FileFormatParams :: Parquet ( params) => {
780845 write ! (
781846 f,
0 commit comments