2222//!
2323//! Extension types are represented using the metadata from Arrow [`Field`]s
2424//! with the key "ARROW:extension:name".
25+ //!
26+ //! Extension types are represented using the metadata from Arrow [`Field`]s
27+ //! with the key "ARROW:extension:name".
28+ //!
29+ //! [`ExtensionType`]: arrow_schema::extension::ExtensionType
2530
2631use crate :: basic:: LogicalType ;
2732use crate :: errors:: ParquetError ;
2833use crate :: schema:: types:: Type ;
2934use arrow_schema:: Field ;
30- use arrow_schema:: extension:: ExtensionType ;
3135
3236/// Adds extension type metadata, if necessary, based on the Parquet field's
3337/// [`LogicalType`]
@@ -36,39 +40,48 @@ use arrow_schema::extension::ExtensionType;
3640/// Arrow DataType, and instead are represented by an Arrow ExtensionType.
3741/// Extension types are attached to Arrow Fields via metadata.
3842pub ( crate ) fn try_add_extension_type (
39- mut arrow_field : Field ,
43+ arrow_field : Field ,
4044 parquet_type : & Type ,
4145) -> Result < Field , ParquetError > {
4246 let Some ( parquet_logical_type) = parquet_type. get_basic_info ( ) . logical_type_ref ( ) else {
4347 return Ok ( arrow_field) ;
4448 } ;
45- match parquet_logical_type {
49+ Ok ( match parquet_logical_type {
4650 #[ cfg( feature = "variant_experimental" ) ]
4751 LogicalType :: Variant { .. } => {
52+ let mut arrow_field = arrow_field;
4853 arrow_field. try_with_extension_type ( parquet_variant_compute:: VariantType ) ?;
54+ arrow_field
4955 }
5056 #[ cfg( feature = "arrow_canonical_extension_types" ) ]
5157 LogicalType :: Uuid => {
58+ let mut arrow_field = arrow_field;
5259 arrow_field. try_with_extension_type ( arrow_schema:: extension:: Uuid ) ?;
60+ arrow_field
5361 }
5462 #[ cfg( feature = "arrow_canonical_extension_types" ) ]
5563 LogicalType :: Json => {
64+ let mut arrow_field = arrow_field;
5665 arrow_field. try_with_extension_type ( arrow_schema:: extension:: Json :: default ( ) ) ?;
66+ arrow_field
5767 }
5868 #[ cfg( feature = "geospatial" ) ]
5969 LogicalType :: Geometry { crs } => {
6070 let md = parquet_geospatial:: WkbMetadata :: new ( crs. as_deref ( ) , None ) ;
71+ let mut arrow_field = arrow_field;
6172 arrow_field. try_with_extension_type ( parquet_geospatial:: WkbType :: new ( Some ( md) ) ) ?;
73+ arrow_field
6274 }
6375 #[ cfg( feature = "geospatial" ) ]
6476 LogicalType :: Geography { crs, algorithm } => {
6577 let algorithm = algorithm. map ( |a| a. try_as_edges ( ) ) . transpose ( ) ?;
6678 let md = parquet_geospatial:: WkbMetadata :: new ( crs. as_deref ( ) , algorithm) ;
79+ let mut arrow_field = arrow_field;
6780 arrow_field. try_with_extension_type ( parquet_geospatial:: WkbType :: new ( Some ( md) ) ) ?;
81+ arrow_field
6882 }
69- _ => { }
70- } ;
71- Ok ( arrow_field)
83+ _ => arrow_field,
84+ } )
7285}
7386
7487/// Returns true if [`try_add_extension_type`] would add an extension type
@@ -97,6 +110,7 @@ pub(crate) fn has_extension_type(parquet_type: &Type) -> bool {
97110/// Return the Parquet logical type to use for the specified Arrow Struct field, if any.
98111#[ cfg( feature = "variant_experimental" ) ]
99112pub ( crate ) fn logical_type_for_struct ( field : & Field ) -> Option < LogicalType > {
113+ use arrow_schema:: extension:: ExtensionType ;
100114 use parquet_variant_compute:: VariantType ;
101115 // Check the name (= quick and cheap) and only try_extension_type if the name matches
102116 // to avoid unnecessary String allocations in ArrowError
@@ -151,6 +165,7 @@ pub(crate) fn logical_type_for_string(_field: &Field) -> Option<LogicalType> {
151165
152166#[ cfg( feature = "geospatial" ) ]
153167pub ( crate ) fn logical_type_for_binary ( field : & Field ) -> Option < LogicalType > {
168+ use arrow_schema:: extension:: ExtensionType ;
154169 use parquet_geospatial:: WkbType ;
155170 use parquet_geospatial:: WkbTypeHint ;
156171
@@ -172,7 +187,7 @@ pub(crate) fn logical_type_for_binary(field: &Field) -> Option<LogicalType> {
172187}
173188
174189#[ cfg( not( feature = "geospatial" ) ) ]
175- pub ( crate ) fn logical_type_for_binary ( field : & Field ) -> Option < LogicalType > {
190+ pub ( crate ) fn logical_type_for_binary ( _field : & Field ) -> Option < LogicalType > {
176191 None
177192}
178193
@@ -182,6 +197,6 @@ pub(crate) fn logical_type_for_binary_view(field: &Field) -> Option<LogicalType>
182197}
183198
184199#[ cfg( not( feature = "geospatial" ) ) ]
185- pub ( crate ) fn logical_type_for_binary_view ( field : & Field ) -> Option < LogicalType > {
200+ pub ( crate ) fn logical_type_for_binary_view ( _field : & Field ) -> Option < LogicalType > {
186201 None
187202}
0 commit comments