@@ -109,7 +109,7 @@ impl FileFormatParams {
109109 FileFormatParams :: NdJson ( v) => v. compression ,
110110 FileFormatParams :: Json ( v) => v. compression ,
111111 FileFormatParams :: Xml ( v) => v. compression ,
112- FileFormatParams :: Parquet ( _ ) => StageFileCompression :: None ,
112+ FileFormatParams :: Parquet ( v ) => v . compression ,
113113 FileFormatParams :: Orc ( _) => StageFileCompression :: None ,
114114 FileFormatParams :: Avro ( _) => StageFileCompression :: None ,
115115 }
@@ -153,18 +153,18 @@ impl FileFormatParams {
153153 StageFileFormatType :: Xml => {
154154 let default = XmlFileFormatParams :: default ( ) ;
155155 let row_tag = reader. take_string ( OPT_ROW_TAG , default. row_tag ) ;
156- let compression = reader. take_compression ( ) ?;
156+ let compression = reader. take_compression_default_none ( ) ?;
157157 FileFormatParams :: Xml ( XmlFileFormatParams {
158158 compression,
159159 row_tag,
160160 } )
161161 }
162162 StageFileFormatType :: Json => {
163- let compression = reader. take_compression ( ) ?;
163+ let compression = reader. take_compression_default_none ( ) ?;
164164 FileFormatParams :: Json ( JsonFileFormatParams { compression } )
165165 }
166166 StageFileFormatType :: NdJson => {
167- let compression = reader. take_compression ( ) ?;
167+ let compression = reader. take_compression_default_none ( ) ?;
168168 let missing_field_as = reader. options . remove ( MISSING_FIELD_AS ) ;
169169 let null_field_as = reader. options . remove ( NULL_FIELD_AS ) ;
170170 let null_if = parse_null_if ( reader. options . remove ( NULL_IF ) ) ?;
@@ -176,7 +176,7 @@ impl FileFormatParams {
176176 ) ?)
177177 }
178178 StageFileFormatType :: Avro => {
179- let compression = reader. take_compression ( ) ?;
179+ let compression = reader. take_compression_default_none ( ) ?;
180180 let missing_field_as = reader. options . remove ( MISSING_FIELD_AS ) ;
181181 let null_if = parse_null_if ( reader. options . remove ( NULL_IF ) ) ?;
182182 FileFormatParams :: Avro ( AvroFileFormatParams :: try_create (
@@ -186,9 +186,11 @@ impl FileFormatParams {
186186 ) ?)
187187 }
188188 StageFileFormatType :: Parquet => {
189+ let compression = reader. take_compression ( StageFileCompression :: Zstd ) ?;
189190 let missing_field_as = reader. options . remove ( MISSING_FIELD_AS ) ;
190191 let null_if = parse_null_if ( reader. options . remove ( NULL_IF ) ) ?;
191192 FileFormatParams :: Parquet ( ParquetFileFormatParams :: try_create (
193+ compression,
192194 missing_field_as. as_deref ( ) ,
193195 null_if,
194196 ) ?)
@@ -201,7 +203,7 @@ impl FileFormatParams {
201203 }
202204 StageFileFormatType :: Csv => {
203205 let default = CsvFileFormatParams :: default ( ) ;
204- let compression = reader. take_compression ( ) ?;
206+ let compression = reader. take_compression_default_none ( ) ?;
205207 let headers = reader. take_u64 ( OPT_SKIP_HEADER , default. headers ) ?;
206208 let field_delimiter =
207209 reader. take_string ( OPT_FIELD_DELIMITER , default. field_delimiter ) ;
@@ -246,7 +248,7 @@ impl FileFormatParams {
246248 }
247249 StageFileFormatType :: Tsv => {
248250 let default = TsvFileFormatParams :: default ( ) ;
249- let compression = reader. take_compression ( ) ?;
251+ let compression = reader. take_compression_default_none ( ) ?;
250252 let headers = reader. take_u64 ( OPT_SKIP_HEADER , default. headers ) ?;
251253 let field_delimiter =
252254 reader. take_string ( OPT_FIELD_DELIMITER , default. field_delimiter ) ;
@@ -329,6 +331,7 @@ impl FileFormatParams {
329331impl Default for FileFormatParams {
330332 fn default ( ) -> Self {
331333 FileFormatParams :: Parquet ( ParquetFileFormatParams {
334+ compression : StageFileCompression :: Zstd ,
332335 missing_field_as : NullAs :: Error ,
333336 null_if : vec ! [ ] ,
334337 } )
@@ -384,10 +387,13 @@ impl FileFormatOptionsReader {
384387 }
385388 }
386389
387- fn take_compression ( & mut self ) -> Result < StageFileCompression > {
390+ fn take_compression_default_none ( & mut self ) -> Result < StageFileCompression > {
391+ self . take_compression ( StageFileCompression :: None )
392+ }
393+ fn take_compression ( & mut self , default : StageFileCompression ) -> Result < StageFileCompression > {
388394 match self . options . remove ( "compression" ) {
389395 Some ( c) => StageFileCompression :: from_str ( & c) . map_err ( ErrorCode :: IllegalFileFormat ) ,
390- None => Ok ( StageFileCompression :: None ) ,
396+ None => Ok ( default ) ,
391397 }
392398 }
393399
@@ -752,16 +758,41 @@ impl AvroFileFormatParams {
752758 }
753759}
754760
755- #[ derive( Clone , Debug , Default , PartialEq , Eq , Serialize , Deserialize ) ]
761+ #[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
756762pub struct ParquetFileFormatParams {
763+ // used only for unload
764+ pub compression : StageFileCompression ,
757765 pub missing_field_as : NullAs ,
758766 pub null_if : Vec < String > ,
759767}
760768
769+ impl Default for ParquetFileFormatParams {
770+ fn default ( ) -> Self {
771+ Self {
772+ compression : StageFileCompression :: Zstd ,
773+ missing_field_as : Default :: default ( ) ,
774+ null_if : Default :: default ( ) ,
775+ }
776+ }
777+ }
778+
761779impl ParquetFileFormatParams {
762- pub fn try_create ( missing_field_as : Option < & str > , null_if : Vec < String > ) -> Result < Self > {
780+ pub fn try_create (
781+ compression : StageFileCompression ,
782+ missing_field_as : Option < & str > ,
783+ null_if : Vec < String > ,
784+ ) -> Result < Self > {
785+ if !matches ! (
786+ compression,
787+ StageFileCompression :: Zstd | StageFileCompression :: Snappy
788+ ) {
789+ return Err ( ErrorCode :: InvalidArgument ( format ! (
790+ "compression algorithm {compression} not supported, only support Zstd and Snappy."
791+ ) ) ) ;
792+ }
763793 let missing_field_as = NullAs :: parse ( missing_field_as, MISSING_FIELD_AS , NullAs :: Error ) ?;
764794 Ok ( Self {
795+ compression,
765796 missing_field_as,
766797 null_if,
767798 } )
0 commit comments