File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -184,7 +184,9 @@ fn valid_type(data_type: &DataType, value: &Value) -> bool {
184184 DataType :: Boolean => value. is_boolean ( ) ,
185185 DataType :: Int8 | DataType :: Int16 | DataType :: Int32 | DataType :: Int64 => value. is_i64 ( ) ,
186186 DataType :: UInt8 | DataType :: UInt16 | DataType :: UInt32 | DataType :: UInt64 => value. is_u64 ( ) ,
187- DataType :: Float16 | DataType :: Float32 | DataType :: Float64 => value. is_f64 ( ) ,
187+ DataType :: Float16 | DataType :: Float32 | DataType :: Float64 => {
188+ value. is_f64 ( ) || value. is_i64 ( ) || value. is_u64 ( )
189+ }
188190 DataType :: Utf8 => value. is_string ( ) ,
189191 DataType :: List ( field) => {
190192 let data_type = field. data_type ( ) ;
Original file line number Diff line number Diff line change @@ -204,13 +204,41 @@ pub fn override_timestamp_fields(
204204 Arc :: new ( Schema :: new ( updated_fields) )
205205}
206206
207+ pub fn override_num_fields_from_schema ( schema : Arc < Schema > ) -> Arc < Schema > {
208+ Arc :: new ( Schema :: new (
209+ schema
210+ . fields ( )
211+ . iter ( )
212+ . map ( |field| {
213+ if field. data_type ( ) == & DataType :: Int64
214+ || field. data_type ( ) == & DataType :: Int32
215+ || field. data_type ( ) == & DataType :: Int16
216+ || field. data_type ( ) == & DataType :: Int8
217+ || field. data_type ( ) == & DataType :: Float64
218+ || field. data_type ( ) == & DataType :: Float32
219+ || field. data_type ( ) == & DataType :: Float16
220+ {
221+ Arc :: new ( Field :: new (
222+ field. name ( ) ,
223+ DataType :: Float64 ,
224+ field. is_nullable ( ) ,
225+ ) )
226+ } else {
227+ field. clone ( )
228+ }
229+ } )
230+ . collect :: < Vec < Arc < Field > > > ( ) ,
231+ ) )
232+ }
233+
207234pub fn update_field_type_in_schema (
208235 inferred_schema : Arc < Schema > ,
209236 existing_schema : Option < & HashMap < String , Arc < Field > > > ,
210237 time_partition : Option < String > ,
211238 log_records : Option < & Vec < Value > > ,
212239) -> Arc < Schema > {
213240 let mut updated_schema = inferred_schema. clone ( ) ;
241+ updated_schema = override_num_fields_from_schema ( updated_schema) ;
214242
215243 if let Some ( existing_schema) = existing_schema {
216244 let existing_fields = get_existing_fields ( inferred_schema. clone ( ) , Some ( existing_schema) ) ;
You can’t perform that action at this time.
0 commit comments